shithub: dav1d

Download patch

ref: d9a911a4fbddcb7a28f64851503521ca6b00d291
parent: dc769f5d44b697a6a8c1fdd975bbab6cd2864574
author: Janne Grunau <[email protected]>
date: Wed Feb 27 14:30:18 EST 2019

tools/dav1d: make the md5 muxer endian-aware

Fixes tests on big endian architectures.

--- a/meson.build
+++ b/meson.build
@@ -214,6 +214,8 @@
 stackalign_flag = []
 stackrealign_flag = []
 
+cdata.set10('ENDIANNESS_BIG', host_machine.endian() == 'big')
+
 if host_machine.cpu_family().startswith('x86')
     if get_option('stack_alignment') > 0
         stack_alignment = get_option('stack_alignment')
--- a/tools/output/md5.c
+++ b/tools/output/md5.c
@@ -63,6 +63,27 @@
     0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391,
 };
 
+
+#if ENDIANNESS_BIG
+#define NE2LE_32(x) (((x & 0x00ff) << 24) |\
+                     ((x & 0xff00) <<  8) |\
+                     ((x >>  8) & 0xff00) |\
+                     ((x >> 24) & 0x00ff))
+
+#define NE2LE_64(x) (((x & 0x000000ff) << 56) |\
+                     ((x & 0x0000ff00) << 40) |\
+                     ((x & 0x00ff0000) << 24) |\
+                     ((x & 0xff000000) <<  8) |\
+                     ((x >>  8) & 0xff000000) |\
+                     ((x >> 24) & 0x00ff0000) |\
+                     ((x >> 40) & 0x0000ff00) |\
+                     ((x >> 56) & 0x000000ff))
+
+#else
+#define NE2LE_32(x) (x)
+#define NE2LE_64(x) (x)
+#endif
+
 typedef struct MuxerPriv {
     unsigned abcd[4];
     uint8_t data[64];
@@ -123,7 +144,7 @@
         tmp = d;
         d = c;
         c = b;
-        b += leftrotate(a + f + k[i] + data[g], s[i >> 4][i & 3]);
+        b += leftrotate(a + f + k[i] + NE2LE_32(data[g]), s[i >> 4][i & 3]);
         a = tmp;
     }
 
@@ -193,7 +214,7 @@
 
 static void md5_finish(MD5Context *const md5) {
     static const uint8_t bit[2] = { 0x80, 0x00 };
-    uint64_t len = md5->len << 3;
+    uint64_t len = NE2LE_64(md5->len << 3);
 
     md5_update(md5, &bit[0], 1);
     while ((md5->len & 63) != 56)