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/kgen/ew_emit.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 / kgen / ew_emit.om` 338 lines · 8008 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 2 note Elementwise API IR record construction. Wire ABI: src/omega_gpu_om_ir.h. 3 note All register numbers are virtual; allocation and encoding use the existing replay entry. 4 note Scratch metadata: 8 loop depth, 9..12 open loops, 13 region depth, 5 note 14 predicated exit, 15 test-only exit bypass, 352..367 BSSY indices, 6 note 368 region mutant, 369 math mutant, 370 test path. No exact-live override. 7 const NR ulong 65535 8 const ALL ulong `18446744073709551615` 9 const MASK32 ulong `4294967295` 10 const MOVRZ ulong 1 11 const MOVI ulong 2 12 const S2R ulong 3 13 const LDC ulong 4 14 const LDC64 ulong 5 15 const LDCU64 ulong 7 16 const IMAD ulong 8 17 const WIDE ulong 9 18 const LDG ulong 11 19 const STG ulong 12 20 const ADD ulong 14 21 const SHR ulong 17 22 const GE ulong 28 23 const XOR ulong 29 24 const FADD ulong 30 25 const FSUB ulong 31 26 const FMUL ulong 32 27 const FFMA ulong 33 28 const RCP ulong 40 29 const RSQ ulong 41 30 const SHFL ulong 42 31 const EXIT ulong 45 32 const BRA ulong 46 33 const EX2 ulong 47 34 const BAR ulong 48 35 const LDS ulong 49 36 const STS ulong 50 37 const LUT ulong 51 38 const SHL ulong 52 39 const HI ulong 53 40 const BSSY ulong 54 41 const BSYNC ulong 55 42 fn cw st ulong wb ulong readb ulong wt ulong to ulong 43 ret or or shl st 9 shl wb 14 or shl readb 17 shl wt 20 44 end 45 fn fld x ulong to ulong 46 if eq x NR 47 ret ALL 48 end 49 ret x 50 end 51 fn r4 d ulong a ulong b ulong c ulong to ulong 52 ret or or d shl a 16 or shl b 32 shl c 48 53 end 54 note op | kind << 8 | flags << 16 | uniform register << 40 55 fn ok op ulong kind ulong flags ulong ur ulong to ulong 56 ret or or op shl kind 8 or shl flags 16 shl ur 40 57 end 58 fn ctrl k ulong fl ulong wt ulong to ulong 59 if eq k 1 60 ret cw 14 7 7 wt 61 end 62 if eq k 2 63 ret or or cw 4 0 7 wt 8192 shl ulong 1 32 64 end 65 if eq k 3 66 ret or or cw 4 2 7 wt 8192 shl ulong 4 32 67 end 68 if eq k 4 69 ret or or cw 4 7 1 wt 8192 shl ulong 2 32 70 end 71 if or eq k 6 eq k 7 72 if ne and fl 2 0 73 ret or cw 5 7 7 wt shl wt 32 74 end 75 ret cw 5 7 7 wt 76 end 77 if eq k 8 78 ret or cw 1 7 7 wt 8192 79 end 80 if eq k 9 81 ret or cw 5 7 7 wt 8192 82 end 83 ret cw 6 7 7 wt 84 end 85 fn operands ins edit ulong 8192 n ulong spec ulong regs ulong to void 86 put ins n and spec 255 87 put ins add n 1 fld and regs 65535 88 put ins add n 2 fld and shr regs 16 65535 89 put ins add n 3 fld and shr regs 32 65535 90 put ins add n 4 fld shr regs 48 91 put ins add n 5 fld and shr spec 40 65535 92 end 93 fn emit ins edit ulong 8192 m edit ulong 512 spec ulong regs ulong imm ulong to void 94 n = get m 0 95 if ge n 1024 96 put m 4 1 97 ret 98 end 99 cc = ctrl and shr spec 8 255 and shr spec 16 255 get m 3 100 put m 0 add n 1 101 n = mul n 8 102 operands ins n spec regs 103 put ins add n 6 or and imm MASK32 shl and cc MASK32 32 104 put ins add n 7 and shr spec 16 255 105 put m 3 shr cc 32 106 end 107 fn fx ins edit ulong 8192 m edit ulong 512 op ulong regs ulong imm ulong to void 108 emit ins m ok op 0 0 NR regs imm 109 end 110 fn vr ins edit ulong 8192 m edit ulong 512 op ulong regs ulong imm ulong to void 111 emit ins m ok op 2 0 NR regs imm 112 end 113 fn nv m edit ulong 512 width ulong to ulong 114 v = get m 1 115 if ge v 256 116 put m 4 2 117 ret NR 118 end 119 put m add 64 v width 120 put m 1 add v 1 121 ret v 122 end 123 fn movi ins edit ulong 8192 m edit ulong 512 d ulong imm ulong to void 124 fx ins m MOVI r4 d NR NR NR imm 125 end 126 fn zero ins edit ulong 8192 m edit ulong 512 d ulong to void 127 fx ins m MOVRZ r4 d NR NR NR 0 128 end 129 fn ai ins edit ulong 8192 m edit ulong 512 d ulong a ulong imm ulong c ulong to void 130 fx ins m IMAD r4 d a NR c imm 131 end 132 fn ar ins edit ulong 8192 m edit ulong 512 d ulong a ulong b ulong c ulong to void 133 fx ins m IMAD r4 d a b c 0 134 end 135 fn add3 ins edit ulong 8192 m edit ulong 512 d ulong a ulong b ulong to void 136 fx ins m ADD r4 d a b NR 0 137 end 138 fn addr ins edit ulong 8192 m edit ulong 512 d ulong idx ulong base ulong to void 139 fx ins m WIDE r4 d idx NR base 4 140 end 141 fn load ins edit ulong 8192 m edit ulong 512 d ulong a ulong to void 142 emit ins m ok LDG 2 0 0 r4 d a NR NR 0 143 end 144 fn store ins edit ulong 8192 m edit ulong 512 a ulong v ulong to void 145 emit ins m ok STG 4 0 0 r4 NR a v NR 0 146 end 147 fn ldconst ins edit ulong 8192 m edit ulong 512 d ulong off ulong to void 148 vr ins m LDC r4 d NR NR NR off 149 end 150 fn isgte ins edit ulong 8192 m edit ulong 512 a ulong b ulong to void 151 emit ins m ok GE 1 0 NR r4 NR a b NR 0 152 end 153 fn split m edit ulong 512 to bool 154 if or gt get m 13 0 and ne get m 14 0 eq get m 15 0 155 put m 4 3 156 ret true 157 end 158 ret false 159 end 160 fn shfl ins edit ulong 8192 m edit ulong 512 d ulong a ulong off ulong to void 161 if split m 162 ret 163 end 164 vr ins m SHFL r4 d a NR NR off 165 end 166 fn bar ins edit ulong 8192 m edit ulong 512 to void 167 if split m 168 ret 169 end 170 emit ins m ok BAR 5 0 NR r4 NR NR NR NR 0 171 end 172 fn exitp ins edit ulong 8192 m edit ulong 512 to void 173 if gt get m 13 0 174 put m 4 4 175 ret 176 end 177 put m 14 1 178 emit ins m ok EXIT 6 2 NR r4 NR NR NR NR 0 179 end 180 fn branch ins edit ulong 8192 m edit ulong 512 target ulong flags ulong to void 181 emit ins m ok BRA 7 flags NR r4 NR NR NR NR and sub target get m 0 MASK32 182 end 183 fn fwd ins edit ulong 8192 m edit ulong 512 to ulong 184 at = get m 0 185 emit ins m ok BRA 7 2 NR r4 NR NR NR NR 1 186 ret at 187 end 188 fn patch ins edit ulong 8192 m edit ulong 512 at ulong to void 189 if or ne get m 4 0 ge at get m 0 190 put m 4 5 191 ret 192 end 193 idx = add mul at 8 6 194 put ins idx or and get ins idx shl MASK32 32 sub get m 0 at 195 end 196 fn tail ins edit ulong 8192 m edit ulong 512 to void 197 emit ins m ok EXIT 6 0 NR r4 NR NR NR NR 0 198 emit ins m ok BRA 7 0 NR r4 NR NR NR NR 0 199 put ins add mul sub get m 0 1 8 6 shl ulong `1032192` 32 200 end 201 fn lb m edit ulong 512 to void 202 d = get m 8 203 if ge d 4 204 put m 4 6 205 ret 206 end 207 put m add 9 d get m 0 208 put m 8 add d 1 209 end 210 fn lend m edit ulong 512 to void 211 d = get m 8 212 n = get m 5 213 if or eq d 0 ge n 4 214 put m 4 7 215 ret 216 end 217 d = sub d 1 218 put m 8 d 219 put m add 16 mul n 2 get m add 9 d 220 put m add 17 mul n 2 sub get m 0 1 221 put m 5 add n 1 222 end 223 fn rb ins edit ulong 8192 m edit ulong 512 to void 224 d = get m 13 225 if ge d 16 226 put m 4 8 227 ret 228 end 229 put m add 352 d get m 0 230 emit ins m ok BSSY 8 0 NR r4 NR NR NR NR 2 231 put ins add mul sub get m 0 1 8 7 shl d 48 232 put m 13 add d 1 233 end 234 fn rx ins edit ulong 8192 m edit ulong 512 cond ulong to void 235 flags = ulong 0 236 if ne cond 0 237 flags = ulong 2 238 if eq cond 2 239 flags = ulong 6 240 end 241 end 242 emit ins m ok BRA 7 flags NR r4 NR NR NR NR 1 243 d = get m 13 244 if eq d 0 245 put m 4 9 246 ret 247 end 248 idx = add mul sub get m 0 1 8 7 249 put ins idx or get ins idx shl d 56 250 end 251 fn rj ins edit ulong 8192 m edit ulong 512 to void 252 d = get m 13 253 if eq d 0 254 put m 4 10 255 ret 256 end 257 d = sub d 1 258 at = get m 0 259 op = BSYNC 260 if eq get m 368 1 261 op = ulong 0 262 end 263 emit ins m ok op 9 0 NR r4 NR NR NR NR 0 264 put ins add mul at 8 7 shl d 48 265 bs = get m add 352 d 266 idx = add mul bs 8 6 267 delta = sub add at 1 bs 268 if eq get m 368 2 269 delta = add delta 1 270 end 271 put ins idx or and get ins idx shl MASK32 32 delta 272 rexits ins d at 273 put m 13 d 274 end 275 fn rexits ins edit ulong 8192 d ulong at ulong to void 276 for i ulong at 277 idx = add mul i 8 7 278 if eq shr get ins idx 56 add d 1 279 put ins idx and get ins idx not shl MASK32 56 280 idx = add mul i 8 6 281 put ins idx or and get ins idx shl MASK32 32 sub at i 282 end 283 end 284 end 285 fn prolog ins edit ulong 8192 m edit ulong 512 to void 286 put m 2 1 287 put m 320 2 288 for i ulong 5 289 width = ulong 1 290 if lt i 3 291 width = ulong 2 292 end 293 v = nv m width 294 end 295 emit ins m ok LDCU64 3 1 NR r4 0 NR NR NR 856 296 vr ins m LDC64 r4 0 NR NR NR 896 297 vr ins m LDC64 r4 1 NR NR NR 904 298 vr ins m LDC64 r4 2 NR NR NR 912 299 vr ins m S2R r4 3 NR NR NR 33 300 vr ins m S2R r4 4 NR NR NR 37 301 end 302 fn paircls op ulong to ulong 303 if or or or eq op MOVRZ eq op MOVI or eq op ADD eq op XOR or or eq op LUT eq op SHR eq op SHL 304 ret 1 305 end 306 if or or eq op IMAD eq op HI or or eq op FADD eq op FSUB or eq op FMUL eq op FFMA 307 ret 2 308 end 309 ret 0 310 end 311 fn schedule ins edit ulong 8192 m edit ulong 512 to void 312 n = get m 0 313 if lt n 2 314 ret 315 end 316 for i ulong sub n 1 317 b = mul i 8 318 op = get ins b 319 cls = paircls op 320 cc = shr get ins add b 6 32 321 if and ne cls 0 ne op ADD 322 if eq cls paircls get ins add b 8 323 if eq and get ins add b 7 2 0 324 if eq and get ins add b 15 2 0 325 if eq and shr cc 9 15 6 326 tighten ins b cc 327 end 328 end 329 end 330 end 331 end 332 end 333 end 334 fn tighten ins edit ulong 8192 b ulong cc ulong to void 335 cc = or and cc not shl ulong 15 9 shl ulong 5 9 336 idx = add b 6 337 put ins idx or and get ins idx MASK32 shl cc 32 338 end