mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-14 15:09:09 +00:00
Rename _bsr/_bsf to bsr/bsf
Now that these functions are behind _COSMO_SOURCE there's no reason for having the ugly underscore anymore. To use these functions, you need to pass -mcosmo to cosmocc.
This commit is contained in:
parent
a6baba1b07
commit
8bfd56b59e
53 changed files with 110 additions and 93 deletions
|
@ -22,7 +22,7 @@
|
|||
* Returns position of first bit set.
|
||||
*
|
||||
* ctz(𝑥) 31^clz(𝑥) clz(𝑥)
|
||||
* uint32 𝑥 _bsf(𝑥) tzcnt(𝑥) ffs(𝑥) _bsr(𝑥) lzcnt(𝑥)
|
||||
* uint32 𝑥 bsf(𝑥) tzcnt(𝑥) ffs(𝑥) bsr(𝑥) lzcnt(𝑥)
|
||||
* 0x00000000 wut 32 0 wut 32
|
||||
* 0x00000001 0 0 1 0 31
|
||||
* 0x80000001 0 0 1 31 0
|
||||
|
@ -35,7 +35,7 @@
|
|||
* @param 𝑥 is a 64-bit integer
|
||||
* @return number in range 0..63 or undefined if 𝑥 is 0
|
||||
*/
|
||||
int(_bsfl)(long x) {
|
||||
int(bsfl)(long x) {
|
||||
unsigned l, r;
|
||||
x &= -x;
|
||||
l = x | x >> 32;
|
||||
|
@ -52,7 +52,7 @@ int(_bsfl)(long x) {
|
|||
* Returns position of first bit set.
|
||||
*
|
||||
* ctz(𝑥) 31^clz(𝑥) clz(𝑥)
|
||||
* uint32 𝑥 _bsf(𝑥) tzcnt(𝑥) ffs(𝑥) _bsr(𝑥) lzcnt(𝑥)
|
||||
* uint32 𝑥 bsf(𝑥) tzcnt(𝑥) ffs(𝑥) bsr(𝑥) lzcnt(𝑥)
|
||||
* 0x00000000 wut 32 0 wut 32
|
||||
* 0x00000001 0 0 1 0 31
|
||||
* 0x80000001 0 0 1 31 0
|
||||
|
@ -65,8 +65,8 @@ int(_bsfl)(long x) {
|
|||
* @param x is a 32-bit integer
|
||||
* @return number in range 0..31 or undefined if 𝑥 is 0
|
||||
*/
|
||||
int(_bsf)(int x) {
|
||||
return _bsf((unsigned)x);
|
||||
int(bsf)(int x) {
|
||||
return bsf((unsigned)x);
|
||||
}
|
||||
|
||||
__weak_reference(_bsfl, _bsfll);
|
||||
__weak_reference(bsfl, bsfll);
|
||||
|
|
|
@ -1,16 +1,18 @@
|
|||
#ifdef _COSMO_SOURCE
|
||||
#ifndef COSMOPOLITAN_LIBC_NEXGEN32E_BSF_H_
|
||||
#define COSMOPOLITAN_LIBC_NEXGEN32E_BSF_H_
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
libcesque int _bsf(int) pureconst;
|
||||
libcesque int _bsfl(long) pureconst;
|
||||
libcesque int _bsfll(long long) pureconst;
|
||||
libcesque int bsf(int) pureconst;
|
||||
libcesque int bsfl(long) pureconst;
|
||||
libcesque int bsfll(long long) pureconst;
|
||||
|
||||
#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
|
||||
#define _bsf(x) __builtin_ctz(x)
|
||||
#define _bsfl(x) __builtin_ctzl(x)
|
||||
#define _bsfll(x) __builtin_ctzll(x)
|
||||
#define bsf(x) __builtin_ctz(x)
|
||||
#define bsfl(x) __builtin_ctzl(x)
|
||||
#define bsfll(x) __builtin_ctzll(x)
|
||||
#endif
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* COSMOPOLITAN_LIBC_NEXGEN32E_BSF_H_ */
|
||||
#endif /* _COSMO_SOURCE */
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
* Returns binary logarithm of 𝑥.
|
||||
*
|
||||
* ctz(𝑥) 31^clz(𝑥) clz(𝑥)
|
||||
* uint32 𝑥 _bsf(𝑥) tzcnt(𝑥) ffs(𝑥) _bsr(𝑥) lzcnt(𝑥)
|
||||
* uint32 𝑥 bsf(𝑥) tzcnt(𝑥) ffs(𝑥) bsr(𝑥) lzcnt(𝑥)
|
||||
* 0x00000000 wut 32 0 wut 32
|
||||
* 0x00000001 0 0 1 0 31
|
||||
* 0x80000001 0 0 1 31 0
|
||||
|
@ -36,7 +36,7 @@
|
|||
* @param x is a 32-bit integer
|
||||
* @return number in range 0..31 or undefined if 𝑥 is 0
|
||||
*/
|
||||
int(_bsr)(int x) {
|
||||
int(bsr)(int x) {
|
||||
int r = 0;
|
||||
if(x & 0xFFFF0000u) { x >>= 16; r |= 16; }
|
||||
if(x & 0xFF00) { x >>= 8; r |= 8; }
|
||||
|
|
|
@ -1,16 +1,18 @@
|
|||
#ifdef _COSMO_SOURCE
|
||||
#ifndef COSMOPOLITAN_LIBC_NEXGEN32E_BSR_H_
|
||||
#define COSMOPOLITAN_LIBC_NEXGEN32E_BSR_H_
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
libcesque int _bsr(int) pureconst;
|
||||
libcesque int _bsrl(long) pureconst;
|
||||
libcesque int _bsrll(long long) pureconst;
|
||||
libcesque int bsr(int) pureconst;
|
||||
libcesque int bsrl(long) pureconst;
|
||||
libcesque int bsrll(long long) pureconst;
|
||||
|
||||
#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
|
||||
#define _bsr(x) (__builtin_clz(x) ^ (sizeof(int) * 8 - 1))
|
||||
#define _bsrl(x) (__builtin_clzl(x) ^ (sizeof(long) * 8 - 1))
|
||||
#define _bsrll(x) (__builtin_clzll(x) ^ (sizeof(long long) * 8 - 1))
|
||||
#define bsr(x) (__builtin_clz(x) ^ (sizeof(int) * 8 - 1))
|
||||
#define bsrl(x) (__builtin_clzl(x) ^ (sizeof(long) * 8 - 1))
|
||||
#define bsrll(x) (__builtin_clzll(x) ^ (sizeof(long long) * 8 - 1))
|
||||
#endif
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* COSMOPOLITAN_LIBC_NEXGEN32E_BSR_H_ */
|
||||
#endif /* _COSMO_SOURCE */
|
||||
|
|
|
@ -29,7 +29,7 @@ static const char kDebruijn[64] = {
|
|||
* Returns binary logarithm of 𝑥.
|
||||
*
|
||||
* ctz(𝑥) 31^clz(𝑥) clz(𝑥)
|
||||
* uint32 𝑥 _bsf(𝑥) tzcnt(𝑥) ffs(𝑥) _bsr(𝑥) lzcnt(𝑥)
|
||||
* uint32 𝑥 bsf(𝑥) tzcnt(𝑥) ffs(𝑥) bsr(𝑥) lzcnt(𝑥)
|
||||
* 0x00000000 wut 32 0 wut 32
|
||||
* 0x00000001 0 0 1 0 31
|
||||
* 0x80000001 0 0 1 31 0
|
||||
|
@ -42,7 +42,7 @@ static const char kDebruijn[64] = {
|
|||
* @param x is a 64-bit integer
|
||||
* @return number in range 0..63 or undefined if 𝑥 is 0
|
||||
*/
|
||||
int(_bsrl)(long x) {
|
||||
int(bsrl)(long x) {
|
||||
x |= x >> 1;
|
||||
x |= x >> 2;
|
||||
x |= x >> 4;
|
||||
|
@ -52,4 +52,4 @@ int(_bsrl)(long x) {
|
|||
return kDebruijn[(x * 0x03f79d71b4cb0a89ull) >> 58];
|
||||
}
|
||||
|
||||
__weak_reference(_bsrl, _bsrll);
|
||||
__weak_reference(bsrl, bsrll);
|
||||
|
|
|
@ -58,7 +58,7 @@ int __cxa_atexit(void *fp, void *arg, void *pred) {
|
|||
return enomem();
|
||||
}
|
||||
}
|
||||
i = _bsr(~b->mask);
|
||||
i = bsr(~b->mask);
|
||||
b->mask |= 1u << i;
|
||||
b->p[i].fp = fp;
|
||||
b->p[i].arg = arg;
|
||||
|
|
|
@ -43,7 +43,7 @@ StartOverLocked:
|
|||
for (;;) {
|
||||
mask = b->mask;
|
||||
while (mask) {
|
||||
i = _bsf(mask);
|
||||
i = bsf(mask);
|
||||
mask &= ~(1u << i);
|
||||
if (!pred || pred == b->p[i].pred) {
|
||||
b->mask &= ~(1u << i);
|
||||
|
|
|
@ -43,7 +43,7 @@ const char *(DescribeFdSet)(char buf[N], ssize_t rc, int nfds, fd_set *fds) {
|
|||
for (int fd = 0; fd < nfds; fd += 64) {
|
||||
uint64_t w = fds->fds_bits[fd >> 6];
|
||||
while (w) {
|
||||
unsigned m = _bsr(w);
|
||||
unsigned m = bsr(w);
|
||||
w &= ~((uint64_t)1 << m);
|
||||
if (fd + m < nfds) {
|
||||
if (!gotsome) {
|
||||
|
|
|
@ -48,7 +48,7 @@ char *FormatHex64(char p[hasatleast 19], uint64_t x, char z) {
|
|||
*p++ = '0';
|
||||
*p++ = 'x';
|
||||
}
|
||||
i = PickGoodWidth(_bsrl(x), z);
|
||||
i = PickGoodWidth(bsrl(x), z);
|
||||
do {
|
||||
*p++ = "0123456789abcdef"[(x >> (i -= 4)) & 15];
|
||||
} while (i);
|
||||
|
|
|
@ -34,7 +34,7 @@ uint64_t tpenc(uint32_t c) {
|
|||
int e, n;
|
||||
uint64_t w;
|
||||
if (0 <= c && c <= 127) return c;
|
||||
e = kTpEnc[_bsr(c) - 7];
|
||||
e = kTpEnc[bsr(c) - 7];
|
||||
n = e & 0xff;
|
||||
w = 0;
|
||||
do {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue