| 1 | /* -*-apcalc-*- |
| 2 | * |
| 3 | * Generate test cases for %$\gf{2}[x]$% arithmetic |
| 4 | * |
| 5 | * (c) 2000 Straylight/Edgeware |
| 6 | */ |
| 7 | |
| 8 | /*----- Licensing notice --------------------------------------------------* |
| 9 | * |
| 10 | * This file is part of Catacomb. |
| 11 | * |
| 12 | * Catacomb is free software; you can redistribute it and/or modify |
| 13 | * it under the terms of the GNU Library General Public License as |
| 14 | * published by the Free Software Foundation; either version 2 of the |
| 15 | * License, or (at your option) any later version. |
| 16 | * |
| 17 | * Catacomb is distributed in the hope that it will be useful, |
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | * GNU Library General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU Library General Public |
| 23 | * License along with Catacomb; if not, write to the Free |
| 24 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
| 25 | * MA 02111-1307, USA. |
| 26 | */ |
| 27 | |
| 28 | /*----- External units ----------------------------------------------------*/ |
| 29 | |
| 30 | read gfx; |
| 31 | |
| 32 | /*----- Global variables --------------------------------------------------*/ |
| 33 | |
| 34 | global op = "+", n = 40, bits = 128; |
| 35 | |
| 36 | /*----- Main code ---------------------------------------------------------*/ |
| 37 | |
| 38 | dummy = config("lib_debug", -1); |
| 39 | |
| 40 | define gfx_test() { |
| 41 | local i, j, x; |
| 42 | local a, b, l; |
| 43 | |
| 44 | for (i = 0; i < n; i++) { |
| 45 | |
| 46 | /* --- Select the inputs and produce the outputs --- */ |
| 47 | |
| 48 | switch (op) { |
| 49 | case '+': |
| 50 | case '-': |
| 51 | a = gf(random(1 << bits)); |
| 52 | b = gf(random(1 << bits)); |
| 53 | l = list(a, b, a + b); |
| 54 | break; |
| 55 | case '*': |
| 56 | a = gf(random(1 << bits)); |
| 57 | b = gf(random(1 << bits)); |
| 58 | l = list(a, b, a * b); |
| 59 | break; |
| 60 | case '2': |
| 61 | a = gf(random(1 << bits)); |
| 62 | l = list(a, a * a); |
| 63 | break; |
| 64 | case '/': |
| 65 | a = gf(random(1 << (bits + random(bits)))); |
| 66 | b = gf(random(1 << bits)); |
| 67 | l = list(a, b, a / b, a % b); |
| 68 | break; |
| 69 | default: |
| 70 | exit "unknown operator"; |
| 71 | break; |
| 72 | } |
| 73 | |
| 74 | /* --- Output the test vector --- * |
| 75 | * |
| 76 | * Be careful to ensure that it has an even number of hex digits in each |
| 77 | * number. |
| 78 | */ |
| 79 | |
| 80 | for (j = 0; j < size(l); j++) { |
| 81 | x = strprintf("%x", l[[j]].x); |
| 82 | if (strlen(x) > 1) |
| 83 | x = substr(x, 3, strlen(x) - 2); |
| 84 | if (strlen(x) % 2) |
| 85 | x = strcat("0", x); |
| 86 | x = strcat(" ", x); |
| 87 | if (j) |
| 88 | x = strcat(" ", x); |
| 89 | if (j == size(l) - 1) |
| 90 | x = strcat(x, ";"); |
| 91 | printf("%s\n", x); |
| 92 | } |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | /*----- That's all, folks -------------------------------------------------*/ |