Skip to content

Commit 99bed86

Browse files
committed
features: Require SSE 4.2 for popcnt
It's not 100% clear whether this is needed. AMD does not appear to need it, but the Intel documentation appears ambiguous. The instruction detail says this: > #UD If CPUID.01H:ECX.POPCNT [Bit 23] = 0. Which implies it'll raise an exception only if the popcnt feature bit is zero. But in section 12.12.3 it says this: > Before an application attempts to use the POPCNT instruction, it > must check that the processor supports Intel SSE4.2 (if > CPUID.01H:ECX.SSE4_2[bit 20] = 1) and POPCNT (if > CPUID.01H:ECX.POPCNT[bit 23] = 1).
1 parent 40300dc commit 99bed86

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

chafa/chafa-features.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,21 @@ init_features (void)
6666
have_sse41 = TRUE;
6767
# endif
6868

69+
/* For popcnt, AMD does not appear to need the SSE 4.2 check, but the Intel
70+
* documentation[1] says the following in section 12.12.3:
71+
*
72+
* > Before an application attempts to use the POPCNT instruction, it
73+
* > must check that the processor supports Intel SSE4.2 (if
74+
* > CPUID.01H:ECX.SSE4_2[bit 20] = 1) and POPCNT (if
75+
* > CPUID.01H:ECX.POPCNT[bit 23] = 1).
76+
*
77+
* [1] https://software.intel.com/en-us/download/intel-64-and-ia-32-architectures-sdm-combined-volumes-1-2a-2b-2c-2d-3a-3b-3c-3d-and-4
78+
*
79+
* So we check both. */
80+
6981
# ifdef HAVE_POPCNT_INTRINSICS
70-
if (__builtin_cpu_supports ("popcnt"))
82+
if (__builtin_cpu_supports ("sse4.2")
83+
&& __builtin_cpu_supports ("popcnt"))
7184
have_popcnt = TRUE;
7285
# endif
7386

0 commit comments

Comments
 (0)