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 / tests / ampere / f16_fixture.om
| 1 | note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 2 | note Dedicated behavior fixture for native_f16 scalar binary32 to binary16 RNE conversion. |
| 3 | |
| 4 | fn f16_sub exp ulong m ulong to ulong |
| 5 | if eq exp 112 |
| 6 | lsb = and shr m 14 1 |
| 7 | r = add add m 8191 lsb |
| 8 | ret shr r 14 |
| 9 | end |
| 10 | if eq exp 111 |
| 11 | lsb = and shr m 15 1 |
| 12 | r = add add m 16383 lsb |
| 13 | ret shr r 15 |
| 14 | end |
| 15 | if eq exp 110 |
| 16 | lsb = and shr m 16 1 |
| 17 | r = add add m 32767 lsb |
| 18 | ret shr r 16 |
| 19 | end |
| 20 | if eq exp 109 |
| 21 | lsb = and shr m 17 1 |
| 22 | r = add add m 65535 lsb |
| 23 | ret shr r 17 |
| 24 | end |
| 25 | if eq exp 108 |
| 26 | lsb = and shr m 18 1 |
| 27 | r = add add m 131071 lsb |
| 28 | ret shr r 18 |
| 29 | end |
| 30 | if eq exp 107 |
| 31 | lsb = and shr m 19 1 |
| 32 | r = add add m 262143 lsb |
| 33 | ret shr r 19 |
| 34 | end |
| 35 | if eq exp 106 |
| 36 | lsb = and shr m 20 1 |
| 37 | r = add add m 524287 lsb |
| 38 | ret shr r 20 |
| 39 | end |
| 40 | if eq exp 105 |
| 41 | lsb = and shr m 21 1 |
| 42 | r = add add m 1048575 lsb |
| 43 | ret shr r 21 |
| 44 | end |
| 45 | if eq exp 104 |
| 46 | lsb = and shr m 22 1 |
| 47 | r = add add m 2097151 lsb |
| 48 | ret shr r 22 |
| 49 | end |
| 50 | if eq exp 103 |
| 51 | lsb = and shr m 23 1 |
| 52 | r = add add m 4194303 lsb |
| 53 | ret shr r 23 |
| 54 | end |
| 55 | if eq exp 102 |
| 56 | lsb = and shr m 24 1 |
| 57 | r = add add m 8388607 lsb |
| 58 | ret shr r 24 |
| 59 | end |
| 60 | ret 0 |
| 61 | end |
| 62 | |
| 63 | fn native_f16 bits ulong to ulong |
| 64 | sign = and shr bits 16 32768 |
| 65 | u = and bits 2147483647 |
| 66 | if ge u 2139095040 |
| 67 | if gt u 2139095040 |
| 68 | payload = and shr u 13 1023 |
| 69 | res = or 32256 payload |
| 70 | ret or sign res |
| 71 | end |
| 72 | ret or sign 31744 |
| 73 | end |
| 74 | if ge u 1199566848 |
| 75 | ret or sign 31744 |
| 76 | end |
| 77 | if ge u 947912704 |
| 78 | lsb = and shr u 13 1 |
| 79 | rounded = add add u 4095 lsb |
| 80 | val = sub rounded 939524096 |
| 81 | ret or sign shr val 13 |
| 82 | end |
| 83 | if gt u 855638016 |
| 84 | exp = shr u 23 |
| 85 | m = or 8388608 and u 8388607 |
| 86 | res = f16_sub exp m |
| 87 | ret or sign res |
| 88 | end |
| 89 | ret sign |
| 90 | end |
| 91 | |
| 92 | fn check eq_val ulong exp_val ulong to ulong |
| 93 | if ne eq_val exp_val |
| 94 | ret 1 |
| 95 | end |
| 96 | ret 0 |
| 97 | end |
| 98 | |
| 99 | fn main to int |
| 100 | fails = ulong 0 |
| 101 | |
| 102 | note Zero |
| 103 | fails = add fails check native_f16 0 0 |
| 104 | fails = add fails check native_f16 2147483648 32768 |
| 105 | note Subnormal boundary and underflow |
| 106 | fails = add fails check native_f16 855638016 0 |
| 107 | fails = add fails check native_f16 855638017 1 |
| 108 | fails = add fails check native_f16 947904511 1023 |
| 109 | fails = add fails check native_f16 947904512 1024 |
| 110 | fails = add fails check native_f16 947912703 1024 |
| 111 | |
| 112 | note Normal min and 1.0f |
| 113 | fails = add fails check native_f16 947912704 1024 |
| 114 | fails = add fails check native_f16 1065353216 15360 |
| 115 | |
| 116 | note RNE ties to even |
| 117 | fails = add fails check native_f16 1065357312 15360 |
| 118 | fails = add fails check native_f16 1065365504 15362 |
| 119 | |
| 120 | note Normal max and overflow boundary |
| 121 | fails = add fails check native_f16 1199562752 31743 |
| 122 | fails = add fails check native_f16 1199566847 31743 |
| 123 | fails = add fails check native_f16 1199566848 31744 |
| 124 | fails = add fails check native_f16 3347050496 64512 |
| 125 | |
| 126 | note Infinities |
| 127 | fails = add fails check native_f16 2139095040 31744 |
| 128 | fails = add fails check native_f16 4286578688 64512 |
| 129 | |
| 130 | note NaNs |
| 131 | fails = add fails check native_f16 2143289344 32256 |
| 132 | fails = add fails check native_f16 2139095041 32256 |
| 133 | fails = add fails check native_f16 4290773024 65024 |
| 134 | fails = add fails check native_f16 2147483647 32767 |
| 135 | |
| 136 | if ne fails 0 |
| 137 | ret 1 |
| 138 | end |
| 139 | ret 0 |
| 140 | end |