@@ -109,11 +109,11 @@ int32_t get_num_physical_cores() {
109109
110110static void cpuid (unsigned leaf, unsigned subleaf,
111111 unsigned *eax, unsigned *ebx, unsigned *ecx, unsigned *edx) {
112- __asm__ (" movq\t %%rbx,%%rsi\n\t "
113- " cpuid\n\t "
114- " xchgq\t %%rbx,%%rsi"
115- : " =a" (*eax), " =S" (*ebx), " =c" (*ecx), " =d" (*edx)
116- : " 0" (leaf), " 2" (subleaf));
112+ __asm__ (" movq\t %%rbx,%%rsi\n\t "
113+ " cpuid\n\t "
114+ " xchgq\t %%rbx,%%rsi"
115+ : " =a" (*eax), " =S" (*ebx), " =c" (*ecx), " =d" (*edx)
116+ : " 0" (leaf), " 2" (subleaf));
117117}
118118
119119static int pin_cpu (int cpu) {
@@ -140,10 +140,12 @@ static bool is_running_on_efficiency_core(void) {
140140static int count_math_cpus (int cpu_count) {
141141 int result = 0 ;
142142 for (int cpu = 0 ; cpu < cpu_count; ++cpu) {
143- if (pin_cpu (cpu))
143+ if (pin_cpu (cpu)) {
144144 return -1 ;
145- if (is_running_on_efficiency_core ())
145+ }
146+ if (is_running_on_efficiency_core ()) {
146147 continue ; // efficiency cores harm lockstep threading
148+ }
147149 ++cpu; // hyperthreading isn't useful for linear algebra
148150 ++result;
149151 }
@@ -158,15 +160,17 @@ static int count_math_cpus(int cpu_count) {
158160int get_math_cpu_count () {
159161#if defined(__x86_64__) && defined(__linux__)
160162 int cpu_count = sysconf (_SC_NPROCESSORS_ONLN);
161- if (cpu_count < 1 )
163+ if (cpu_count < 1 ) {
162164 return get_num_physical_cores ();
165+ }
163166 if (is_hybrid_cpu ()) {
164167 cpu_set_t affinity;
165168 if (!pthread_getaffinity_np (pthread_self (), sizeof (affinity), &affinity)) {
166169 int result = count_math_cpus (cpu_count);
167170 pthread_setaffinity_np (pthread_self (), sizeof (affinity), &affinity);
168- if (result > 0 )
171+ if (result > 0 ) {
169172 return result;
173+ }
170174 }
171175 }
172176#endif
0 commit comments