3 # $Id: mpx-gen,v 1.2 1999/12/10 23:26:51 mdw Exp $
5 # Generate test vectors for MPX testing
7 # --- Generate an `l'-byte hex number ---
13 for (i =
0; i
< l
; i
++) {
14 x = int
(rand
() * 256);
15 s = s
sprintf("%02X", x
);
24 # --- Initialization ---
27 if (i in
ARGV) len =
ARGV[i
++]; else len =
32;
28 if (i in
ARGV) op =
ARGV[i
++]; else op =
"+";
29 if (i in
ARGV) rep =
ARGV[i
++]; else rep =
1;
31 # --- Output filters ---
33 # This is complicated. `bc' emits numbers split over multiple lines with
34 # backslashes. It also doesn't pad to an even number of digits, which the
35 # test rig is expecting, or use lower-case, which looks nicer.
37 # The first bit matches a line ending with a backslash. If it finds one,
38 # it appends the next line, removes the backslash/newline pair, and loops
41 # The next substitution translates the whole kaboodle into lower-case.
43 # The next one looks for an off number of hex digits and prepends a zero if
46 # The one after that just indents by two spaces. The final one sticks a
47 # semicolon on the end.
58 s/^[0-9a-f]\\([0-9a-f][0-9a-f]\\)*$/0&/\n\
61 out =
"sed 'y/ABCDEF/abcdef/; s/^/ /'"
70 print "obase = 16" | bc
;
71 print "ibase = 16" | bc
;
73 # --- Shifting operations ---
75 if (op ==
"<<" || op ==
">>") {
76 y = int
(rand
() * len
* 4) + int
(rand
() * len
* 4);
77 rop =
(op ==
"<<" ?
"*" : "/");
80 print x
, rop
, "(2 ^ " z
")" | bc
;
86 ylen = int
(rand
() * len
) + 1;
101 # --- Other operations ---
105 if (op == "-" && x < y) {