We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 202241c commit eeb97e2Copy full SHA for eeb97e2
libclc/native_cpu-unknown-linux/libspirv/integer/popcount.cl
@@ -4,11 +4,12 @@
4
5
// We can't use __builtin_popcountg because it supports only unsigned
6
// types, and we can't use __builtin_popcount because the implicit cast
7
-// to int doesn't work due to sign extension, so we explictly cast to
8
-// the unsigned type.
+// to int doesn't work due to sign extension, so we use type punning to
+// preserve the bit pattern and avoid sign extension.
9
+
10
#define DEF_POPCOUNT_HELPER(TYPE, UTYPE) \
11
_CLC_OVERLOAD TYPE __popcount_helper(TYPE c) { \
- return __builtin_popcountg((UTYPE)c); \
12
+ return __builtin_popcountg(*(UTYPE*)&c); \
13
}
14
15
DEF_POPCOUNT_HELPER(char, unsigned char)
0 commit comments