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/omega-mv/blob/main/gpu/nvidia/om/codegen/regalloc.om # omega-mv Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance. Brought by drakestapleton Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / gpu / nvidia / om / codegen / regalloc.om` 189 lines ยท 3468 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 2 note Exact core allocator successor of CUDApp `22ebf8f`, not the validating component allocator. 3 note Wire ulong4096: nv,nu,limit,peakG,peakU; records16+10*v for GPR0..255/UGPR256..287. 4 note Record: vreg,first,last,physical,bundle,pair,quad,active,map,reserved. 5 note Portable two's-complement reinterpretation; the bridge lowers no integer-to-integer bitcast. 6 fn ra_u2l x ulong to long 7 if lt x ulong `9223372036854775808` 8 ret long x 9 end 10 ret sub long -1 long xor x ulong `18446744073709551615` 11 end 12 fn ra_l2u v long to ulong 13 if ge v long 0 14 ret ulong v 15 end 16 ret xor ulong sub long -1 v ulong `18446744073709551615` 17 end 18 fn ra_get m view ulong 4096 b ulong to long 19 ret ra_u2l get m b 20 end 21 fn ra_put m edit ulong 4096 b ulong v long to void 22 put m b ra_l2u v 23 end 24 fn ra_width m view ulong 4096 b ulong to long 25 w = ra_get m add b 4 26 if ne w 0 27 ret w 28 end 29 if ne ra_get m add b 5 0 30 ret 2 31 end 32 if ne ra_get m add b 6 0 33 ret 4 34 end 35 ret 1 36 end 37 fn ra_after m view ulong 4096 a ulong b ulong to bool 38 ai = add mul a 10 17 39 bi = add mul b 10 17 40 ret gt ra_get m ai ra_get m bi 41 end 42 fn ra_sort m view ulong 4096 order edit ulong 256 count ulong to void 43 for i ulong count 44 for j ulong count 45 if gt j i 46 a = get order i 47 b = get order j 48 if ra_after m a b 49 put order i b 50 put order j a 51 end 52 end 53 end 54 end 55 end 56 fn ra_clear m view ulong 4096 busy edit uchar 246 b ulong lim long to void 57 p = ra_get m add b 3 58 if and ge p 0 lt p lim 59 w = ra_width m b 60 for k long w 61 if lt add p k lim 62 put busy ulong add p k 0 63 end 64 end 65 end 66 end 67 fn ra_free m edit ulong 4096 busy edit uchar 246 first long lim long to void 68 for v ulong ulong ra_get m 0 69 b = add mul v 10 16 70 if ne ra_get m add b 7 0 71 if lt ra_get m add b 2 first 72 ra_clear m busy b lim 73 ra_put m add b 7 0 74 end 75 end 76 end 77 end 78 fn ra_find busy edit uchar 246 w long lim long to long 79 step = long 1 80 start = long 2 81 if eq w 4 82 step = 4 83 start = 4 84 else 85 if eq w 2 86 step = 2 87 end 88 end 89 p = start 90 while le p sub lim step bound 246 91 ok = true 92 for k long step 93 if ne get busy ulong add p k 0 94 ok = false 95 end 96 end 97 if ok 98 for k long step 99 put busy ulong add p k 1 100 end 101 ret p 102 end 103 p = add p step 104 end 105 ret -1 106 end 107 fn ra_gprs m edit ulong 4096 lim long to long 108 order = new ulong 256 0 109 busy = new uchar 246 0 110 count = ulong 0 111 peak = long 2 112 for v ulong ulong ra_get m 0 113 b = add mul v 10 16 114 if ge ra_get m add b 1 0 115 put order count v 116 count = add count 1 117 else 118 ra_put m add b 3 2 119 ra_put m add b 8 2 120 end 121 end 122 ra_sort m order count 123 for i ulong count 124 v = get order i 125 b = add mul v 10 16 126 ra_free m busy ra_get m add b 1 lim 127 w = ra_width m b 128 p = ra_find busy w lim 129 if lt p 0 130 ret -1 131 end 132 ra_put m add b 3 p 133 ra_put m add b 7 1 134 ra_put m add b 8 p 135 top = sub add p w 1 136 if gt top peak 137 peak = top 138 end 139 end 140 ra_put m 3 add peak 1 141 ret 0 142 end 143 fn ra_solve m edit ulong 4096 to long 144 lim = ra_get m 2 145 if eq lim 0 146 lim = 128 147 end 148 note A caller-provided limit beyond the busy array was C undefined behavior. Refuse it. 149 if or lt lim 0 gt lim 246 150 ret -1 151 end 152 if or lt ra_get m 0 0 gt ra_get m 0 256 153 ret -1 154 end 155 if or lt ra_get m 1 0 gt ra_get m 1 32 156 ret -1 157 end 158 rc = ra_gprs m lim 159 if ne rc 0 160 ret rc 161 end 162 cur = long 4 163 for uv ulong ulong ra_get m 1 164 b = add mul add uv 256 10 16 165 if ne ra_get m add b 5 0 166 if ne rem cur 2 0 167 cur = add cur 1 168 end 169 if ge add cur 1 32 170 ret -1 171 end 172 ra_put m add b 3 cur 173 ra_put m add b 8 cur 174 cur = add cur 2 175 else 176 if ge cur 32 177 ret -1 178 end 179 ra_put m add b 3 cur 180 ra_put m add b 8 cur 181 cur = add cur 1 182 end 183 end 184 ra_put m 4 cur 185 ret 0 186 end 187 fn ra_run m edit ulong 4096 to long 188 ret ra_solve m 189 end