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:
Justine Tunney 2024-03-04 17:33:26 -08:00
parent a6baba1b07
commit 8bfd56b59e
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
53 changed files with 110 additions and 93 deletions

View file

@ -2028,7 +2028,7 @@ static int ParseModrm(struct As *a, int *disp) {
if (((reg & 070) >> 3) == 2) modrm |= HASASZ; // asz
if (IsComma(a)) {
++a->i;
modrm |= (_bsr(GetInt(a)) & 3) << 6;
modrm |= (bsr(GetInt(a)) & 3) << 6;
}
}
ConsumePunct(a, ')');

View file

@ -301,7 +301,7 @@ static void PickAsmRegisters(Asm *a) {
if (!(m = a->ops[i].regmask)) break;
if (popcnt(m) != j) break;
if (!(m &= regset)) CouldNotAllocateRegister(&a->ops[i], "rm");
pick = 1 << (a->ops[i].reg = _bsf(m));
pick = 1 << (a->ops[i].reg = bsf(m));
if (pick & PRECIOUS) a->regclob |= pick;
regset &= ~pick;
a->ops[i].regmask = 0;
@ -309,14 +309,14 @@ static void PickAsmRegisters(Asm *a) {
case kAsmXmm:
if (!(m = a->ops[i].regmask)) break;
if (!(m &= xmmset)) CouldNotAllocateRegister(&a->ops[i], "xmm");
xmmset &= ~(1 << (a->ops[i].reg = _bsf(m)));
xmmset &= ~(1 << (a->ops[i].reg = bsf(m)));
a->ops[i].regmask = 0;
break;
case kAsmFpu:
if (!(m = a->ops[i].x87mask)) break;
if (popcnt(m) != j) break;
if (!(m &= x87sts)) CouldNotAllocateRegister(&a->ops[i], "fpu");
x87sts &= ~(1 << (a->ops[i].reg = _bsf(m)));
x87sts &= ~(1 << (a->ops[i].reg = bsf(m)));
a->ops[i].x87mask = 0;
break;
default:
@ -540,7 +540,7 @@ static char *HandleAsmSpecifier(Asm *a, char *p) {
if ((i = c - '0') >= a->n) {
error_tok(a->tok, "bad asm reference at offset %d", p - a->str);
}
z = _bsr(a->ops[i].node->ty->size);
z = bsr(a->ops[i].node->ty->size);
if (z > 3 && a->ops[i].type == kAsmReg) {
error_tok(a->tok, "bad asm op size");
}
@ -679,7 +679,7 @@ static void StoreAsmOutputs(Asm *a) {
println("\tset%s\t(%%rax)", a->ops[i].str + a->ops[i].predicate);
break;
case kAsmReg:
z = _bsr(a->ops[i].node->ty->size);
z = bsr(a->ops[i].node->ty->size);
if (a->ops[i].reg) {
gen_addr(a->ops[i].node);
if (z > 3) error_tok(a->tok, "bad asm out size");
@ -734,7 +734,7 @@ static void StoreAsmOutputs(Asm *a) {
static void PushClobbers(Asm *a) {
int i, regs = a->regclob & PRECIOUS;
while (regs) {
i = _bsf(regs);
i = bsf(regs);
pushreg(kGreg[3][i]);
regs &= ~(1 << i);
}
@ -743,7 +743,7 @@ static void PushClobbers(Asm *a) {
static void PopClobbers(Asm *a) {
int i, regs = a->regclob & PRECIOUS;
while (regs) {
i = _bsr(regs);
i = bsr(regs);
popreg(kGreg[3][i]);
regs &= ~(1 << i);
}

View file

@ -281,7 +281,7 @@ static int CompareDoxIndexEntry(const void *p1, const void *p2, void *arg) {
}
static unsigned long roundup2pow(unsigned long x) {
return x > 1 ? 2ul << _bsrl(x - 1) : x ? 1 : 0;
return x > 1 ? 2ul << bsrl(x - 1) : x ? 1 : 0;
}
static void IndexDox(struct Dox *dox) {

View file

@ -67,7 +67,7 @@ void canonicalize_newline(char *p) {
p += 16;
q += 16;
} else {
m = _bsf(m);
m = bsf(m);
memmove(q, p, m);
p += m;
q += m;
@ -126,7 +126,7 @@ void remove_backslash_newline(char *p) {
i += 16;
j += 16;
} else {
m = _bsf(m);
m = bsf(m);
memmove(p + j, p + i, m);
i += m;
j += m;

View file

@ -9,7 +9,7 @@ implicit_functions_are_long() {
}
external_functions_are_long() {
if (_bsrl(0x0001000000000000) != 48) {
if (bsrl(0x0001000000000000) != 48) {
__builtin_trap();
}
}

View file

@ -680,7 +680,7 @@ static void convert_universal_chars(char *p) {
p += 16;
q += 16;
} else {
m = _bsf(m);
m = bsf(m);
memmove(q, p, m);
p += m;
q += m;

View file

@ -935,7 +935,7 @@ static void* internal_memalign(mstate m, size_t alignment, size_t bytes) {
if (alignment < MIN_CHUNK_SIZE) /* must be at least a minimum chunk size */
alignment = MIN_CHUNK_SIZE;
/* alignment is 32+ bytes rounded up to nearest two power */
alignment = 2ul << _bsrl(MAX(MIN_CHUNK_SIZE, alignment) - 1);
alignment = 2ul << bsrl(MAX(MIN_CHUNK_SIZE, alignment) - 1);
if (bytes >= MAX_REQUEST - alignment) {
if (m != 0) { /* Test isn't needed but avoids compiler warning */
MALLOC_FAILURE_ACTION;

View file

@ -369,7 +369,7 @@ static wint_t Capitalize(wint_t c) {
static struct rune DecodeUtf8(int c) {
struct rune r;
if (c < 252) {
r.n = _bsr(255 & ~c);
r.n = bsr(255 & ~c);
r.c = c & (((1 << r.n) - 1) | 3);
r.n = 6 - r.n;
} else {
@ -645,7 +645,7 @@ static void abAppendw(struct abuf *a, unsigned long long w) {
p[5] = (0x0000ff0000000000 & w) >> 050;
p[6] = (0x00ff000000000000 & w) >> 060;
p[7] = (0xff00000000000000 & w) >> 070;
a->len += w ? (_bsrll(w) >> 3) + 1 : 1;
a->len += w ? (bsrll(w) >> 3) + 1 : 1;
p[8] = 0;
}
@ -1634,7 +1634,7 @@ static size_t linenoiseEscape(char *d, const char *s, size_t n) {
break;
}
WRITE32LE(p, w);
p += (_bsr(w) >> 3) + 1;
p += (bsr(w) >> 3) + 1;
l = w;
}
return p - d;

View file

@ -785,7 +785,7 @@ LUAI_FUNC void luaO_chunkid (char *out, const char *source, size_t srclen);
** Computes ceil(log2(x))
*/
static inline int luaO_ceillog2 (unsigned int x) {
return --x ? _bsr(x) + 1 : 0;
return --x ? bsr(x) + 1 : 0;
}
#endif

View file

@ -31,7 +31,7 @@ fancy_roundup(int x)
/* Round up to the closest power of 2 >= n. */
int r;
assert(x > 128);
r = 1u << (_bsr(x - 1) + 1); /* hacker's delight */
r = 1u << (bsr(x - 1) + 1); /* hacker's delight */
return r > 0 ? r : -1;
}

View file

@ -878,7 +878,7 @@ privileged static void xed_evex_scanner(struct XedDecodedInst *d) {
}
privileged static uint64_t xed_read_number(uint8_t *p, size_t n, bool s) {
switch (s << 2 | _bsr(n)) {
switch (s << 2 | bsr(n)) {
case 0b000:
return *p;
case 0b100: