@@ -103,29 +103,6 @@ const uint8 pg_number_of_ones[256] = {
103
103
4 , 5 , 5 , 6 , 5 , 6 , 6 , 7 , 5 , 6 , 6 , 7 , 6 , 7 , 7 , 8
104
104
};
105
105
106
- /*
107
- * With MSVC on x86_64 builds, try using native popcnt instructions via the
108
- * __popcnt and __popcnt64 intrinsics. These don't work the same as GCC's
109
- * __builtin_popcount* intrinsic functions as they always emit popcnt
110
- * instructions.
111
- */
112
- #if defined(_MSC_VER ) && defined(_M_AMD64 )
113
- #define HAVE_X86_64_POPCNTQ
114
- #endif
115
-
116
- /*
117
- * On x86_64, we can use the hardware popcount instruction, but only if
118
- * we can verify that the CPU supports it via the cpuid instruction.
119
- *
120
- * Otherwise, we fall back to __builtin_popcount if the compiler has that,
121
- * or a hand-rolled implementation if not.
122
- */
123
- #ifdef HAVE_X86_64_POPCNTQ
124
- #if defined(HAVE__GET_CPUID ) || defined(HAVE__CPUID )
125
- #define TRY_POPCNT_FAST 1
126
- #endif
127
- #endif
128
-
129
106
static int pg_popcount32_slow (uint32 word );
130
107
static int pg_popcount64_slow (uint64 word );
131
108
@@ -138,9 +115,6 @@ static int pg_popcount64_fast(uint64 word);
138
115
139
116
int (* pg_popcount32 ) (uint32 word ) = pg_popcount32_choose ;
140
117
int (* pg_popcount64 ) (uint64 word ) = pg_popcount64_choose ;
141
- #else
142
- int (* pg_popcount32 ) (uint32 word ) = pg_popcount32_slow ;
143
- int (* pg_popcount64 ) (uint64 word ) = pg_popcount64_slow ;
144
118
#endif /* TRY_POPCNT_FAST */
145
119
146
120
#ifdef TRY_POPCNT_FAST
@@ -291,6 +265,28 @@ pg_popcount64_slow(uint64 word)
291
265
#endif /* HAVE__BUILTIN_POPCOUNT */
292
266
}
293
267
268
+ #ifndef TRY_POPCNT_FAST
269
+
270
+ /*
271
+ * When the POPCNT instruction is not available, there's no point in using
272
+ * function pointers to vary the implementation between the fast and slow
273
+ * method. We instead just make these actual external functions when
274
+ * TRY_POPCNT_FAST is not defined. The compiler should be able to inline
275
+ * the slow versions here.
276
+ */
277
+ int
278
+ pg_popcount32 (uint32 word )
279
+ {
280
+ return pg_popcount32_slow (word );
281
+ }
282
+
283
+ int
284
+ pg_popcount64 (uint64 word )
285
+ {
286
+ return pg_popcount64_slow (word );
287
+ }
288
+
289
+ #endif /* !TRY_POPCNT_FAST */
294
290
295
291
/*
296
292
* pg_popcount
0 commit comments