|
24 | 24 | #pragma warning (disable : 4201) // Nonstandard extension - nameless struct
|
25 | 25 | #include <windows.h>
|
26 | 26 | #include "systimer.h"
|
| 27 | +#include <Utility/intrin_compat.h> |
27 | 28 |
|
28 | 29 | #ifdef _UNIX
|
29 | 30 | # include <time.h> // for time(), localtime() and timezone variable.
|
@@ -127,42 +128,18 @@ const char* CPUDetectClass::Get_Processor_Manufacturer_Name()
|
127 | 128 |
|
128 | 129 | static unsigned Calculate_Processor_Speed(__int64& ticks_per_second)
|
129 | 130 | {
|
130 |
| - struct { |
131 |
| - unsigned timer0_h; |
132 |
| - unsigned timer0_l; |
133 |
| - unsigned timer1_h; |
134 |
| - unsigned timer1_l; |
135 |
| - } Time; |
| 131 | + unsigned __int64 timer0=0; |
| 132 | + unsigned __int64 timer1=0; |
136 | 133 |
|
137 |
| -#ifdef WIN32 |
138 |
| - __asm { |
139 |
| - ASM_RDTSC; |
140 |
| - mov Time.timer0_h, eax |
141 |
| - mov Time.timer0_l, edx |
142 |
| - } |
143 |
| -#elif defined(_UNIX) |
144 |
| - __asm__("rdtsc"); |
145 |
| - __asm__("mov %eax, __Time.timer1_h"); |
146 |
| - __asm__("mov %edx, __Time.timer1_l"); |
147 |
| -#endif |
| 134 | + timer0=_rdtsc(); |
148 | 135 |
|
149 | 136 | unsigned start=TIMEGETTIME();
|
150 | 137 | unsigned elapsed;
|
151 | 138 | while ((elapsed=TIMEGETTIME()-start)<200) {
|
152 |
| -#ifdef WIN32 |
153 |
| - __asm { |
154 |
| - ASM_RDTSC; |
155 |
| - mov Time.timer1_h, eax |
156 |
| - mov Time.timer1_l, edx |
157 |
| - } |
158 |
| -#elif defined(_UNIX) |
159 |
| - __asm__ ("rdtsc"); |
160 |
| - __asm__("mov %eax, __Time.timer1_h"); |
161 |
| - __asm__("mov %edx, __Time.timer1_l"); |
162 |
| -#endif |
| 139 | + timer1=_rdtsc(); |
163 | 140 | }
|
164 | 141 |
|
165 |
| - __int64 t=*(__int64*)&Time.timer1_h-*(__int64*)&Time.timer0_h; |
| 142 | + __int64 t=timer1-timer0; |
166 | 143 | ticks_per_second=(__int64)((1000.0/(double)elapsed)*(double)t); // Ticks per second
|
167 | 144 | return unsigned((double)t/(double)(elapsed*1000));
|
168 | 145 | }
|
@@ -826,6 +803,7 @@ void CPUDetectClass::Init_CPUID_Instruction()
|
826 | 803 | // because CodeWarrior seems to have problems with
|
827 | 804 | // the command (huh?)
|
828 | 805 |
|
| 806 | +#if defined(_MSC_VER) && _MSC_VER < 1300 |
829 | 807 | #ifdef WIN32
|
830 | 808 | __asm
|
831 | 809 | {
|
@@ -868,6 +846,10 @@ void CPUDetectClass::Init_CPUID_Instruction()
|
868 | 846 | __asm__(" pop %ebx");
|
869 | 847 | #endif
|
870 | 848 | HasCPUIDInstruction=!!cpuid_available;
|
| 849 | +#else |
| 850 | + // TheSuperHackers @info Mauller 30/3/2020 All modern CPUs have the CPUID instruction, VS22 code will not run on a cpu that doesn't. |
| 851 | + HasCPUIDInstruction = true; |
| 852 | +#endif // defined(_MSC_VER) && _MSC_VER < 1300 |
871 | 853 | }
|
872 | 854 |
|
873 | 855 | void CPUDetectClass::Init_Processor_Features()
|
@@ -941,44 +923,12 @@ bool CPUDetectClass::CPUID(
|
941 | 923 | {
|
942 | 924 | if (!Has_CPUID_Instruction()) return false; // Most processors since 486 have CPUID...
|
943 | 925 |
|
944 |
| - unsigned u_eax; |
945 |
| - unsigned u_ebx; |
946 |
| - unsigned u_ecx; |
947 |
| - unsigned u_edx; |
948 |
| - |
949 |
| -#ifdef WIN32 |
950 |
| - __asm |
951 |
| - { |
952 |
| - pushad |
953 |
| - mov eax, [cpuid_type] |
954 |
| - xor ebx, ebx |
955 |
| - xor ecx, ecx |
956 |
| - xor edx, edx |
957 |
| - cpuid |
958 |
| - mov [u_eax], eax |
959 |
| - mov [u_ebx], ebx |
960 |
| - mov [u_ecx], ecx |
961 |
| - mov [u_edx], edx |
962 |
| - popad |
963 |
| - } |
964 |
| -#elif defined(_UNIX) |
965 |
| - __asm__("pusha"); |
966 |
| - __asm__("mov __cpuid_type, %eax"); |
967 |
| - __asm__("xor %ebx, %ebx"); |
968 |
| - __asm__("xor %ecx, %ecx"); |
969 |
| - __asm__("xor %edx, %edx"); |
970 |
| - __asm__("cpuid"); |
971 |
| - __asm__("mov %eax, __u_eax"); |
972 |
| - __asm__("mov %ebx, __u_ebx"); |
973 |
| - __asm__("mov %ecx, __u_ecx"); |
974 |
| - __asm__("mov %edx, __u_edx"); |
975 |
| - __asm__("popa"); |
976 |
| -#endif |
977 |
| - |
978 |
| - u_eax_=u_eax; |
979 |
| - u_ebx_=u_ebx; |
980 |
| - u_ecx_=u_ecx; |
981 |
| - u_edx_=u_edx; |
| 926 | + unsigned int regs[4]; |
| 927 | + cpuid(regs, cpuid_type); |
| 928 | + u_eax_ = regs[0]; |
| 929 | + u_ebx_ = regs[1]; |
| 930 | + u_ecx_ = regs[2]; |
| 931 | + u_edx_ = regs[3]; |
982 | 932 |
|
983 | 933 | return true;
|
984 | 934 | }
|
|
0 commit comments