mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-01-31 11:37:35 +00:00
87d7010495
This change helps spectre more intelligently plan execution, by working around false output dependencies, impacting ops like popcnt bsr and bsf
24 lines
1 KiB
C
24 lines
1 KiB
C
#ifndef COSMOPOLITAN_LIBC_BITS_POPCNT_H_
|
|
#define COSMOPOLITAN_LIBC_BITS_POPCNT_H_
|
|
#include "libc/nexgen32e/x86feature.h"
|
|
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
|
COSMOPOLITAN_C_START_
|
|
|
|
unsigned long popcnt(unsigned long) pureconst;
|
|
|
|
#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
|
|
#define popcnt(X) \
|
|
(__builtin_constant_p(X) ? __builtin_popcountll(X) : ({ \
|
|
unsigned long PoP = (X); \
|
|
if (X86_HAVE(POPCNT)) { \
|
|
asm("popcnt\t%0,%0" : "+r"(PoP) : /* no inputs */ : "cc"); \
|
|
} else { \
|
|
PoP = (popcnt)(PoP); \
|
|
} \
|
|
PoP; \
|
|
}))
|
|
#endif /* GNUC && !ANSI */
|
|
|
|
COSMOPOLITAN_C_END_
|
|
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
|
#endif /* COSMOPOLITAN_LIBC_BITS_POPCNT_H_ */
|