Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/CUDApp/blob/main/om/encoder/ldg_offset_test.om # 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 Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `CUDApp / om / encoder / ldg_offset_test.om` 164 lines · 4070 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 2 note ldg_offset_test.om: gate for the signed 24-bit byte offset of LDG.E (op 11) in the seeded encoder (#373). 3 note Concatenate after bw_enc_sm121.om; mk/om-encoder.mk test-om-encoder-ldg compiles it with the pinned omc. 4 note No arguments: every row through enc1. Accepted offsets 0, +0x40, -0x100000, +0x7fffff, -0x800000 must give 5 note exactly the words below; +0x800000, -0x800001, 0x7fffffff and 0x80000000 must be refused. 6 note Exit 0, else 10+r for accepted row r, 20+r for refused row r. 7 note One argument: write the five accepted instructions (80 bytes) on stdout for the ORACLE. 8 note Two arguments: read the ORACLE's text on stdin and require the five LDG.E lines of ldgnd in order. 9 note Exit 0, 4 when a line is missing or out of order, 70 on a read error, 71 when the text is too long. 10 note ORACLE (independent, not first-party, never shipped): NVIDIA nvdisasm 13.0.85 -b SM121 -hex. The packing is the 11 note C encoder's (src/omega_blackwell_codegen.c bw_c_encode_insn: w1 = ureg or (imm and 0xffffff) shl 8); the 12 note first four w1 values are the words that encoder produced in #373's freestanding run. 13 note Operands: R2 <- desc[UR8][R30.64+imm]. Decimal constants by Wolfram: w0 `503478657` = 0x1e027981, 14 note w2 `203299072` = 0x0c1e1900, w3 991744 = 0x000f2200; w1: 8, 16392 = 0x4008, `4026531848` = 0xf0000008, 15 note `2147483400` = 0x7fffff08, `2147483656` = 0x80000008. Offsets as uint32: 64, `4293918720` = -0x100000, 16 note `8388607`, `4286578688` = -0x800000; refused `8388608` = 0x800000, `4286578687` = -0x800001, `2147483647`, `2147483648`. 17 text ldgnd "LDG.E R2, desc[UR8][R30.64] ;|LDG.E R2, desc[UR8][R30.64+0x40] ;|LDG.E R2, desc[UR8][R30.64+-0x100000] ;|LDG.E R2, desc[UR8][R30.64+0x7fffff] ;|LDG.E R2, desc[UR8][R30.64+-0x800000] ;|" 18 global lt_imm ulong 5 19 global lt_w1 ulong 5 20 global lt_bad ulong 4 21 22 fn lt_init to void 23 put lt_imm 0 0 24 put lt_imm 1 64 25 put lt_imm 2 `4293918720` 26 put lt_imm 3 `8388607` 27 put lt_imm 4 `4286578688` 28 put lt_w1 0 8 29 put lt_w1 1 16392 30 put lt_w1 2 `4026531848` 31 put lt_w1 3 `2147483400` 32 put lt_w1 4 `2147483656` 33 put lt_bad 0 `8388608` 34 put lt_bad 1 `4286578687` 35 put lt_bad 2 `2147483647` 36 put lt_bad 3 `2147483648` 37 end 38 39 note encode LDG.E R2, desc[UR8][R30.64+imm] into w; enc1's result (0 accepted) 40 fn lt_enc imm ulong w edit ulong 4 to ulong 41 o = new ulong 16 0 42 put o 0 11 43 put o 1 2 44 put o 2 30 45 put o 5 8 46 put o 6 imm 47 ret enc1 view o w 48 end 49 50 fn lt_words w view ulong 4 r ulong to bool 51 if ne get w 0 `503478657` 52 ret false 53 end 54 if ne get w 1 get lt_w1 r 55 ret false 56 end 57 if ne get w 2 `203299072` 58 ret false 59 end 60 ret eq get w 3 991744 61 end 62 63 fn lt_rows to int 64 w = new ulong 4 0 65 for r ulong 5 66 if ne lt_enc get lt_imm r edit w 0 67 ret int add 10 r 68 end 69 if not lt_words view w r 70 ret int add 10 r 71 end 72 end 73 for r ulong 4 74 if eq lt_enc get lt_bad r edit w 0 75 ret int add 20 r 76 end 77 end 78 ret 0 79 end 80 81 fn lt_bin to int 82 w = new ulong 4 0 83 code = new uchar 16384 0 84 for r ulong 5 85 if ne lt_enc get lt_imm r edit w 0 86 ret int add 10 r 87 end 88 store edit code r view w 89 end 90 off = ulong 0 91 while lt off 80 92 n = write 1 code off sub 80 off 93 if le n 0 94 ret 3 95 end 96 off = add off ulong n 97 end 98 ret 0 99 end 100 101 note does needle ldgnd[s..e) start at buf[i]? The caller keeps i + e - s within the text. 102 fn lt_at buf view uchar 65536 i ulong s ulong e ulong to bool 103 for j ulong sub e s 104 if ne get buf add i j get ldgnd add s j 105 ret false 106 end 107 end 108 ret true 109 end 110 111 note the end of the first match of ldgnd[s..e) in buf[i..n), or n+1 when absent 112 fn lt_find buf view uchar 65536 n ulong i ulong s ulong e ulong to ulong 113 while le add i sub e s n 114 if lt_at buf i s e 115 ret add i sub e s 116 end 117 i = add i 1 118 end 119 ret add n 1 120 end 121 122 fn lt_check to int 123 buf = new uchar 65536 0 124 n = ulong 0 125 while lt n 65536 126 k = read 0 buf n sub 65536 n 127 if lt k 0 128 ret 70 129 end 130 if eq k 0 131 break 132 end 133 n = add n ulong k 134 end 135 if eq n 65536 136 ret 71 137 end 138 pos = ulong 0 139 s = ulong 0 140 for e ulong len ldgnd 141 if eq get ldgnd e 124 142 pos = lt_find view buf n pos s e 143 if gt pos n 144 ret 4 145 end 146 s = add e 1 147 end 148 end 149 ret 0 150 end 151 152 fn main to int 153 lt_init 154 if gt argcnt 3 155 ret 64 156 end 157 if eq argcnt 3 158 ret lt_check 159 end 160 if eq argcnt 2 161 ret lt_bin 162 end 163 ret lt_rows 164 end