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/bw_spec_cmp.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 / bw_spec_cmp.om` 313 lines · 4676 bytes Raw Blame History 1 note bw_spec_cmp.om: comparison of spec-driven encoder/decoder vs reference encoder 2 3 fn read_exact fd int buf edit uchar 128 n ulong to long 4 got = ulong 0 5 while lt got n bound 128 6 r = read fd buf got sub n got 7 if lt r 0 8 ret -1 9 end 10 if eq r 0 11 if ne got 0 12 ret -1 13 end 14 ret 0 15 end 16 got = add got ulong r 17 end 18 ret long got 19 end 20 21 fn unpack_u64 buf view uchar 128 off ulong to ulong 22 v = ulong 0 23 for b ulong 8 24 sh = mul b 8 25 byte_v = ulong get buf add off b 26 v = or v shl byte_v sh 27 end 28 ret v 29 end 30 31 fn unpack_case buf view uchar 128 o edit ulong 16 to void 32 for i ulong 16 33 off = mul i 8 34 put o i unpack_u64 buf off 35 end 36 end 37 38 note Compare active semantic roles, not inactive packing slots. Zero control 39 note and FSET default are documented canonicalizations, absent RA/RB means RZ. 40 note Keep field-local values out of the seeded comparator's register live range. 41 fn same_fld sp_tbl view ulong 3001 fb ulong o view ulong 16 dec view ulong 16 to bool 42 role = get sp_tbl fb 43 word = get sp_tbl add fb 1 44 a = sp_val role word o 45 b = sp_val role word dec 46 if and eq role R_FSET eq a 0 47 a = `66084864` 48 end 49 if ne a b 50 ret false 51 end 52 ret true 53 end 54 55 fn same_sem sp_tbl view ulong 3001 o view ulong 16 dec view ulong 16 to bool 56 idx = sp_find sp_tbl o 57 if eq idx 63 58 ret false 59 end 60 if ne sp_find sp_tbl dec idx 61 ret false 62 end 63 if ne get o 0 get dec 0 64 ret false 65 end 66 base = mul idx 45 67 control = get o 7 68 if eq control 0 69 control = get sp_tbl add base 8 70 if eq get o 0 46 71 if and eq get o 6 0 eq get o 9 0 72 control = `1032192` 73 else 74 control = `1042944` 75 end 76 end 77 end 78 if ne control get dec 7 79 ret false 80 end 81 nf = get sp_tbl add base 9 82 for f ulong nf 83 fb = add add base 10 mul f 7 84 if not same_fld sp_tbl fb o dec 85 ret false 86 end 87 end 88 ret true 89 end 90 91 fn run_check_loop sp_tbl edit ulong 3001 corrupt bool to int 92 buf = new uchar 128 0 93 o = new ulong 16 0 94 w_ref = new ulong 4 0 95 w_spec = new ulong 4 0 96 o_dec = new ulong 16 0 97 count = ulong 0 98 99 while lt count 500 bound 500 100 r = read_exact int 0 buf 128 101 if lt r 0 102 ret 2 103 end 104 if eq r 0 105 break 106 end 107 unpack_case buf o 108 if ne enc1 o w_ref 0 109 ret 1 110 end 111 if ne sp_enc sp_tbl o w_spec 0 112 ret 1 113 end 114 if and corrupt eq count 0 115 put w_ref 0 xor get w_ref 0 1 116 end 117 for k ulong 4 118 if ne get w_ref k get w_spec k 119 ret 1 120 end 121 end 122 if ne sp_dec sp_tbl w_spec o_dec 0 123 ret 1 124 end 125 if not same_sem sp_tbl o o_dec 126 ret 1 127 end 128 count = add count 1 129 end 130 131 if ne count 461 132 ret 1 133 end 134 ret 0 135 end 136 137 fn emit_sample sp_tbl edit ulong 3001 s_idx ulong to int 138 o = new ulong 16 0 139 w = new ulong 4 0 140 buf = new uchar 16 0 141 142 if eq s_idx 0 143 note NOP 144 put o 0 0 145 end 146 if eq s_idx 1 147 note IMAD R0, R1, R2, R3 148 put o 0 8 149 put o 1 0 150 put o 2 1 151 put o 3 2 152 put o 4 3 153 put o 12 1 154 put o 13 1 155 end 156 if eq s_idx 2 157 note FADD R4, R5, R6 158 put o 0 30 159 put o 1 4 160 put o 2 5 161 put o 3 6 162 put o 12 1 163 put o 13 1 164 end 165 if eq s_idx 3 166 note LDG.E R10, desc[UR5][R12.64] 167 put o 0 11 168 put o 1 10 169 put o 2 12 170 put o 5 5 171 put o 12 1 172 put o 14 1 173 end 174 if eq s_idx 4 175 note BRA 0x100 176 put o 0 46 177 put o 6 16 178 end 179 180 st = sp_enc sp_tbl o w 181 if ne st 0 182 ret 1 183 end 184 185 for i ulong 4 186 v = get w i 187 off = mul i 4 188 for b ulong 4 189 sh = mul b 8 190 put buf add off b uchar and shr v sh 255 191 end 192 end 193 194 sent = ulong 0 195 while lt sent 16 bound 16 196 k = write int 1 buf sent sub 16 sent 197 if le k 0 198 ret 1 199 end 200 sent = add sent ulong k 201 end 202 ret 0 203 end 204 205 fn run_neg_mutant sp_tbl edit ulong 3001 to int 206 o = new ulong 16 0 207 w_mut = new ulong 4 0 208 w_ref = new ulong 4 0 209 decoded = new ulong 16 0 210 put o 0 1 211 put o 1 5 212 r_ref = enc1 o w_ref 213 if ne r_ref 0 214 ret 1 215 end 216 217 note Shift field on form 1 (MOV_RZ): fbase = 55, shift is at 57 218 orig_sh = get sp_tbl 57 219 put sp_tbl 57 add orig_sh 1 220 r_mut = sp_enc sp_tbl o w_mut 221 put sp_tbl 57 orig_sh 222 223 if ne r_mut 0 224 ret 1 225 end 226 227 same = true 228 for i ulong 4 229 if ne get w_mut i get w_ref i 230 same = false 231 end 232 end 233 234 if same 235 ret 1 236 end 237 if ne sp_dec sp_tbl w_mut decoded E_OK 238 ret 1 239 end 240 if same_sem sp_tbl o decoded 241 ret 1 242 end 243 ret 0 244 end 245 246 fn run_neg_range sp_tbl edit ulong 3001 to int 247 o = new ulong 16 0 248 w = new ulong 4 0 249 put o 0 1 250 put o 1 256 251 st = sp_enc sp_tbl o w 252 if ne st E_RANGE 253 ret 1 254 end 255 ret 0 256 end 257 258 fn run_neg_nomat sp_tbl edit ulong 3001 to int 259 w = new ulong 4 `4294967295` 260 dec = new ulong 16 0 261 dst = sp_dec sp_tbl w dec 262 if ne dst E_NOMAT 263 ret 1 264 end 265 ret 0 266 end 267 268 fn main to int 269 sp_tbl = new ulong 3001 0 270 sp_init sp_tbl 271 mode = new uchar 16 0 272 k = ulong 0 273 if ge argcnt 2 274 read_k = argread 1 mode 0 16 275 if gt read_k 0 276 k = ulong read_k 277 end 278 end 279 280 if eq k 0 281 ret run_check_loop sp_tbl false 282 end 283 284 c0 = get mode 0 285 286 if eq c0 99 287 note 'c' -> corrupt 288 ret run_check_loop sp_tbl true 289 end 290 291 if eq c0 115 292 note 's' -> sample 293 s_idx = sub ulong get mode 6 48 294 ret emit_sample sp_tbl s_idx 295 end 296 297 if eq c0 109 298 note 'm' -> mutant 299 ret run_neg_mutant sp_tbl 300 end 301 302 if eq c0 114 303 note 'r' -> range 304 ret run_neg_range sp_tbl 305 end 306 307 if eq c0 110 308 note 'n' -> nomat 309 ret run_neg_nomat sp_tbl 310 end 311 312 ret 1 313 end