CUDApp
CUDA++: AIEN’s GPU machine-code toolchain, runtime and driver client for NVIDIA GPUs without the CUDA toolkit. Hardware coverage and driver replacement limits are explicit.
Brought by drakestapleton
CUDApp / tests / dis_words_test.c
| 1 | /* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ |
| 2 | #include "omega_dis_words.h" |
| 3 | #include "omega_sm121_disasm.h" |
| 4 | #include <stdio.h> |
| 5 | #include <string.h> |
| 6 | extern uint64_t oracle_word(const uint8_t *, uint64_t, uint64_t, uint64_t); |
| 7 | static unsigned cases; |
| 8 | static int check(const uint8_t *b, uint64_t mode, uint64_t at, uint64_t prev, int plant) { |
| 9 | uint64_t a = omega_dis_word(b, mode, at, prev), c = oracle_word(b, mode, at, prev); |
| 10 | cases++; |
| 11 | if (plant) a ^= 1; |
| 12 | if (a != c) { fprintf(stderr, "word mismatch case %u\n", cases); return 1; } |
| 13 | return 0; |
| 14 | } |
| 15 | int main(int argc, char **argv) { |
| 16 | int plant = argc > 1 && !strcmp(argv[1], "--plant"); |
| 17 | uint8_t b[64] = {0}; |
| 18 | const uint64_t edges[] = {0,1,15,16,17,UINT32_MAX-1,UINT32_MAX}; |
| 19 | for (unsigned p = 0; p < 8; p++) for (unsigned v = 0; v < 256; v++) { |
| 20 | memset(b, 0, sizeof b); b[p] = (uint8_t)v; |
| 21 | if (check(b,0,0,0,plant)) return 1; |
| 22 | } |
| 23 | for (unsigned op = 0; op < 65536; op++) { |
| 24 | b[0] = op; b[1] = op >> 8; |
| 25 | for (unsigned e = 0; e < sizeof edges/sizeof edges[0]; e++) { |
| 26 | if (check(b,1,edges[e],edges[e],0)) return 1; |
| 27 | } |
| 28 | } |
| 29 | memset(b,0,sizeof b); |
| 30 | if (omega_sm121_padding_start(NULL,64)) return 1; |
| 31 | for (unsigned p = 0; p < 4; p++) { |
| 32 | b[p*16] = 0x4d; b[p*16+1] = 0x79; |
| 33 | for (unsigned n = 0; n <= 64; n++) { |
| 34 | size_t want = 0; |
| 35 | for (size_t at = 0; at + 16 <= n; at += 16) |
| 36 | want = oracle_word(b+at,1,at,want); |
| 37 | if (omega_sm121_padding_start(b,n) != want) return 1; |
| 38 | } |
| 39 | } |
| 40 | printf("DISASM WORDS PASS cases=%u\n",cases); |
| 41 | return 0; |
| 42 | } |