shithub: dav1d

Download patch

ref: c49680e629931ecf90a294a37f9a99622be3c71c
parent: c82cf102fc635c73d7e6e94d19f37cacd90c44cb
author: Janne Grunau <[email protected]>
date: Thu Dec 6 16:22:40 EST 2018

checkasm: replace rand() with xorshift xor128

Reduces the aarch64 checkasm run time from 22s to 2.4s.

--- a/tests/checkasm/cdef.c
+++ b/tests/checkasm/cdef.c
@@ -34,7 +34,7 @@
 
 static void init_tmp(pixel *buf, int n, const int bitdepth_max) {
     while (n--)
-        *buf++ = rand() & bitdepth_max;
+        *buf++ = rnd() & bitdepth_max;
 }
 
 static void check_cdef_filter(const cdef_fn fn, const int w, const int h,
@@ -57,7 +57,7 @@
                 memcpy(c_src, src, (10 * 16 + 8) * sizeof(pixel));
 
 #if BITDEPTH == 16
-                const int bitdepth_max = rand() & 1 ? 0x3ff : 0xfff;
+                const int bitdepth_max = rnd() & 1 ? 0x3ff : 0xfff;
 #else
                 const int bitdepth_max = 0xff;
 #endif
@@ -66,8 +66,8 @@
                 init_tmp(top, 16 * 2 + 8, bitdepth_max);
                 init_tmp((pixel *) left,8 * 2, bitdepth_max);
 
-                const int lvl = 1 + (rand() % 62);
-                const int damping = 3 + (rand() & 3) + bitdepth_min_8;
+                const int lvl = 1 + (rnd() % 62);
+                const int damping = 3 + (rnd() & 3) + bitdepth_min_8;
                 const int pri_strength = (lvl >> 2) << bitdepth_min_8;
                 int sec_strength = lvl & 3;
                 sec_strength += sec_strength == 3;
@@ -100,7 +100,7 @@
     if (check_func(fn, "cdef_dir_%dbpc", BITDEPTH)) {
         unsigned c_var, a_var;
 #if BITDEPTH == 16
-        const int bitdepth_max = rand() & 1 ? 0x3ff : 0xfff;
+        const int bitdepth_max = rnd() & 1 ? 0x3ff : 0xfff;
 #else
         const int bitdepth_max = 0xff;
 #endif
--- a/tests/checkasm/checkasm.c
+++ b/tests/checkasm/checkasm.c
@@ -143,6 +143,33 @@
     uint32_t i;
 } intfloat;
 
+static uint32_t xs_state[4];
+
+static void xor128_srand(unsigned int seed) {
+    xs_state[0] = seed;
+    xs_state[1] = ( seed & 0xffff0000) | (~seed & 0x0000ffff);
+    xs_state[2] = (~seed & 0xffff0000) | ( seed & 0x0000ffff);
+    xs_state[3] = ~seed;
+}
+
+// xor128 from Marsaglia, George (July 2003). "Xorshift RNGs".
+//             Journal of Statistical Software. 8 (14).
+//             doi:10.18637/jss.v008.i14.
+int xor128_rand(void) {
+    const uint32_t x = xs_state[0];
+    const uint32_t t = x ^ (x << 11);
+
+    xs_state[0] = xs_state[1];
+    xs_state[1] = xs_state[2];
+    xs_state[2] = xs_state[3];
+    uint32_t w = xs_state[3];
+
+    w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
+    xs_state[3] = w;
+
+    return w >> 1;
+}
+
 static int is_negative(const intfloat u) {
     return u.i >> 31;
 }
@@ -453,7 +480,7 @@
         for (int i = 0; tests[i].func; i++) {
             if (state.test_name && strcmp(tests[i].name, state.test_name))
                 continue;
-            srand(state.seed);
+            xor128_srand(state.seed);
             state.current_test_name = tests[i].name;
             tests[i].func();
         }
@@ -567,7 +594,7 @@
     v->ok = 1;
     v->cpu = state.cpu_flag;
     state.current_func_ver = v;
-    srand(state.seed);
+    xor128_srand(state.seed);
 
     if (state.cpu_flag)
         state.num_checked++;
--- a/tests/checkasm/checkasm.h
+++ b/tests/checkasm/checkasm.h
@@ -50,6 +50,9 @@
 #include "include/common/attributes.h"
 #include "include/common/intops.h"
 
+int xor128_rand(void);
+#define rnd xor128_rand
+
 #define decl_check_bitfns(name) \
 name##_8bpc(void); \
 name##_16bpc(void)
--- a/tests/checkasm/ipred.c
+++ b/tests/checkasm/ipred.c
@@ -85,21 +85,21 @@
 
                     int a = 0;
                     if (mode >= Z1_PRED && mode <= Z3_PRED) /* angle */
-                        a = (90 * (mode - Z1_PRED) + z_angles[rand() % 27]) |
-                            (rand() & 0x600);
+                        a = (90 * (mode - Z1_PRED) + z_angles[rnd() % 27]) |
+                            (rnd() & 0x600);
                     else if (mode == FILTER_PRED) /* filter_idx */
-                        a = (rand() % 5) | (rand() & ~511);
+                        a = (rnd() % 5) | (rnd() & ~511);
 
 #if BITDEPTH == 16
-                    const int bitdepth_max = rand() & 1 ? 0x3ff : 0xfff;
+                    const int bitdepth_max = rnd() & 1 ? 0x3ff : 0xfff;
 #else
                     const int bitdepth_max = 0xff;
 #endif
 
                     for (int i = -h * 2; i <= w * 2; i++)
-                        topleft[i] = rand() & bitdepth_max;
+                        topleft[i] = rnd() & bitdepth_max;
 
-                    const int maxw = 1 + (rand() % 128), maxh = 1 + (rand() % 128);
+                    const int maxw = 1 + (rnd() % 128), maxh = 1 + (rnd() % 128);
                     call_ref(c_dst, stride, topleft, w, h, a, maxw, maxh
                              HIGHBD_TAIL_SUFFIX);
                     call_new(a_dst, stride, topleft, w, h, a, maxw, maxh
@@ -134,13 +134,13 @@
                     for (int w_pad = (w >> 2) - 1; w_pad >= 0; w_pad--) {
                         for (int h_pad = (h >> 2) - 1; h_pad >= 0; h_pad--) {
 #if BITDEPTH == 16
-                            const int bitdepth_max = rand() & 1 ? 0x3ff : 0xfff;
+                            const int bitdepth_max = rnd() & 1 ? 0x3ff : 0xfff;
 #else
                             const int bitdepth_max = 0xff;
 #endif
                             for (int y = 0; y < (h << ss_ver); y++)
                                 for (int x = 0; x < (w << ss_hor); x++)
-                                    luma[y * 32 + x] = rand() & bitdepth_max;
+                                    luma[y * 32 + x] = rnd() & bitdepth_max;
 
                             call_ref(c_dst, luma, stride, w_pad, h_pad, w, h);
                             call_new(a_dst, luma, stride, w_pad, h_pad, w, h);
@@ -175,7 +175,7 @@
                 for (int h = imax(w / 4, 4); h <= imin(w * 4, 32); h <<= 1)
                 {
 #if BITDEPTH == 16
-                    const int bitdepth_max = rand() & 1 ? 0x3ff : 0xfff;
+                    const int bitdepth_max = rnd() & 1 ? 0x3ff : 0xfff;
 #else
                     const int bitdepth_max = 0xff;
 #endif
@@ -182,14 +182,14 @@
 
                     const ptrdiff_t stride = w * sizeof(pixel);
 
-                    int alpha = ((rand() & 15) + 1) * (1 - (rand() & 2));
+                    int alpha = ((rnd() & 15) + 1) * (1 - (rnd() & 2));
 
                     for (int i = -h * 2; i <= w * 2; i++)
-                        topleft[i] = rand() & bitdepth_max;
+                        topleft[i] = rnd() & bitdepth_max;
 
                     int luma_avg = w * h >> 1;
                     for (int i = 0; i < w * h; i++)
-                        luma_avg += ac[i] = rand() & (bitdepth_max << 3);
+                        luma_avg += ac[i] = rnd() & (bitdepth_max << 3);
                     luma_avg /= w * h;
                     for (int i = 0; i < w * h; i++)
                         ac[i] -= luma_avg;
@@ -222,7 +222,7 @@
             for (int h = imax(w / 4, 4); h <= imin(w * 4, 64); h <<= 1)
             {
 #if BITDEPTH == 16
-                const int bitdepth_max = rand() & 1 ? 0x3ff : 0xfff;
+                const int bitdepth_max = rnd() & 1 ? 0x3ff : 0xfff;
 #else
                 const int bitdepth_max = 0xff;
 #endif
@@ -229,10 +229,10 @@
                 const ptrdiff_t stride = w * sizeof(pixel);
 
                 for (int i = 0; i < 8; i++)
-                    pal[i] = rand() & bitdepth_max;
+                    pal[i] = rnd() & bitdepth_max;
 
                 for (int i = 0; i < w * h; i++)
-                    idx[i] = rand() & 7;
+                    idx[i] = rnd() & 7;
 
                 call_ref(c_dst, stride, pal, idx, w, h);
                 call_new(a_dst, stride, pal, idx, w, h);
--- a/tests/checkasm/itx.c
+++ b/tests/checkasm/itx.c
@@ -155,7 +155,7 @@
     }
 
     if (eob)
-        eob += rand() % (n - eob - 1);
+        eob += rnd() % (n - eob - 1);
     for (n = eob + 1; n < sw * sh; n++)
         coeff[scan[n]] = 0;
     return eob;
@@ -173,7 +173,7 @@
         double in[64], temp_out[64];
 
         for (int i = 0; i < w; i++)
-            in[i] = (rand() & (2 * bitdepth_max + 1)) - bitdepth_max;
+            in[i] = (rnd() & (2 * bitdepth_max + 1)) - bitdepth_max;
 
         switch (itx_1d_types[txtp][0]) {
         case DCT:
@@ -258,7 +258,7 @@
                                BITDEPTH))
                 {
 #if BITDEPTH == 16
-                    const int bitdepth_max = rand() & 1 ? 0x3ff : 0xfff;
+                    const int bitdepth_max = rnd() & 1 ? 0x3ff : 0xfff;
 #else
                     const int bitdepth_max = 0xff;
 #endif
@@ -265,7 +265,7 @@
                     const int eob = ftx(coeff[0], tx, txtp, w, h, subsh, bitdepth_max);
 
                     for (int j = 0; j < w * h; j++)
-                        c_dst[j] = a_dst[j] = rand() & bitdepth_max;
+                        c_dst[j] = a_dst[j] = rnd() & bitdepth_max;
 
                     memcpy(coeff[1], coeff[0], sw * sh * sizeof(**coeff));
                     memcpy(coeff[2], coeff[0], sw * sh * sizeof(**coeff));
--- a/tests/checkasm/loopfilter.c
+++ b/tests/checkasm/loopfilter.c
@@ -41,51 +41,51 @@
     I <<= bitdepth_min_8;
     H <<= bitdepth_min_8;
 
-    const int filter_type = rand() % 4;
-    const int edge_diff = rand() % ((E + 2) * 4) - 2 * (E + 2);
+    const int filter_type = rnd() % 4;
+    const int edge_diff = rnd() % ((E + 2) * 4) - 2 * (E + 2);
     switch (filter_type) {
     case 0: // random, unfiltered
         for (int i = -8; i < 8; i++)
-            dst[i * stride] = rand() & bitdepth_max;
+            dst[i * stride] = rnd() & bitdepth_max;
         break;
     case 1: // long flat
-        dst[-8 * stride] = rand() & bitdepth_max;
-        dst[+7 * stride] = rand() & bitdepth_max;
-        dst[+0 * stride] = rand() & bitdepth_max;
+        dst[-8 * stride] = rnd() & bitdepth_max;
+        dst[+7 * stride] = rnd() & bitdepth_max;
+        dst[+0 * stride] = rnd() & bitdepth_max;
         dst[-1 * stride] = iclip_pixel(dst[+0 * stride] + edge_diff);
         for (int i = 1; i < 7; i++) {
             dst[-(1 + i) * stride] = iclip_pixel(dst[-1 * stride] +
-                                                 rand() % (2 * (F + 1)) - (F + 1));
+                                                 rnd() % (2 * (F + 1)) - (F + 1));
             dst[+(0 + i) * stride] = iclip_pixel(dst[+0 * stride] +
-                                                 rand() % (2 * (F + 1)) - (F + 1));
+                                                 rnd() % (2 * (F + 1)) - (F + 1));
         }
         break;
     case 2: // short flat
         for (int i = 4; i < 8; i++) {
-            dst[-(1 + i) * stride] = rand() & bitdepth_max;
-            dst[+(0 + i) * stride] = rand() & bitdepth_max;
+            dst[-(1 + i) * stride] = rnd() & bitdepth_max;
+            dst[+(0 + i) * stride] = rnd() & bitdepth_max;
         }
-        dst[+0 * stride] = rand() & bitdepth_max;
+        dst[+0 * stride] = rnd() & bitdepth_max;
         dst[-1 * stride] = iclip_pixel(dst[+0 * stride] + edge_diff);
         for (int i = 1; i < 4; i++) {
             dst[-(1 + i) * stride] = iclip_pixel(dst[-1 * stride] +
-                                                 rand() % (2 * (F + 1)) - (F + 1));
+                                                 rnd() % (2 * (F + 1)) - (F + 1));
             dst[+(0 + i) * stride] = iclip_pixel(dst[+0 * stride] +
-                                                 rand() % (2 * (F + 1)) - (F + 1));
+                                                 rnd() % (2 * (F + 1)) - (F + 1));
         }
         break;
     case 3: // normal or hev
         for (int i = 4; i < 8; i++) {
-            dst[-(1 + i) * stride] = rand() & bitdepth_max;
-            dst[+(0 + i) * stride] = rand() & bitdepth_max;
+            dst[-(1 + i) * stride] = rnd() & bitdepth_max;
+            dst[+(0 + i) * stride] = rnd() & bitdepth_max;
         }
-        dst[+0 * stride] = rand() & bitdepth_max;
+        dst[+0 * stride] = rnd() & bitdepth_max;
         dst[-1 * stride] = iclip_pixel(dst[+0 * stride] + edge_diff);
         for (int i = 1; i < 4; i++) {
             dst[-(1 + i) * stride] = iclip_pixel(dst[-(0 + i) * stride] +
-                                                 rand() % (2 * (I + 1)) - (I + 1));
+                                                 rnd() % (2 * (I + 1)) - (I + 1));
             dst[+(0 + i) * stride] = iclip_pixel(dst[+(i - 1) * stride] +
-                                                 rand() % (2 * (I + 1)) - (I + 1));
+                                                 rnd() % (2 * (I + 1)) - (I + 1));
         }
         break;
     }
