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/seed/ng/tests/ir/intcv-oracle.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 / seed / ng / tests / ir / intcv-oracle.om` 306 lines ยท 4026 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 2 note Build with src/ir.om. Usage: intcv SOURCE-ID DEST-ID CASE, ids u8..u64=2..5, i8..i64=6..9. 3 note Emits a minimal IR unit, then does the equivalent native seeded-omc conversion. 4 note Exit 0 or trap 5 is the independent expected result for the emitted unit. 5 note 4 unsigned widths x 4 signed widths x 8 boundary cases = 128 runs. 6 global ic_arg uchar 24 7 fn ic_num arg ulong to uint 8 n = argread arg ic_arg 0 len ic_arg 9 if or le n 0 gt n 3 10 exit 2 11 end 12 v = uint 0 13 for j ulong ulong n bound 3 14 c = uint get ic_arg j 15 if or lt c 48 gt c 57 16 exit 2 17 end 18 v = add mul v 10 sub c 48 19 end 20 ret v 21 end 22 fn ic_width t uint to ulong 23 if or eq t 2 eq t 6 24 ret 8 25 end 26 if or eq t 3 eq t 7 27 ret 16 28 end 29 if or eq t 4 eq t 8 30 ret 32 31 end 32 ret 64 33 end 34 fn ic8 x uchar t uint to void 35 if eq t 6 36 y = byte x 37 ret 38 end 39 if eq t 7 40 y = short x 41 ret 42 end 43 if eq t 8 44 y = int x 45 ret 46 end 47 y = long x 48 end 49 fn ic16 x ushort t uint to void 50 if eq t 6 51 y = byte x 52 ret 53 end 54 if eq t 7 55 y = short x 56 ret 57 end 58 if eq t 8 59 y = int x 60 ret 61 end 62 y = long x 63 end 64 fn ic32 x uint t uint to void 65 if eq t 6 66 y = byte x 67 ret 68 end 69 if eq t 7 70 y = short x 71 ret 72 end 73 if eq t 8 74 y = int x 75 ret 76 end 77 y = long x 78 end 79 fn ic64 x ulong t uint to void 80 if eq t 6 81 y = byte x 82 ret 83 end 84 if eq t 7 85 y = short x 86 ret 87 end 88 if eq t 8 89 y = int x 90 ret 91 end 92 y = long x 93 end 94 fn ic_emit s uint t uint v ulong to void 95 ir_init 96 f = ir_fnew 2 0 8 97 b = ir_blk f 98 a = ir_res ir_op b 1 s v 0 99 o = ir_op b 78 t 5 2 100 ir_set o 0 ir_ftok f 101 ir_set o 1 a 102 tok = ir_otok o 103 cv = ir_op b 36 t 0 1 104 ir_set cv 0 a 105 z = ir_res ir_op b 1 8 0 0 106 o = ir_op b 63 0 0 2 107 ir_set o 0 tok 108 ir_set o 1 z 109 n = ir_wr 110 if eq ar_out 1 1 0 n 0 111 exit 2 112 end 113 end 114 fn ic_umain to int 115 if ne argcnt 4 116 ret 2 117 end 118 s = ic_num 1 119 t = ic_num 2 120 j = ic_num 3 121 if or lt s 2 gt s 5 122 ret 2 123 end 124 if or lt t 6 gt t 9 125 ret 2 126 end 127 if gt j 7 128 ret 2 129 end 130 ws = ic_width s 131 mx = not ulong 0 132 if lt ws 64 133 mx = sub shl ulong 1 ws 1 134 end 135 hi = shl ulong 1 sub ic_width t 1 136 v = ulong 0 137 if eq j 1 138 v = sub hi 1 139 end 140 if eq j 2 141 v = hi 142 end 143 if eq j 3 144 v = add hi 1 145 end 146 if eq j 4 147 v = mx 148 end 149 if eq j 5 150 v = sub mx 1 151 end 152 if eq j 6 153 v = 1 154 end 155 if eq j 7 156 v = shl ulong 1 sub ws 1 157 end 158 if gt v mx 159 v = mx 160 end 161 ic_emit s t v 162 if eq s 2 163 ic8 uchar v t 164 end 165 if eq s 3 166 ic16 ushort v t 167 end 168 if eq s 4 169 ic32 uint v t 170 end 171 if eq s 5 172 ic64 v t 173 end 174 ret 0 175 end 176 177 fn ic_boundary t uint j ulong to f64 178 w = ic_width t 179 hi = mul f64 shl ulong 1 sub w 1 2.0f64 180 lo = f64 0.0 181 if ge t 6 182 hi = f64 shl ulong 1 sub w 1 183 lo = neg hi 184 end 185 if eq j 0 186 ret sub lo 1.0 187 end 188 if eq j 1 189 ret sub lo 0.5 190 end 191 if eq j 2 192 ret lo 193 end 194 if eq j 3 195 ret add lo 0.5 196 end 197 if eq j 4 198 ret add lo 1.0 199 end 200 if eq j 5 201 ret sub hi 1.0 202 end 203 if eq j 6 204 ret sub hi 0.5 205 end 206 if eq j 7 207 ret hi 208 end 209 if eq j 8 210 ret add hi 0.5 211 end 212 if eq j 9 213 ret add hi 1.0 214 end 215 note Adjacent representable values below and above the high boundary, including 64-bit widths. 216 u = bitcast ulong hi 217 if eq j 10 218 ret bitcast f64 sub u 1 219 end 220 if eq j 11 221 ret bitcast f64 add u 1 222 end 223 u = bitcast ulong lo 224 if eq j 12 225 if eq lo 0.0f64 226 ret bitcast f64 ulong 0x8000000000000001 227 end 228 ret bitcast f64 sub u 1 229 end 230 if eq j 13 231 ret bitcast f64 add u 1 232 end 233 if eq j 14 234 ret -0.5f64 235 end 236 ret 0.5f64 237 end 238 note Independent integer decoding of truncation range, not ngrun's float comparisons. 239 fn ic_floatbad s uint t uint bits ulong to bool 240 p = ulong 52 241 bias = ulong 1023 242 es = ulong 2047 243 sg = ne shr bits 63 0 244 if eq s 13 245 p = 23 246 bias = 127 247 es = 255 248 sg = ne shr bits 31 0 249 end 250 e = and shr bits p es 251 m = and bits sub shl ulong 1 p 1 252 if eq e es 253 ret true 254 end 255 if lt e bias 256 ret false 257 end 258 e = sub e bias 259 w = ic_width t 260 if lt t 6 261 ret or sg ge e w 262 end 263 if not sg 264 ret ge e sub w 1 265 end 266 if gt e sub w 1 267 ret true 268 end 269 if lt e sub w 1 270 ret false 271 end 272 if ge e p 273 ret ne m 0 274 end 275 ret ne shr m sub p e 0 276 end 277 fn ic_fmain s uint to int 278 t = ic_num 2 279 j = ic_num 3 280 if or lt t 2 gt t 9 281 ret 2 282 end 283 if gt j 15 284 ret 2 285 end 286 x = ic_boundary t ulong j 287 bits = bitcast ulong x 288 if eq s 13 289 bits = ulong bitcast uint f32 x 290 end 291 ic_emit s t bits 292 if ic_floatbad s t bits 293 ret 105 294 end 295 ret 0 296 end 297 fn main to int 298 if ne argcnt 4 299 ret 2 300 end 301 s = ic_num 1 302 if or eq s 13 eq s 14 303 ret ic_fmain s 304 end 305 ret ic_umain 306 end