diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2018-06-12 17:51:13 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2018-06-12 17:51:13 (GMT) |
commit | d152af2b8883fb101cfbdc607601cb963f40db4a (patch) | |
tree | 3720f17abed1398243448f7cd4ca8f5d3de8d4d9 /src | |
parent | 60160c213f574ba1386a954d4c3fa4bf3435782e (diff) |
Refactored the msb implementation.
Diffstat (limited to 'src')
-rw-r--r-- | src/common/asm.c | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/src/common/asm.c b/src/common/asm.c index f29d599..692256f 100644 --- a/src/common/asm.c +++ b/src/common/asm.c @@ -25,6 +25,18 @@ +/** + * Indice du bit de poids fort dans un quartet. + */ + +static const unsigned int _bval[16] = { + + 0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4 + +}; + + + /****************************************************************************** * * * Paramètres : v = valeur quelconque sur 32 bits. * @@ -40,8 +52,6 @@ bool msb_32(uint32_t v, unsigned int *p) { - static const unsigned int bval[] = { 0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4 }; - /* S'il n'y a aucun bit à 1... */ if (v == 0) return false; @@ -60,7 +70,7 @@ bool msb_32(uint32_t v, unsigned int *p) if (v & 0x0000ff00) { *p += 16 / 2; v >>= 16 / 2; } if (v & 0x000000f0) { *p += 16 / 4; v >>= 16 / 4; } - *p += bval[v]; + *p += _bval[v]; return true; @@ -82,8 +92,6 @@ bool msb_32(uint32_t v, unsigned int *p) bool msb_64(uint64_t v, unsigned int *p) { - static const unsigned int bval[] = { 0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4 }; - /* S'il n'y a aucun bit à 1... */ if (v == 0) return false; @@ -98,7 +106,7 @@ bool msb_64(uint64_t v, unsigned int *p) if (v & 0x000000000000ff00ull) { *p += 32 / 4; v >>= 32 / 4; } if (v & 0x00000000000000f0ull) { *p += 32 / 8; v >>= 32 / 8; } - *p += bval[v]; + *p += _bval[v]; return true; |