| 1 | #! /usr/bin/awk -f |
| 2 | # |
| 3 | # $Id: mpx-gen,v 1.1 1999/11/14 13:53:44 mdw Exp $ |
| 4 | # |
| 5 | # Generate test vectors for MPX testing |
| 6 | |
| 7 | # --- Generate an `l'-byte hex number --- |
| 8 | |
| 9 | function r(l, i, s, x) |
| 10 | { |
| 11 | if (!l) l = len; |
| 12 | s = ""; |
| 13 | for (i = 0; i < l; i++) { |
| 14 | x = int(rand() * 256); |
| 15 | s = s sprintf("%02X", x); |
| 16 | } |
| 17 | return (s); |
| 18 | } |
| 19 | |
| 20 | # --- Main code --- |
| 21 | |
| 22 | BEGIN { |
| 23 | |
| 24 | # --- Initialization --- |
| 25 | |
| 26 | i = 1; |
| 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; |
| 30 | |
| 31 | # --- Output filters --- |
| 32 | |
| 33 | bc = "bc | sed 'y/ABCDEF/abcdef/; \ |
| 34 | s/^[0-9a-f]\\([0-9a-f][0-9a-f]\\)*$/0&/; \ |
| 35 | s/^/ /; \ |
| 36 | $ s/$/;/'"; |
| 37 | out = "sed 'y/ABCDEF/abcdef/; s/^/ /'" |
| 38 | |
| 39 | # --- Main code --- |
| 40 | |
| 41 | srand(); |
| 42 | |
| 43 | while (rep--) { |
| 44 | x = r(); |
| 45 | |
| 46 | print "obase = 16" | bc; |
| 47 | print "ibase = 16" | bc; |
| 48 | |
| 49 | # --- Shifting operations --- |
| 50 | |
| 51 | if (op == "<<" || op == ">>") { |
| 52 | y = int(rand() * len * 4) + int(rand() * len * 4); |
| 53 | rop = (op == "<<" ? "*" : "/"); |
| 54 | z = sprintf("%X", y); |
| 55 | print x, y | out; |
| 56 | print x, rop, "(2 ^ " z ")" | bc; |
| 57 | } |
| 58 | |
| 59 | # --- Division --- |
| 60 | |
| 61 | else if (op == "/") { |
| 62 | ylen = int(rand() * len) + 1; |
| 63 | y = r(ylen); |
| 64 | print x | out; |
| 65 | print y | out; |
| 66 | print x, "/", y | bc; |
| 67 | print x, "%", y | bc; |
| 68 | } |
| 69 | |
| 70 | # --- Squaring --- |
| 71 | |
| 72 | else if (op == "2") { |
| 73 | print x | out; |
| 74 | print x, "*", x | bc; |
| 75 | } |
| 76 | |
| 77 | # --- Other operations --- |
| 78 | |
| 79 | else { |
| 80 | y = r(); |
| 81 | if (op == "-" && x < y) { |
| 82 | t = x; x = y; y = t; |
| 83 | } |
| 84 | print x | out; |
| 85 | print y | out; |
| 86 | print x, op, y | bc; |
| 87 | } |
| 88 | |
| 89 | close(out); |
| 90 | close(bc); |
| 91 | if (rep) |
| 92 | print; |
| 93 | } |
| 94 | |
| 95 | exit 0; |
| 96 | } |