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 / numeric / rest.om
| 1 | note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 2 | note Numeric remainder composed after numeric.om. Float payloads are bits. |
| 3 | fn nrmask op ulong to ulong |
| 4 | if eq op 4 |
| 5 | ret 6 |
| 6 | end |
| 7 | if eq op 19 |
| 8 | ret 1 |
| 9 | end |
| 10 | if eq op 20 |
| 11 | ret 3 |
| 12 | end |
| 13 | if eq op 21 |
| 14 | ret 4 |
| 15 | end |
| 16 | if eq op 22 |
| 17 | ret 2 |
| 18 | end |
| 19 | if eq op 23 |
| 20 | ret 5 |
| 21 | end |
| 22 | if and ge op 24 le op 26 |
| 23 | ret sub op 17 |
| 24 | end |
| 25 | if eq op 27 |
| 26 | ret 11 |
| 27 | end |
| 28 | if eq op 28 |
| 29 | ret 12 |
| 30 | end |
| 31 | if eq op 29 |
| 32 | ret 14 |
| 33 | end |
| 34 | if eq op 30 |
| 35 | ret 10 |
| 36 | end |
| 37 | if eq op 31 |
| 38 | ret 13 |
| 39 | end |
| 40 | ret 0 |
| 41 | end |
| 42 | fn nrclass mode ulong a ulong to ulong |
| 43 | if eq mode 0 |
| 44 | ret and a ABS |
| 45 | end |
| 46 | if eq mode 1 |
| 47 | ret b2u isnan32 a |
| 48 | end |
| 49 | if eq mode 2 |
| 50 | ret b2u eq and a ABS INF |
| 51 | end |
| 52 | if eq mode 3 |
| 53 | ret b2u ne and a SGN 0 |
| 54 | end |
| 55 | if eq mode 4 |
| 56 | ret b2u and eq and a INF 0 ne and a 8388607 0 |
| 57 | end |
| 58 | if eq mode 5 |
| 59 | ret b2u iszero32 a |
| 60 | end |
| 61 | if eq mode 6 |
| 62 | ret b2u and ne and a INF 0 ne and a INF INF |
| 63 | end |
| 64 | if and eq and a INF 0 ne and a 8388607 0 |
| 65 | ret and a SGN |
| 66 | end |
| 67 | ret a |
| 68 | end |
| 69 | fn nrelem op ulong a ulong b ulong c ulong cpu ulong to ulong |
| 70 | if lt op 4 |
| 71 | ret numeric_ref op a b c |
| 72 | end |
| 73 | if eq op 4 |
| 74 | if eq fsetpge a b 1 |
| 75 | ret a |
| 76 | end |
| 77 | ret b |
| 78 | end |
| 79 | if eq op 5 |
| 80 | if eq fsetpge a 0 1 |
| 81 | ret b |
| 82 | end |
| 83 | ret a |
| 84 | end |
| 85 | if eq op 6 |
| 86 | ret fmin32 a b |
| 87 | end |
| 88 | if eq op 7 |
| 89 | ret fmax32 a b |
| 90 | end |
| 91 | if eq op 8 |
| 92 | ret i2f32 a |
| 93 | end |
| 94 | if eq op 9 |
| 95 | ret toint a 0 false |
| 96 | end |
| 97 | if eq op 10 |
| 98 | ret canon ieeediv 1065353216 a |
| 99 | end |
| 100 | if eq op 11 |
| 101 | ret canon ieeediv 1065353216 ieeesqrt a |
| 102 | end |
| 103 | if eq op 14 |
| 104 | if eq cpu 1 |
| 105 | ret canon mdiv a b |
| 106 | end |
| 107 | ret canon ieeediv a b |
| 108 | end |
| 109 | if eq op 15 |
| 110 | if eq cpu 1 |
| 111 | ret canon msqrt a |
| 112 | end |
| 113 | ret canon ieeesqrt a |
| 114 | end |
| 115 | if eq op 16 |
| 116 | ret canon mexp a |
| 117 | end |
| 118 | if eq op 17 |
| 119 | ret canon mlog a |
| 120 | end |
| 121 | if and ge op 19 le op 31 |
| 122 | if eq fsetpred nrmask op a b 1 |
| 123 | ret a |
| 124 | end |
| 125 | ret b |
| 126 | end |
| 127 | if and ge op 32 le op 34 |
| 128 | ret toint a sub op 31 false |
| 129 | end |
| 130 | if eq op 35 |
| 131 | ret toint a 0 true |
| 132 | end |
| 133 | if eq op 36 |
| 134 | ret u2f32 a |
| 135 | end |
| 136 | if eq op 37 |
| 137 | ret narrow a 10 15 31 |
| 138 | end |
| 139 | if eq op 38 |
| 140 | ret narrow a 7 127 255 |
| 141 | end |
| 142 | if eq op 39 |
| 143 | ret f16to32 and a 65535 |
| 144 | end |
| 145 | if eq op 40 |
| 146 | ret bf16to32 and a 65535 |
| 147 | end |
| 148 | if eq op 41 |
| 149 | ret canon ffmaint a b c |
| 150 | end |
| 151 | ret a |
| 152 | end |
| 153 | note flags encode a,b,c,out and FP environment: bits 0..4. |
| 154 | fn nrcheck op ulong n ulong flags ulong arity ulong ftzmod ulong to ulong |
| 155 | if or ge op 42 ne and flags 9 9 |
| 156 | ret 1 |
| 157 | end |
| 158 | if eq and flags 16 0 |
| 159 | ret 5 |
| 160 | end |
| 161 | if and ge arity 2 eq and flags 2 0 |
| 162 | ret 1 |
| 163 | end |
| 164 | if and ge arity 3 eq and flags 4 0 |
| 165 | ret 1 |
| 166 | end |
| 167 | if eq ftzmod 0 |
| 168 | if and or eq op 13 eq op 18 ne rem n 32 0 |
| 169 | ret 3 |
| 170 | end |
| 171 | if and eq op 12 ne rem n 64 0 |
| 172 | ret 3 |
| 173 | end |
| 174 | end |
| 175 | ret 0 |
| 176 | end |
| 177 | fn nrseed op ulong a ulong got ulong to ulong |
| 178 | if or eq nrclass 6 a 0 and eq op 11 ne and a SGN 0 |
| 179 | ret 0 |
| 180 | end |
| 181 | ex = nrelem op a 0 0 0 |
| 182 | if eq nrclass 6 ex 0 |
| 183 | ret 0 |
| 184 | end |
| 185 | diff = sub f64 f32of got f64 f32of ex |
| 186 | if lt diff 0.0f64 |
| 187 | diff = neg diff |
| 188 | end |
| 189 | mag = f64 f32of ex |
| 190 | if lt mag 0.0f64 |
| 191 | mag = neg mag |
| 192 | end |
| 193 | note Source bound 1 / 1048576, exactly 2^-20. |
| 194 | if or isnan32 got not le diff mul mag div 1.0f64 1048576.0f64 |
| 195 | ret or shl ex 32 2 |
| 196 | end |
| 197 | ret or shl ex 32 1 |
| 198 | end |
| 199 | fn nrreduce mode ulong op ulong n ulong flags ulong stride ulong to ulong |
| 200 | if eq mode 0 |
| 201 | if or eq op 1 eq op 2 |
| 202 | ret 2143289344 |
| 203 | end |
| 204 | ret 2147483648 |
| 205 | end |
| 206 | if eq mode 1 |
| 207 | if eq op 0 |
| 208 | ret 0 |
| 209 | end |
| 210 | ret 2143289344 |
| 211 | end |
| 212 | if eq mode 2 |
| 213 | if or ge op 4 eq and flags 8 0 |
| 214 | ret 1 |
| 215 | end |
| 216 | if and gt n 0 eq and flags 1 0 |
| 217 | ret 1 |
| 218 | end |
| 219 | if and eq op 3 gt n 16777216 |
| 220 | ret 3 |
| 221 | end |
| 222 | if gt n 4611686018427387839 |
| 223 | ret 3 |
| 224 | end |
| 225 | if eq and flags 16 0 |
| 226 | ret 5 |
| 227 | end |
| 228 | ret 0 |
| 229 | end |
| 230 | if eq mode 3 |
| 231 | ret div add n 31 32 |
| 232 | end |
| 233 | if eq mode 4 |
| 234 | ret and add n 31 not ulong 31 |
| 235 | end |
| 236 | if eq mode 5 |
| 237 | if eq op 3 |
| 238 | ret canon mdiv flags u2f32 n |
| 239 | end |
| 240 | ret flags |
| 241 | end |
| 242 | ret 0 |
| 243 | end |
| 244 | note mode 0..7 IEEE; 8 predicate mask; 9 predicate; 10 element; |
| 245 | note 11 permutation source; 12 bulk check; 13 checked lane; 14 seed; |
| 246 | note 15 compare/subnormal flags; 16 FTZ element; 20..25 reduction plan. |
| 247 | fn numeric_rest_run mode ulong a ulong b ulong c ulong d ulong e ulong to ulong |
| 248 | if le mode 7 |
| 249 | ret nrclass mode a |
| 250 | end |
| 251 | if eq mode 8 |
| 252 | ret nrmask a |
| 253 | end |
| 254 | if eq mode 9 |
| 255 | m = nrmask a |
| 256 | if eq m 0 |
| 257 | ret M32 |
| 258 | end |
| 259 | ret fsetpred m b c |
| 260 | end |
| 261 | if eq mode 10 |
| 262 | ret nrelem a b c d e |
| 263 | end |
| 264 | if eq mode 11 |
| 265 | if eq a 12 |
| 266 | ret xor b 63 |
| 267 | end |
| 268 | if and eq a 13 ne rem b 32 31 |
| 269 | ret add b 1 |
| 270 | end |
| 271 | ret b |
| 272 | end |
| 273 | if eq mode 12 |
| 274 | ret nrcheck a b c d e |
| 275 | end |
| 276 | if eq mode 13 |
| 277 | ret b2u or ne a 18 eq rem b 32 0 |
| 278 | end |
| 279 | if eq mode 14 |
| 280 | ret nrseed a b c |
| 281 | end |
| 282 | if eq mode 15 |
| 283 | ret or cmpeq a b c shl nrclass 4 b 1 |
| 284 | end |
| 285 | if eq mode 16 |
| 286 | if not or or lt a 4 eq a 41 or eq a 6 eq a 7 |
| 287 | ret 4294967296 |
| 288 | end |
| 289 | ret nrclass 7 nrelem a nrclass 7 b nrclass 7 c nrclass 7 d 0 |
| 290 | end |
| 291 | if eq mode 17 |
| 292 | if eq a 18 |
| 293 | if eq rem b 32 0 |
| 294 | ret 1 |
| 295 | end |
| 296 | ret 2 |
| 297 | end |
| 298 | ret 0 |
| 299 | end |
| 300 | if eq mode 18 |
| 301 | if lt b 32 |
| 302 | ret b |
| 303 | end |
| 304 | ret 32 |
| 305 | end |
| 306 | if eq mode 19 |
| 307 | ret b2u ge a 2 |
| 308 | end |
| 309 | if and eq mode 25 and eq a 3 eq e 1 |
| 310 | ret canon ieeediv c u2f32 b |
| 311 | end |
| 312 | if and ge mode 20 le mode 25 |
| 313 | ret nrreduce sub mode 20 a b c d |
| 314 | end |
| 315 | if eq mode 26 |
| 316 | if or ge a 4 and gt c 0 eq and e 8 0 |
| 317 | ret 1 |
| 318 | end |
| 319 | if and and gt c 0 gt b 0 eq and e 1 0 |
| 320 | ret 1 |
| 321 | end |
| 322 | if and gt c 1 lt d b |
| 323 | ret 3 |
| 324 | end |
| 325 | if and gt c 0 gt b 0 |
| 326 | if gt b 4611686018427387903 |
| 327 | ret 3 |
| 328 | end |
| 329 | if gt c 1 |
| 330 | if gt d div sub 4611686018427387903 b sub c 1 |
| 331 | ret 3 |
| 332 | end |
| 333 | end |
| 334 | end |
| 335 | ret 0 |
| 336 | end |
| 337 | if eq mode 27 |
| 338 | if eq e 0 |
| 339 | ret 2 |
| 340 | end |
| 341 | if or or eq b 0 gt b 65536 ne and c 9 9 |
| 342 | ret 1 |
| 343 | end |
| 344 | if and ge d 2 eq and c 2 0 |
| 345 | ret 1 |
| 346 | end |
| 347 | if and ge d 3 eq and c 4 0 |
| 348 | ret 1 |
| 349 | end |
| 350 | if and or eq a 13 eq a 18 ne rem b 32 0 |
| 351 | ret 3 |
| 352 | end |
| 353 | if and eq a 12 ne rem b 64 0 |
| 354 | ret 3 |
| 355 | end |
| 356 | ret 0 |
| 357 | end |
| 358 | if eq mode 28 |
| 359 | ret b2u or ne a 3 eq b c |
| 360 | end |
| 361 | if eq mode 29 |
| 362 | if or ge a 42 eq c 0 |
| 363 | ret 1 |
| 364 | end |
| 365 | if or lt b 1 gt b 15 |
| 366 | ret 2 |
| 367 | end |
| 368 | ret 0 |
| 369 | end |
| 370 | if eq mode 30 |
| 371 | if gt b 1 |
| 372 | ret div add b 31 32 |
| 373 | end |
| 374 | ret 0 |
| 375 | end |
| 376 | if eq mode 31 |
| 377 | if eq b 0 |
| 378 | ret 0 |
| 379 | end |
| 380 | ret SGN |
| 381 | end |
| 382 | if eq mode 32 |
| 383 | ret b2u eq a 3 |
| 384 | end |
| 385 | if eq mode 33 |
| 386 | ret b2u or eq a 3 eq a 41 |
| 387 | end |
| 388 | if eq mode 34 |
| 389 | ret b2u ge a 2 |
| 390 | end |
| 391 | if eq mode 35 |
| 392 | ret b2u and and eq a 38 gt b 0 eq c 1 |
| 393 | end |
| 394 | if eq mode 36 |
| 395 | if eq a 0 |
| 396 | ret 2 |
| 397 | end |
| 398 | ret 0 |
| 399 | end |
| 400 | ret 0 |
| 401 | end |