Endianess correction
authoryann.collet.73@gmail.com <yann.collet.73@gmail.com@650e7d94-2a16-8b24-b05c-7c0b3f6821cd>
Fri, 9 Dec 2011 13:59:59 +0000 (13:59 +0000)
committeryann.collet.73@gmail.com <yann.collet.73@gmail.com@650e7d94-2a16-8b24-b05c-7c0b3f6821cd>
Fri, 9 Dec 2011 13:59:59 +0000 (13:59 +0000)
git-svn-id: https://lz4.googlecode.com/svn/trunk@42 650e7d94-2a16-8b24-b05c-7c0b3f6821cd

Makefile
lz4.c

index 06e4d9e..bd0a567 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,10 +1,10 @@
 all: lz4demo64 lz4demo32 
 
 lz4demo64: lz4.c lz4.h lz4demo.c
-       gcc      -g -O3 -I. -std=c99 -Wall -W lz4.c lz4demo.c -o lz4demo64.exe
+       gcc      -g -O3 -I. -std=c99 -Wall -W -Wno-implicit-function-declaration lz4.c lz4demo.c -o lz4demo64.exe
 
 lz4demo32: lz4.c lz4.h lz4demo.c
-       gcc -m32 -g -O3 -I. -std=c99 -Wall -W lz4.c lz4demo.c -o lz4demo32.exe
+       gcc -m32 -g -O3 -I. -std=c99 -Wall -W -Wno-implicit-function-declaration lz4.c lz4demo.c -o lz4demo32.exe
 
 clean:
        rm -f core *.o lz4demo32.exe lz4demo64.exe
diff --git a/lz4.c b/lz4.c
index 92fe61a..8041552 100644 (file)
--- a/lz4.c
+++ b/lz4.c
@@ -230,9 +230,15 @@ _next_match:
                anchor = ip;\r
                while (ip<matchlimit-3)\r
                {\r
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__\r
                        int diff = A32(ref) ^ A32(ip);\r
                        if (!diff) { ip+=4; ref+=4; continue; }\r
                        ip += DeBruijnBytePos[((U32)((diff & -diff) * 0x077CB531U)) >> 27];\r
+#else\r
+                       if (A32(ref) == A32(ip)) { ip+=4; ref+=4; continue; }\r
+                       if (A16(ref) == A16(ip)) { ip+=2; ref+=2; }\r
+                       if (*ref == *ip) ip++;\r
+#endif\r
                        goto _endCount;\r
                }\r
                if ((ip<(matchlimit-1)) && (A16(ref) == A16(ip))) { ip+=2; ref+=2; }\r
@@ -371,9 +377,15 @@ _next_match:
                anchor = ip;\r
                while (ip<matchlimit-3)\r
                {\r
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__\r
                        int diff = A32(ref) ^ A32(ip);\r
                        if (!diff) { ip+=4; ref+=4; continue; }\r
                        ip += DeBruijnBytePos[((U32)((diff & -diff) * 0x077CB531U)) >> 27];\r
+#else\r
+                       if (A32(ref) == A32(ip)) { ip+=4; ref+=4; continue; }\r
+                       if (A16(ref) == A16(ip)) { ip+=2; ref+=2; }\r
+                       if (*ref == *ip) ip++;\r
+#endif\r
                        goto _endCount;\r
                }\r
                if ((ip<(matchlimit-1)) && (A16(ref) == A16(ip))) { ip+=2; ref+=2; }\r