3 # Generate test vectors for MPX testing
5 # --- Generate an `l'-byte hex number ---
11 for (i = 0; i < l; i++) {
12 x = int(rand() * 256);
13 s = s sprintf("%02X", x);
22 # --- Initialization ---
25 if (i in ARGV) len = ARGV[i++]; else len = 32;
26 if (i in ARGV) op = ARGV[i++]; else op = "+";
27 if (i in ARGV) rep = ARGV[i++]; else rep = 1;
29 # --- Output filters ---
31 # This is complicated. `bc' emits numbers split over multiple lines with
32 # backslashes. It also doesn't pad to an even number of digits, which the
33 # test rig is expecting, or use lower-case, which looks nicer.
35 # The first bit matches a line ending with a backslash. If it finds one,
36 # it appends the next line, removes the backslash/newline pair, and loops
39 # The next substitution translates the whole kaboodle into lower-case.
41 # The next one looks for an off number of hex digits and prepends a zero if
44 # The one after that just indents by two spaces. The final one sticks a
45 # semicolon on the end.
56 s/^[0-9a-f]\\([0-9a-f][0-9a-f]\\)*$/0&/\n\
59 out = "sed 'y/ABCDEF/abcdef/; s/^/ /'"
68 print "obase = 16" | bc;
69 print "ibase = 16" | bc;
71 # --- Shifting operations ---
73 if (op == "<<" || op == ">>") {
74 y = int(rand() * len * 4) + int(rand() * len * 4);
75 rop = (op == "<<" ? "*" : "/");
78 print x, rop, "(2 ^ " z ")" | bc;
84 ylen = int(rand() * len) + 1;
99 # --- Other operations ---
103 if (op == "-" && x < y) {