[flac-dev] [PATCH 2] more changes in bitmath.h

lvqcl lvqcl.mail at gmail.com
Mon Dec 28 11:50:47 PST 2015


1) FLAC supports only MSVS 2005 and newer, so (_MSC_VER >= 1400)
is always true and can be removed.


2) The argument for FLAC__clz_uint32() is of FLAC__uint32 type, so
FLAC__clz_soft_uint32() should have the same argument type.


3) The patch removes unnecessary parentheses around 'word' variable.


4) It also replaces "sizeof(FLAC__uint32) * CHAR_BIT  - 1 - FLAC__clz_uint32(v)"
with "FLAC__clz_uint32(v) ^ 31U" (and the same for 64-bit version).

"sizeof(FLAC__uint32) * CHAR_BIT" must be 32, or the code won't work.
So it's simpler to use "31 - FLAC__clz_uint32(v)" or even better,
"FLAC__clz_uint32(v) ^ 31".

Why XORing is better: gcc implements __builtin_clz as bsr^31, so
FLAC__bitmath_ilog2() now calculates 31 - (bsr^31). GCC is unable
to simplify it to just bsr. But it can do it for (bsr^31)^31.


5) The patch adds FLAC__U64L() for a big constant.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 2_bitmath_h.patch
Type: application/octet-stream
Size: 3166 bytes
Desc: not available
Url : http://lists.xiph.org/pipermail/flac-dev/attachments/20151228/f3622bb8/attachment.obj 


More information about the flac-dev mailing list