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
omega-mv / seed / omc / tests / float / bitcast_int.om
| 1 | note bitcast between integer types of one width keeps the bits, and the result is a canonical value of the |
| 2 | note new type: compare, add, signed shr, widening conversion, call argument and array store all see it, and |
| 3 | note the source name keeps its own value. Each 8/16/32-bit signed/unsigned pair both ways, f32 to and from |
| 4 | note int, and the 64-bit pair as the control that was already right. omc 2c824805 kept the old extension |
| 5 | note (uint 4294967295 as int compared unequal to -1 and add 2 trapped 1). Expected values were computed with |
| 6 | note Wolfram (two's complement of the bit patterns), never by this compiler. Exit 0 when every check passed. |
| 7 | fn bi32 x uint to int |
| 8 | ret bitcast int x |
| 9 | end |
| 10 | fn bu32 x int to uint |
| 11 | ret bitcast uint x |
| 12 | end |
| 13 | fn bi16 x ushort to short |
| 14 | ret bitcast short x |
| 15 | end |
| 16 | fn bu16 x short to ushort |
| 17 | ret bitcast ushort x |
| 18 | end |
| 19 | fn bi8 x uchar to byte |
| 20 | ret bitcast byte x |
| 21 | end |
| 22 | fn bu8 x byte to uchar |
| 23 | ret bitcast uchar x |
| 24 | end |
| 25 | fn isneg1 x int to int |
| 26 | if eq x -1 |
| 27 | ret 0 |
| 28 | end |
| 29 | ret 1 |
| 30 | end |
| 31 | fn u2i32 to int |
| 32 | a = new int 1 0 |
| 33 | u = uint 4294967295 |
| 34 | v = bitcast int u |
| 35 | if ne v -1 |
| 36 | ret 1 |
| 37 | end |
| 38 | if ge v 0 |
| 39 | ret 2 |
| 40 | end |
| 41 | if ne add v 2 1 |
| 42 | ret 3 |
| 43 | end |
| 44 | if ne shr v 1 -1 |
| 45 | ret 4 |
| 46 | end |
| 47 | if ne long v -1 |
| 48 | ret 5 |
| 49 | end |
| 50 | if ne u 4294967295 |
| 51 | ret 6 |
| 52 | end |
| 53 | if ne isneg1 v 0 |
| 54 | ret 7 |
| 55 | end |
| 56 | put a 0 v |
| 57 | if ne get a 0 -1 |
| 58 | ret 8 |
| 59 | end |
| 60 | m = bitcast int uint 2147483648 |
| 61 | if ne add m 1 -2147483647 |
| 62 | ret 9 |
| 63 | end |
| 64 | if ne bi32 2147483653 -2147483643 |
| 65 | ret 10 |
| 66 | end |
| 67 | ret 0 |
| 68 | end |
| 69 | fn i2u32 to int |
| 70 | s = int -1 |
| 71 | v = bitcast uint s |
| 72 | if ne v 4294967295 |
| 73 | ret 11 |
| 74 | end |
| 75 | if ne ulong v 4294967295 |
| 76 | ret 12 |
| 77 | end |
| 78 | if ne add v 1 0 |
| 79 | ret 13 |
| 80 | end |
| 81 | if ne shr v 31 1 |
| 82 | ret 14 |
| 83 | end |
| 84 | if ne s -1 |
| 85 | ret 15 |
| 86 | end |
| 87 | if ne bu32 -2147483648 2147483648 |
| 88 | ret 16 |
| 89 | end |
| 90 | ret 0 |
| 91 | end |
| 92 | fn u2i16 to int |
| 93 | u = ushort 65535 |
| 94 | v = bitcast short u |
| 95 | if ne v -1 |
| 96 | ret 21 |
| 97 | end |
| 98 | if ge v 0 |
| 99 | ret 22 |
| 100 | end |
| 101 | if ne add v 2 1 |
| 102 | ret 23 |
| 103 | end |
| 104 | if ne long v -1 |
| 105 | ret 24 |
| 106 | end |
| 107 | if ne bi16 32768 -32768 |
| 108 | ret 25 |
| 109 | end |
| 110 | s = short -1 |
| 111 | w = bitcast ushort s |
| 112 | if ne ulong w 65535 |
| 113 | ret 26 |
| 114 | end |
| 115 | if ne bu16 -32768 32768 |
| 116 | ret 27 |
| 117 | end |
| 118 | ret 0 |
| 119 | end |
| 120 | fn u2i8 to int |
| 121 | u = uchar 255 |
| 122 | v = bitcast byte u |
| 123 | if ne v -1 |
| 124 | ret 31 |
| 125 | end |
| 126 | if ge v 0 |
| 127 | ret 32 |
| 128 | end |
| 129 | if ne add v 2 1 |
| 130 | ret 33 |
| 131 | end |
| 132 | if ne long v -1 |
| 133 | ret 34 |
| 134 | end |
| 135 | if ne bi8 200 -56 |
| 136 | ret 35 |
| 137 | end |
| 138 | s = byte -1 |
| 139 | w = bitcast uchar s |
| 140 | if ne ulong w 255 |
| 141 | ret 36 |
| 142 | end |
| 143 | if ne bu8 -128 128 |
| 144 | ret 37 |
| 145 | end |
| 146 | ret 0 |
| 147 | end |
| 148 | fn f32int to int |
| 149 | f = bitcast f32 int -1 |
| 150 | g = bitcast uint f |
| 151 | if ne g 4294967295 |
| 152 | ret 41 |
| 153 | end |
| 154 | if ne ulong g 4294967295 |
| 155 | ret 42 |
| 156 | end |
| 157 | h = bitcast int f32 -1.0 |
| 158 | if ne h -1082130432 |
| 159 | ret 43 |
| 160 | end |
| 161 | if ge h 0 |
| 162 | ret 44 |
| 163 | end |
| 164 | ret 0 |
| 165 | end |
| 166 | fn w64pair to int |
| 167 | u = ulong 18446744073709551615 |
| 168 | v = bitcast long u |
| 169 | if ne v -1 |
| 170 | ret 51 |
| 171 | end |
| 172 | if ne add v 2 1 |
| 173 | ret 52 |
| 174 | end |
| 175 | w = bitcast ulong long -1 |
| 176 | if ne w 18446744073709551615 |
| 177 | ret 53 |
| 178 | end |
| 179 | ret 0 |
| 180 | end |
| 181 | fn main to int |
| 182 | r = u2i32 |
| 183 | if ne r 0 |
| 184 | ret r |
| 185 | end |
| 186 | r = i2u32 |
| 187 | if ne r 0 |
| 188 | ret r |
| 189 | end |
| 190 | r = u2i16 |
| 191 | if ne r 0 |
| 192 | ret r |
| 193 | end |
| 194 | r = u2i8 |
| 195 | if ne r 0 |
| 196 | ret r |
| 197 | end |
| 198 | r = f32int |
| 199 | if ne r 0 |
| 200 | ret r |
| 201 | end |
| 202 | r = w64pair |
| 203 | if ne r 0 |
| 204 | ret r |
| 205 | end |
| 206 | ret 0 |
| 207 | end |