xiaoyin0208 / lz4

Automatically exported from code.google.com/p/lz4
0 stars 0 forks source link

_BitScanReverse and __builtin_clzll funciton use error ? #71

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
LZ4 use _BitScanReverse windows api in funtion static inline int 
LZ4_NbCommonBytes (register U64 val) if marco LZ4_BIG_ENDIAN defined.

I think LZ4_NbCommonBytes function use for find least bit is set(1).

But in MSDN,

_BitScanReverse desc is:
Search the mask data from most significant bit (MSB) to least significant bit 
(LSB) for a set bit (1).

_BitScanForward desc is 
"Search the mask data from least significant bit (LSB) to the most significant 
bit (MSB) for a set bit (1)." 

two fucntion don't care bit Endian.

I think LZ4_NbCommonBytes only need function _BitScanForward,that is enough.

Similar to __builtin_clzll in gcc.

Best regards!

Original issue reported on code.google.com by sailerz...@gmail.com on 18 Jun 2013 at 3:58

GoogleCodeExporter commented 8 years ago
> I think LZ4_NbCommonBytes function use for find least bit is set(1).

Well, not exactly.
LZ4_NbCommonBytes() is used to know how many bytes are in common between a 
source and a reference, progressing in memory order. It's only called to 
"finalize" this count (i.e. we know that values being compared are not strictly 
equal).
LSB and MSB are only methods to find that answer.

For little endian CPU, the first byte is the smallest one. So we look for LSB.
For big endian CPU, the first byte is the highest one. So we look for MSB.

Original comment by yann.col...@gmail.com on 19 Jun 2013 at 2:58

GoogleCodeExporter commented 8 years ago

Original comment by yann.col...@gmail.com on 19 Jun 2013 at 2:59

GoogleCodeExporter commented 8 years ago

Original comment by yann.col...@gmail.com on 1 Jul 2013 at 7:53