[XviD-devel] Endian Problem found
Christoph Nägeli
chn at kbw.ch
Tue Dec 23 13:19:29 CET 2003
Hello,
Since the xvid_bench quant test looked a little strange I had a look at
the code (run on a PowerPC):
===== test quant =====
PLAINC - quant_mpeg_intra 101.431 usec crc32=0x750b840e | ERROR
PLAINC - quant_mpeg_inter 104.775 usec crc32=0x0b895346 | ERROR
PLAINC - dequant_mpeg_intra 53.767 usec crc32=0x2f2cb029 | ERROR
PLAINC - dequant_mpeg_inter 65.915 usec crc32=0x4b64700b | ERROR
PLAINC - quant_h263_intra 39.888 usec crc32=0x99380911 | ERROR
PLAINC - quant_h263_inter 44.091 usec crc32=0x9d1bb0e2 | ERROR
PLAINC - dequant_h263_intra 46.557 usec crc32=0x66f1a2e5 | ERROR
PLAINC - dequant_h263_inter 43.007 usec crc32=0x565a0e26 | ERROR
I found (or think I found) the problem in
uint32_t calc_crc(uint8_t *mem, int len, uint32_t initial);
The first Pointer is declared in the caller as uint16_t.
In the Preprocessor Macro DO#, The mem pointer gets read byte by byte,
since it's actually a uint16_t the right way to read it on a big-endian
would be [1] [0] [3] [2] ... (right?)
So I changed the function to test if this is the only problem. As I
know that the len is always a multiple of 64 in this file, I made the
following changes:
#define DO2(c, crc) ((crc) = crc32tab[((unsigned int)((crc)>>24) ^
(c[1])) & 0xff] ^ ((crc) << 8)); \
((crc) = crc32tab[((unsigned int)((crc)>>24) ^
(c[0])) & 0xff] ^ ((crc) << 8))
uint32_t
calc_crc(uint8_t *mem, int len, uint32_t initial)
{
register unsigned int crc;
crc = initial;
while(len >= 2) {
DO2(mem, crc);
mem += 2;
len -= 2;
}
return crc;
}
With this code, the test runcs successfully. Has anyone an idea how to
change it that it works if the 'len' isn't a multiple of 2?
And what if the mem is really a uint8_t* or uint32_t* (the code above
wouldn't work for that)?
Christoph
Test result with the code above:
===== test quant =====
PLAINC - quant_mpeg_intra 100.195 usec crc32=0xfd6a21a4
PLAINC - quant_mpeg_inter 104.684 usec crc32=0xf6de7757
PLAINC - dequant_mpeg_intra 51.418 usec crc32=0x2def7bc7
PLAINC - dequant_mpeg_inter 64.169 usec crc32=0xd878c722
PLAINC - quant_h263_intra 41.068 usec crc32=0x2eba9d43
PLAINC - quant_h263_inter 39.234 usec crc32=0xbd315a7e
PLAINC - dequant_h263_intra 44.601 usec crc32=0x9841212a
PLAINC - dequant_h263_inter 40.860 usec crc32=0xe7df8fba
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: text/enriched
Size: 2623 bytes
Desc: not available
Url : http://edu.bnhof.de/pipermail/xvid-devel/attachments/20031223/3a7856e4/attachment.bin
More information about the XviD-devel
mailing list