Make minor improvements

This commit is contained in:
Justine Tunney 2020-12-23 23:42:56 -08:00
parent 04caf6f9ad
commit 95b142e4e5
95 changed files with 3818 additions and 2760 deletions

View file

@ -3,6 +3,8 @@
#include "libc/nexgen32e/bsr.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
/* TODO(jart): DELETE? */
/**
* Generic Thompson-Pike Varint Decoder.
* @return number of bytes successfully consumed or -1 w/ errno
@ -12,11 +14,11 @@
forceinline int tpdecodecb(wint_t *out, int first,
int get(void *arg, uint32_t i), void *arg) {
uint32_t wc, cb, need, msb, j, i = 1;
if (unlikely((wc = first) == -1)) return -1;
while (unlikely((wc & 0b11000000) == 0b10000000)) {
if (__builtin_expect((wc = first) == -1, 0)) return -1;
while (__builtin_expect((wc & 0b11000000) == 0b10000000, 0)) {
if ((wc = get(arg, i++)) == -1) return -1;
}
if (unlikely(!(0 <= wc && wc <= 0x7F))) {
if (__builtin_expect(!(0 <= wc && wc <= 0x7F), 0)) {
msb = wc < 252 ? bsr(~wc & 0xff) : 1;
need = 7 - msb;
wc &= ((1u << msb) - 1) | 0b00000011;
@ -30,7 +32,7 @@ forceinline int tpdecodecb(wint_t *out, int first,
}
}
}
if (likely(out)) *out = (wint_t)wc;
if (__builtin_expect(!!out, 1)) *out = (wint_t)wc;
return i;
}