chiark / gitweb /
Infrastructure: Split the files into subdirectories.
[mLib] / bits-testgen.c
diff --git a/bits-testgen.c b/bits-testgen.c
deleted file mode 100644 (file)
index bd52b30..0000000
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- * Generate random test vectors for 64-bit operations.
- *
- * As an independent reference, we use the Catacomb multiprecision integer
- * library.
- */
-
-#include <stdio.h>
-
-#include <catacomb/mp.h>
-#include <catacomb/mprand.h>
-#include <catacomb/fibrand.h>
-
-static mp *m64;
-static grand *r;
-
-#define NVEC 64
-
-static mp *mp_rol(mp *d, mp *x, unsigned s)
-{
-  mp *l = mp_lsl(MP_NEW, x, s);
-  mp *r = mp_lsr(MP_NEW, x, 64 - s);
-  d = mp_add(d, l, r);
-  mp_drop(l);
-  mp_drop(r);
-  return (d);
-}
-
-static mp *mp_ror(mp *d, mp *x, unsigned s)
-{
-  mp *l = mp_lsl(MP_NEW, x, 64 - s);
-  mp *r = mp_lsr(MP_NEW, x, s);
-  d = mp_add(d, l, r);
-  mp_drop(l);
-  mp_drop(r);
-  return (d);
-}
-
-static void putmp(mp *x)
-{
-  octet buf[8];
-  unsigned i;
-  fputc(' ', stdout);
-  mp_storeb(x, buf, sizeof(buf));
-  for (i = 0; i < sizeof(buf); i++)
-    printf("%02x", buf[i]);
-}
-
-#define GEN_SHIFT(op)                                                  \
-                                                                       \
-static void gen_##op(void)                                             \
-{                                                                      \
-  unsigned i;                                                          \
-  fputs("\n" #op "64 {\n", stdout);                                    \
-  for (i = 0; i < NVEC; i++) {                                         \
-    mp *x = mprand_range(MP_NEW, m64, r, 0);                           \
-    unsigned s = r->ops->range(r, 70), ss = s & 63;                    \
-    mp *y = mp_##op(MP_NEW, x, ss);                                    \
-    mp_div(0, &y, y, m64);                                             \
-                                                                       \
-    fputs(" ", stdout);                                                        \
-    putmp(x); printf(" %2u", s); putmp(y);                             \
-    fputs(";\n", stdout);                                              \
-    mp_drop(x); mp_drop(y);                                            \
-  }                                                                    \
-  for (i = 0; i < 4; i++) {                                            \
-    mp *x = mprand_range(MP_NEW, m64, r, 0);                           \
-    mp *y = mp_##op(MP_NEW, x, 32);                                    \
-    mp_div(0, &y, y, m64);                                             \
-                                                                       \
-    fputs(" ", stdout);                                                        \
-    putmp(x); printf(" 32"); putmp(y);                                 \
-    fputs(";\n", stdout);                                              \
-    mp_drop(x); mp_drop(y);                                            \
-  }                                                                    \
-  fputs("}\n", stdout);                                                        \
-}
-
-#define GEN_ARITH(op)                                                  \
-                                                                       \
-static void gen_##op(void)                                             \
-{                                                                      \
-  unsigned i;                                                          \
-  fputs("\n" #op "64 {\n", stdout);                                    \
-  for (i = 0; i < NVEC; i++) {                                         \
-    mp *x = mprand_range(MP_NEW, m64, r, 0);                           \
-    mp *y = mprand_range(MP_NEW, m64, r, 0);                           \
-    mp *z = mp_##op(MP_NEW, x, y);                                     \
-    mp_div(0, &z, z, m64);                                             \
-                                                                       \
-    fputs(" ", stdout);                                                        \
-    putmp(x); putmp(y); putmp(z);                                      \
-    fputs(";\n", stdout);                                              \
-    mp_drop(x); mp_drop(y); mp_drop(z);                                        \
-  }                                                                    \
-  fputs("}\n", stdout);                                                        \
-}
-
-GEN_SHIFT(lsl)
-GEN_SHIFT(lsr)
-GEN_SHIFT(rol)
-GEN_SHIFT(ror)
-GEN_ARITH(add)
-GEN_ARITH(sub)
-
-int main(void)
-{
-  m64 = mp_lsl(MP_NEW, MP_ONE, 64);
-  r = fibrand_create(0);
-  fputs("# Test vectors for 64-bit operations [generated]\n", stdout);
-
-  gen_lsl();
-  gen_lsr();
-  gen_rol();
-  gen_ror();
-  gen_add();
-  gen_sub();
-  return (0);
-}