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 / om / codegen / cg_pfhost_emit.om
| 1 | note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 2 | note Seeded e5b32567. Tape ABI from omega_gpu_om_ir.h; scheduling mirrors omega_bw_em.h. |
| 3 | note st: count,pending,held; record scratch at 8..15. Helpers never retain per-record allocations. |
| 4 | const PHNONE ulong 18446744073709551615 |
| 5 | fn ph_base st edit ulong 16 op ulong d ulong a ulong b ulong to void |
| 6 | put st 8 op |
| 7 | put st 9 d |
| 8 | put st 10 a |
| 9 | put st 11 b |
| 10 | put st 12 PHNONE |
| 11 | put st 13 PHNONE |
| 12 | put st 14 0 |
| 13 | put st 15 0 |
| 14 | end |
| 15 | fn ph_emit ins edit ulong 8192 st edit ulong 16 kind ulong to void |
| 16 | waits = get st 1 |
| 17 | ctl = or or shl ulong 6 9 shl ulong 7 14 shl ulong 7 17 |
| 18 | if eq kind 1 |
| 19 | ctl = or or shl ulong 14 9 shl ulong 7 14 shl ulong 7 17 |
| 20 | end |
| 21 | if or eq kind 2 eq kind 3 |
| 22 | ctl = or or shl ulong 4 9 shl ulong 1 17 8192 |
| 23 | end |
| 24 | if eq kind 3 |
| 25 | waits = and waits 2 |
| 26 | end |
| 27 | if eq kind 4 |
| 28 | ctl = or or or shl ulong 4 9 shl ulong 2 14 shl ulong 7 17 8192 |
| 29 | end |
| 30 | if eq kind 5 |
| 31 | ctl = or or or shl ulong 4 9 shl ulong 7 14 shl ulong 1 17 8192 |
| 32 | end |
| 33 | if eq kind 7 |
| 34 | ctl = or or shl ulong 5 9 shl ulong 7 14 shl ulong 7 17 |
| 35 | end |
| 36 | if eq kind 11 |
| 37 | ctl = or or or shl ulong 4 9 shl ulong 3 14 shl ulong 1 17 8192 |
| 38 | waits = and waits 2 |
| 39 | end |
| 40 | ctl = or ctl shl waits 20 |
| 41 | n = mul get st 0 8 |
| 42 | for j ulong 8 |
| 43 | put ins add n j get st add j 8 |
| 44 | end |
| 45 | put ins add n 6 or get st 14 shl ctl 32 |
| 46 | put st 0 add get st 0 1 |
| 47 | if or eq kind 0 eq kind 1 |
| 48 | put st 1 0 |
| 49 | end |
| 50 | if eq kind 2 |
| 51 | put st 1 3 |
| 52 | end |
| 53 | if eq kind 3 |
| 54 | put st 1 or get st 1 3 |
| 55 | end |
| 56 | if eq kind 4 |
| 57 | put st 1 4 |
| 58 | end |
| 59 | if eq kind 5 |
| 60 | put st 1 2 |
| 61 | end |
| 62 | if eq kind 7 |
| 63 | if eq and get st 15 2 0 |
| 64 | put st 1 0 |
| 65 | end |
| 66 | end |
| 67 | if eq kind 11 |
| 68 | put st 1 or get st 1 2 |
| 69 | put st 2 or get st 2 8 |
| 70 | end |
| 71 | end |
| 72 | fn ph_imm ins edit ulong 8192 st edit ulong 16 op ulong d ulong imm ulong kind ulong to void |
| 73 | ph_base st op d PHNONE PHNONE |
| 74 | put st 14 imm |
| 75 | if eq op 7 |
| 76 | put st 15 1 |
| 77 | end |
| 78 | ph_emit ins st kind |
| 79 | end |
| 80 | fn ph_imad ins edit ulong 8192 st edit ulong 16 d ulong a ulong imm ulong c ulong to void |
| 81 | ph_base st 8 d a PHNONE |
| 82 | put st 12 c |
| 83 | put st 14 imm |
| 84 | ph_emit ins st 0 |
| 85 | end |
| 86 | fn ph_wide ins edit ulong 8192 st edit ulong 16 d ulong a ulong imm ulong c ulong to void |
| 87 | ph_base st 9 d a PHNONE |
| 88 | put st 12 c |
| 89 | put st 14 imm |
| 90 | ph_emit ins st 0 |
| 91 | end |
| 92 | fn ph_load ins edit ulong 8192 st edit ulong 16 d ulong a ulong imm ulong kind ulong to void |
| 93 | ph_base st 57 d a PHNONE |
| 94 | put st 13 0 |
| 95 | put st 14 imm |
| 96 | ph_emit ins st kind |
| 97 | end |
| 98 | fn ph_consume st edit ulong 16 to void |
| 99 | put st 1 or get st 1 and get st 2 8 |
| 100 | put st 2 and get st 2 not ulong 8 |
| 101 | end |
| 102 | fn ph_tail ins edit ulong 8192 st edit ulong 16 to void |
| 103 | ph_imm ins st 45 PHNONE 0 7 |
| 104 | ph_base st 46 PHNONE PHNONE PHNONE |
| 105 | ph_emit ins st 7 |
| 106 | put ins sub mul get st 0 8 2 shl ulong 1032192 32 |
| 107 | end |
| 108 | fn ph_branch ins edit ulong 8192 st edit ulong 16 target ulong to void |
| 109 | ph_base st 46 PHNONE PHNONE PHNONE |
| 110 | put st 14 and sub target get st 0 4294967295 |
| 111 | put st 15 2 |
| 112 | ph_emit ins st 7 |
| 113 | end |
| 114 | note args: destination and source subregisters travel packed in flags scratch cfg[8..13]. |
| 115 | fn ph_muladd ins edit ulong 8192 st edit ulong 16 cf view ulong 64 to void |
| 116 | ph_base st 32 get cf 10 get cf 11 get cf 12 |
| 117 | put st 15 or shl get cf 13 24 shl get cf 14 32 |
| 118 | if eq get cf 3 1 |
| 119 | put st 8 33 |
| 120 | put st 9 get cf 8 |
| 121 | put st 12 get cf 8 |
| 122 | put st 15 or get st 15 or shl get cf 9 16 shl get cf 9 40 |
| 123 | ph_emit ins st 0 |
| 124 | else |
| 125 | ph_emit ins st 0 |
| 126 | ph_base st 30 get cf 8 get cf 8 get cf 10 |
| 127 | put st 15 or shl get cf 9 16 shl get cf 9 24 |
| 128 | ph_emit ins st 0 |
| 129 | end |
| 130 | end |