@@ -117,7 +117,7 @@
     }
 
     Av1FilterLUT lut;
-    const int sharp = rand() & 7;
+    const int sharp = rnd() & 7;
     for (int level = 0; level < 64; level++) {
         int limit = level;
 
@@ -142,18 +142,18 @@
             uint8_t l[32 * 2][4];
 
             for (int j = 0; j < n_blks; j++) {
-                const int idx = rand() % (i + 2);
+                const int idx = rnd() % (i + 2);
                 if (idx) vmask[idx - 1] |= 1U << j;
                 if (dir) {
-                    l[j][lf_idx] = rand() & 63;
-                    l[j + 32][lf_idx] = rand() & 63;
+                    l[j][lf_idx] = rnd() & 63;
+                    l[j + 32][lf_idx] = rnd() & 63;
                 } else {
-                    l[j * 2][lf_idx] = rand() & 63;
-                    l[j * 2 + 1][lf_idx] = rand() & 63;
+                    l[j * 2][lf_idx] = rnd() & 63;
+                    l[j * 2 + 1][lf_idx] = rnd() & 63;
                 }
             }
 #if BITDEPTH == 16
-            const int bitdepth_max = rand() & 1 ? 0x3ff : 0xfff;
+            const int bitdepth_max = rnd() & 1 ? 0x3ff : 0xfff;
 #else
             const int bitdepth_max = 0xff;
 #endif
--- a/tests/checkasm/looprestoration.c
+++ b/tests/checkasm/looprestoration.c
@@ -38,7 +38,7 @@
 {
     for (int y = 0; y < h; y++) {
         for (int x = 0; x < w; x++)
-            buf[x] = rand() & bitdepth_max;
+            buf[x] = rnd() & bitdepth_max;
         buf += PXSTRIDE(stride);
     }
 }
@@ -74,12 +74,12 @@
         {
             int16_t filter[2][3], filter_v[7], filter_h[7];
 
-            filter[0][0] = pl ? 0 : (rand() & 15) - 5;
-            filter[0][1] = (rand() & 31) - 23;
-            filter[0][2] = (rand() & 63) - 17;
-            filter[1][0] = pl ? 0 : (rand() & 15) - 5;
-            filter[1][1] = (rand() & 31) - 23;
-            filter[1][2] = (rand() & 63) - 17;
+            filter[0][0] = pl ? 0 : (rnd() & 15) - 5;
+            filter[0][1] = (rnd() & 31) - 23;
+            filter[0][2] = (rnd() & 63) - 17;
+            filter[1][0] = pl ? 0 : (rnd() & 15) - 5;
+            filter[1][1] = (rnd() & 31) - 23;
+            filter[1][2] = (rnd() & 63) - 17;
 
             filter_h[0] = filter_h[6] = filter[0][0];
             filter_h[1] = filter_h[5] = filter[0][1];
@@ -91,10 +91,10 @@
             filter_v[2] = filter_v[4] = filter[1][2];
             filter_v[3] = -((filter_v[0] + filter_v[1] + filter_v[2]) * 2);
 
-            const int base_w = 1 + (rand() % 384);
-            const int base_h = 1 + (rand() & 63);
+            const int base_w = 1 + (rnd() % 384);
+            const int base_h = 1 + (rnd() & 63);
 #if BITDEPTH == 16
-            const int bitdepth_max = rand() & 1 ? 0x3ff : 0xfff;
+            const int bitdepth_max = rnd() & 1 ? 0x3ff : 0xfff;
 #else
             const int bitdepth_max = 0xff;
 #endif
@@ -145,14 +145,14 @@
         {
             int16_t sgr_wt[2];
 
-            sgr_wt[0] = dav1d_sgr_params[sgr_idx][0] ? (rand() & 127) - 96 : 0;
-            sgr_wt[1] = dav1d_sgr_params[sgr_idx][1] ? (rand() & 127) - 32 :
+            sgr_wt[0] = dav1d_sgr_params[sgr_idx][0] ? (rnd() & 127) - 96 : 0;
+            sgr_wt[1] = dav1d_sgr_params[sgr_idx][1] ? (rnd() & 127) - 32 :
                             iclip(128 - sgr_wt[0], -32, 95);
 
-            const int base_w = 1 + (rand() % 384);
-            const int base_h = 1 + (rand() & 63);
+            const int base_w = 1 + (rnd() % 384);
+            const int base_h = 1 + (rnd() & 63);
 #if BITDEPTH == 16
-            const int bitdepth_max = rand() & 1 ? 0x3ff : 0xfff;
+            const int bitdepth_max = rnd() & 1 ? 0x3ff : 0xfff;
 #else
             const int bitdepth_max = 0xff;
 #endif
--- a/tests/checkasm/mc.c
+++ b/tests/checkasm/mc.c
@@ -60,16 +60,16 @@
                     const int min = w <= 32 ? 2 : w / 4;
                     const int max = imax(imin(w * 4, 128), 32);
                     for (int h = min; h <= max; h <<= 1) {
-                        const int mx = (mxy & 1) ? rand() % 15 + 1 : 0;
-                        const int my = (mxy & 2) ? rand() % 15 + 1 : 0;
+                        const int mx = (mxy & 1) ? rnd() % 15 + 1 : 0;
+                        const int my = (mxy & 2) ? rnd() % 15 + 1 : 0;
 #if BITDEPTH == 16
-                        const int bitdepth_max = rand() & 1 ? 0x3ff : 0xfff;
+                        const int bitdepth_max = rnd() & 1 ? 0x3ff : 0xfff;
 #else
                         const int bitdepth_max = 0xff;
 #endif
 
                         for (int i = 0; i < 135 * 135; i++)
-                            src_buf[i] = rand() & bitdepth_max;
+                            src_buf[i] = rnd() & bitdepth_max;
 
                         call_ref(c_dst, w, src, w, w, h, mx, my HIGHBD_TAIL_SUFFIX);
                         call_new(a_dst, w, src, w, w, h, mx, my HIGHBD_TAIL_SUFFIX);
@@ -100,16 +100,16 @@
                     filter_names[filter], w, mxy_names[mxy], BITDEPTH))
                     for (int h = imax(w / 4, 4); h <= imin(w * 4, 128); h <<= 1)
                     {
-                        const int mx = (mxy & 1) ? rand() % 15 + 1 : 0;
-                        const int my = (mxy & 2) ? rand() % 15 + 1 : 0;
+                        const int mx = (mxy & 1) ? rnd() % 15 + 1 : 0;
+                        const int my = (mxy & 2) ? rnd() % 15 + 1 : 0;
 #if BITDEPTH == 16
-                        const int bitdepth_max = rand() & 1 ? 0x3ff : 0xfff;
+                        const int bitdepth_max = rnd() & 1 ? 0x3ff : 0xfff;
 #else
                         const int bitdepth_max = 0xff;
 #endif
 
                         for (int i = 0; i < 135 * 135; i++)
-                            src_buf[i] = rand() & bitdepth_max;
+                            src_buf[i] = rnd() & bitdepth_max;
 
                         call_ref(c_tmp, src, w, w, h, mx, my HIGHBD_TAIL_SUFFIX);
                         call_new(a_tmp, src, w, w, h, mx, my HIGHBD_TAIL_SUFFIX);
@@ -128,10 +128,10 @@
 {
     for (int i = 0; i < 2; i++) {
         for (int j = 0; j < 135 * 135; j++)
-            buf[j] = rand() & bitdepth_max;
-        c->mct[rand() % N_2D_FILTERS](tmp[i], buf + 135 * 3 + 3,
+            buf[j] = rnd() & bitdepth_max;
+        c->mct[rnd() % N_2D_FILTERS](tmp[i], buf + 135 * 3 + 3,
                                       128 * sizeof(pixel), 128, 128,
-                                      rand() & 15, rand() & 15
+                                      rnd() & 15, rnd() & 15
                                       HIGHBD_TAIL_SUFFIX);
     }
 }
@@ -149,7 +149,7 @@
             for (int h = imax(w / 4, 4); h <= imin(w * 4, 128); h <<= 1)
             {
 #if BITDEPTH == 16
-                const int bitdepth_max = rand() & 1 ? 0x3ff : 0xfff;
+                const int bitdepth_max = rnd() & 1 ? 0x3ff : 0xfff;
 #else
                 const int bitdepth_max = 0xff;
 #endif
@@ -176,9 +176,9 @@
         if (check_func(c->w_avg, "w_avg_w%d_%dbpc", w, BITDEPTH))
             for (int h = imax(w / 4, 4); h <= imin(w * 4, 128); h <<= 1)
             {
-                int weight = rand() % 15 + 1;
+                int weight = rnd() % 15 + 1;
 #if BITDEPTH == 16
-                const int bitdepth_max = rand() & 1 ? 0x3ff : 0xfff;
+                const int bitdepth_max = rnd() & 1 ? 0x3ff : 0xfff;
 #else
                 const int bitdepth_max = 0xff;
 #endif
@@ -201,7 +201,7 @@
     ALIGN_STK_32(uint8_t, mask,  128 * 128,);
 
     for (int i = 0; i < 128 * 128; i++)
-        mask[i] = rand() % 65;
+        mask[i] = rnd() % 65;
 
     declare_func(void, pixel *dst, ptrdiff_t dst_stride, const int16_t *tmp1,
                  const int16_t *tmp2, int w, int h, const uint8_t *mask
@@ -212,7 +212,7 @@
             for (int h = imax(w / 4, 4); h <= imin(w * 4, 128); h <<= 1)
             {
 #if BITDEPTH == 16
-                const int bitdepth_max = rand() & 1 ? 0x3ff : 0xfff;
+                const int bitdepth_max = rnd() & 1 ? 0x3ff : 0xfff;
 #else
                 const int bitdepth_max = 0xff;
 #endif
@@ -246,9 +246,9 @@
                            BITDEPTH))
                 for (int h = imax(w / 4, 4); h <= imin(w * 4, 128); h <<= 1)
                 {
-                    int sign = rand() & 1;
+                    int sign = rnd() & 1;
 #if BITDEPTH == 16
-                    const int bitdepth_max = rand() & 1 ? 0x3ff : 0xfff;
+                    const int bitdepth_max = rnd() & 1 ? 0x3ff : 0xfff;
 #else
                     const int bitdepth_max = 0xff;
 #endif
@@ -284,16 +284,16 @@
         if (check_func(c->blend, "blend_w%d_%dbpc", w, BITDEPTH))
             for (int h = imax(w / 2, 4); h <= imin(w * 2, 32); h <<= 1) {
 #if BITDEPTH == 16
-                const int bitdepth_max = rand() & 1 ? 0x3ff : 0xfff;
+                const int bitdepth_max = rnd() & 1 ? 0x3ff : 0xfff;
 #else
                 const int bitdepth_max = 0xff;
 #endif
                 for (int i = 0; i < 32 * 32; i++) {
-                    tmp[i] = rand() & bitdepth_max;
-                    mask[i] = rand() % 65;
+                    tmp[i] = rnd() & bitdepth_max;
+                    mask[i] = rnd() % 65;
                 }
                 for (int i = 0; i < w * h; i++)
-                    c_dst[i] = a_dst[i] = rand() & bitdepth_max;
+                    c_dst[i] = a_dst[i] = rnd() & bitdepth_max;
 
                 call_ref(c_dst, dst_stride, tmp, w, h, mask);
                 call_new(a_dst, dst_stride, tmp, w, h, mask);
@@ -319,15 +319,15 @@
         if (check_func(c->blend_v, "blend_v_w%d_%dbpc", w, BITDEPTH))
             for (int h = 2; h <= (w == 2 ? 64 : 128); h <<= 1) {
 #if BITDEPTH == 16
-                const int bitdepth_max = rand() & 1 ? 0x3ff : 0xfff;
+                const int bitdepth_max = rnd() & 1 ? 0x3ff : 0xfff;
 #else
                 const int bitdepth_max = 0xff;
 #endif
 
                 for (int i = 0; i < w * h; i++)
-                    c_dst[i] = a_dst[i] = rand() & bitdepth_max;
+                    c_dst[i] = a_dst[i] = rnd() & bitdepth_max;
                 for (int i = 0; i < 32 * 128; i++)
-                    tmp[i] = rand() & bitdepth_max;
+                    tmp[i] = rnd() & bitdepth_max;
 
                 call_ref(c_dst, dst_stride, tmp, w, h);
                 call_new(a_dst, dst_stride, tmp, w, h);
@@ -353,14 +353,14 @@
         if (check_func(c->blend_h, "blend_h_w%d_%dbpc", w, BITDEPTH))
             for (int h = (w == 128 ? 4 : 2); h <= 32; h <<= 1) {
 #if BITDEPTH == 16
-                const int bitdepth_max = rand() & 1 ? 0x3ff : 0xfff;
+                const int bitdepth_max = rnd() & 1 ? 0x3ff : 0xfff;
 #else
                 const int bitdepth_max = 0xff;
 #endif
                 for (int i = 0; i < w * h; i++)
-                    c_dst[i] = a_dst[i] = rand() & bitdepth_max;
+                    c_dst[i] = a_dst[i] = rnd() & bitdepth_max;
                 for (int i = 0; i < 128 * 32; i++)
-                    tmp[i] = rand() & bitdepth_max;
+                    tmp[i] = rnd() & bitdepth_max;
 
                 call_ref(c_dst, dst_stride, tmp, w, h);
                 call_new(a_dst, dst_stride, tmp, w, h);
@@ -387,19 +387,19 @@
                  HIGHBD_DECL_SUFFIX);
 
     if (check_func(c->warp8x8, "warp_8x8_%dbpc", BITDEPTH)) {
-        const int mx = (rand() & 0x1fff) - 0x800;
-        const int my = (rand() & 0x1fff) - 0x800;
+        const int mx = (rnd() & 0x1fff) - 0x800;
+        const int my = (rnd() & 0x1fff) - 0x800;
 #if BITDEPTH == 16
-        const int bitdepth_max = rand() & 1 ? 0x3ff : 0xfff;
+        const int bitdepth_max = rnd() & 1 ? 0x3ff : 0xfff;
 #else
         const int bitdepth_max = 0xff;
 #endif
 
         for (int i = 0; i < 4; i++)
-            abcd[i] = (rand() & 0x1fff) - 0x800;
+            abcd[i] = (rnd() & 0x1fff) - 0x800;
 
         for (int i = 0; i < 15 * 15; i++)
-            src_buf[i] = rand() & bitdepth_max;
+            src_buf[i] = rnd() & bitdepth_max;
 
         call_ref(c_dst, dst_stride, src, src_stride, abcd, mx, my HIGHBD_TAIL_SUFFIX);
         call_new(a_dst, dst_stride, src, src_stride, abcd, mx, my HIGHBD_TAIL_SUFFIX);
@@ -424,19 +424,19 @@
                  HIGHBD_DECL_SUFFIX);
 
     if (check_func(c->warp8x8t, "warp_8x8t_%dbpc", BITDEPTH)) {
-        const int mx = (rand() & 0x1fff) - 0x800;
-        const int my = (rand() & 0x1fff) - 0x800;
+        const int mx = (rnd() & 0x1fff) - 0x800;
+        const int my = (rnd() & 0x1fff) - 0x800;
 #if BITDEPTH == 16
-        const int bitdepth_max = rand() & 1 ? 0x3ff : 0xfff;
+        const int bitdepth_max = rnd() & 1 ? 0x3ff : 0xfff;
 #else
         const int bitdepth_max = 0xff;
 #endif
 
         for (int i = 0; i < 4; i++)
-            abcd[i] = (rand() & 0x1fff) - 0x800;
+            abcd[i] = (rnd() & 0x1fff) - 0x800;
 
         for (int i = 0; i < 15 * 15; i++)
-            src_buf[i] = rand() & bitdepth_max;
+            src_buf[i] = rnd() & bitdepth_max;
 
         call_ref(c_tmp, 8, src, src_stride, abcd, mx, my HIGHBD_TAIL_SUFFIX);
         call_new(a_tmp, 8, src, src_stride, abcd, mx, my HIGHBD_TAIL_SUFFIX);
@@ -473,21 +473,21 @@
                                    const enum EdgeFlags edge)
 {
 #define set_off(edge1, edge2, pos, dim) \
-    *i##dim = edge & (HAVE_##edge1 | HAVE_##edge2) ? 160 : 1 + (rand() % (b##dim - 2)); \
+    *i##dim = edge & (HAVE_##edge1 | HAVE_##edge2) ? 160 : 1 + (rnd() % (b##dim - 2)); \
     switch (edge & (HAVE_##edge1 | HAVE_##edge2)) { \
     case HAVE_##edge1 | HAVE_##edge2: \
         assert(b##dim <= *i##dim); \
-        *pos = rand() % (*i##dim - b##dim + 1); \
+        *pos = rnd() % (*i##dim - b##dim + 1); \
         break; \
     case HAVE_##edge1: \
-        *pos = (*i##dim - b##dim) + 1 + (rand() % (b##dim - 1)); \
+        *pos = (*i##dim - b##dim) + 1 + (rnd() % (b##dim - 1)); \
         break; \
     case HAVE_##edge2: \
-        *pos = -(1 + (rand() % (b##dim - 1))); \
+        *pos = -(1 + (rnd() % (b##dim - 1))); \
         break; \
     case 0: \
         assert(b##dim - 1 > *i##dim); \
-        *pos = -(1 + (rand() % (b##dim - *i##dim - 1))); \
+        *pos = -(1 + (rnd() % (b##dim - *i##dim - 1))); \
         break; \
     }
     set_off(LEFT, RIGHT, x, w);
@@ -500,7 +500,7 @@
     ALIGN_STK_32(pixel, src,   160 * 160,);
 
     for (int i = 0; i < 160 * 160; i++)
-        src[i] = rand() & ((1U << BITDEPTH) - 1);
+        src[i] = rnd() & ((1U << BITDEPTH) - 1);
 
     declare_func(void, intptr_t bw, intptr_t bh, intptr_t iw, intptr_t ih,
                  intptr_t x, intptr_t y,
@@ -513,8 +513,8 @@
             for (int h = imax(w / 4, 4); h <= imin(w * 4, 128); h <<= 1) {
                 // we skip 0xf, since it implies that we don't need emu_edge
                 for (enum EdgeFlags edge = 0; edge < 0xf; edge++) {
-                    const int bw = w + (rand() & 7);
-                    const int bh = h + (rand() & 7);
+                    const int bw = w + (rnd() & 7);
+                    const int bh = h + (rnd() & 7);
                     random_offset_for_edge(&x, &y, bw, bh, &iw, &ih, edge);
                     call_ref(bw, bh, iw, ih, x, y,
                              c_dst, 192 * sizeof(pixel), src, 160 * sizeof(pixel));