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 / tests / polyglot / test_asm.om
| 1 | note SPDX-License-Identifier: Apache-2.0 |
| 2 | note Copyright 2026 Drake Stapleton (AIEN / aien-dev) |
| 3 | note |
| 4 | note tests/polyglot/test_asm.om -- pure seeded OM-2 POLYGLOT-0 lane B1 correctness gate |
| 5 | note (asm_sdot, asm_crumb): error contract, MA-3 shape grid, random unaligned+canary |
| 6 | note cases, and large magnitudes up to OMX_MAX_N (16,777,215). |
| 7 | |
| 8 | global g_ta_st ulong 8 |
| 9 | note [0]=checks [1]=fail [2]=cases [3]=rng |
| 10 | global g_ta_ns ulong 31 |
| 11 | global g_ta_ms ulong 10 |
| 12 | global g_ta_sps f64 5 |
| 13 | global g_ta_bad byte 5 |
| 14 | |
| 15 | text t_ta_hdr "POLYGLOT test-asm " |
| 16 | text t_ta_pass "PASS" |
| 17 | text t_ta_fail "FAIL" |
| 18 | text t_ta_sep1 ": " |
| 19 | text t_ta_chk " checks, " |
| 20 | text t_ta_fls " failures; 2 candidates; cases: grid " |
| 21 | text t_ta_rnd ", random " |
| 22 | text t_ta_lrg ", large " |
| 23 | text t_ta_err "; error-contract checks " |
| 24 | text t_ta_efail "FAIL test_asm check #" |
| 25 | |
| 26 | fn ta_init_tables to void |
| 27 | put g_ta_st 0 0 |
| 28 | put g_ta_st 1 0 |
| 29 | put g_ta_st 2 0 |
| 30 | put g_ta_st 3 0x504f4c5941534d31 |
| 31 | |
| 32 | put g_ta_ns 0 1 |
| 33 | put g_ta_ns 1 2 |
| 34 | put g_ta_ns 2 3 |
| 35 | put g_ta_ns 3 4 |
| 36 | put g_ta_ns 4 5 |
| 37 | put g_ta_ns 5 7 |
| 38 | put g_ta_ns 6 15 |
| 39 | put g_ta_ns 7 16 |
| 40 | put g_ta_ns 8 17 |
| 41 | put g_ta_ns 9 31 |
| 42 | put g_ta_ns 10 32 |
| 43 | put g_ta_ns 11 33 |
| 44 | put g_ta_ns 12 63 |
| 45 | put g_ta_ns 13 64 |
| 46 | put g_ta_ns 14 65 |
| 47 | put g_ta_ns 15 79 |
| 48 | put g_ta_ns 16 80 |
| 49 | put g_ta_ns 17 81 |
| 50 | put g_ta_ns 18 127 |
| 51 | put g_ta_ns 19 128 |
| 52 | put g_ta_ns 20 129 |
| 53 | put g_ta_ns 21 159 |
| 54 | put g_ta_ns 22 160 |
| 55 | put g_ta_ns 23 161 |
| 56 | put g_ta_ns 24 255 |
| 57 | put g_ta_ns 25 256 |
| 58 | put g_ta_ns 26 257 |
| 59 | put g_ta_ns 27 1000 |
| 60 | put g_ta_ns 28 1023 |
| 61 | put g_ta_ns 29 1024 |
| 62 | put g_ta_ns 30 1025 |
| 63 | |
| 64 | put g_ta_ms 0 1 |
| 65 | put g_ta_ms 1 2 |
| 66 | put g_ta_ms 2 3 |
| 67 | put g_ta_ms 3 4 |
| 68 | put g_ta_ms 4 5 |
| 69 | put g_ta_ms 5 7 |
| 70 | put g_ta_ms 6 15 |
| 71 | put g_ta_ms 7 16 |
| 72 | put g_ta_ms 8 17 |
| 73 | put g_ta_ms 9 33 |
| 74 | |
| 75 | put g_ta_sps 0 0.0f64 |
| 76 | put g_ta_sps 1 0.3f64 |
| 77 | put g_ta_sps 2 0.6f64 |
| 78 | put g_ta_sps 3 0.9f64 |
| 79 | put g_ta_sps 4 1.0f64 |
| 80 | |
| 81 | put g_ta_bad 0 byte 2 |
| 82 | put g_ta_bad 1 byte -2 |
| 83 | put g_ta_bad 2 byte -128 |
| 84 | put g_ta_bad 3 byte 127 |
| 85 | put g_ta_bad 4 byte 3 |
| 86 | end |
| 87 | |
| 88 | fn ta_rnd to ulong |
| 89 | st = new ulong 1 0 |
| 90 | put st 0 get g_ta_st 3 |
| 91 | v = omx_rng_next st |
| 92 | put g_ta_st 3 get st 0 |
| 93 | ret v |
| 94 | end |
| 95 | |
| 96 | fn ta_rnd01 to f64 |
| 97 | st = new ulong 1 0 |
| 98 | put st 0 get g_ta_st 3 |
| 99 | v = omx_rng_01 st |
| 100 | put g_ta_st 3 get st 0 |
| 101 | ret v |
| 102 | end |
| 103 | |
| 104 | fn ta_chk cond bool to void |
| 105 | c = add get g_ta_st 0 1 |
| 106 | put g_ta_st 0 c |
| 107 | if not cond |
| 108 | f = add get g_ta_st 1 1 |
| 109 | put g_ta_st 1 f |
| 110 | if le f 20 |
| 111 | omx_eputs t_ta_efail |
| 112 | omx_eputu c |
| 113 | omx_enl |
| 114 | end |
| 115 | end |
| 116 | end |
| 117 | |
| 118 | note wk: 0=random 1=zero 2=pos 3=neg |
| 119 | fn ta_fill_w cnt ulong wk ulong sp f64 to void |
| 120 | for i ulong cnt bound 16777216 |
| 121 | if eq wk 1 |
| 122 | put g_omx_w i byte 0 |
| 123 | else |
| 124 | if eq wk 2 |
| 125 | put g_omx_w i byte 1 |
| 126 | else |
| 127 | if eq wk 3 |
| 128 | put g_omx_w i byte -1 |
| 129 | else |
| 130 | if lt ta_rnd01 sp |
| 131 | put g_omx_w i byte 0 |
| 132 | else |
| 133 | if eq and ta_rnd 1 1 |
| 134 | put g_omx_w i byte 1 |
| 135 | else |
| 136 | put g_omx_w i byte -1 |
| 137 | end |
| 138 | end |
| 139 | end |
| 140 | end |
| 141 | end |
| 142 | end |
| 143 | end |
| 144 | |
| 145 | note xk: 0=random 1=min(-128) 2=max(127) 3=alt 4=zero |
| 146 | fn ta_fill_x xoff ulong n ulong xk ulong to void |
| 147 | for j ulong n bound 16777216 |
| 148 | if eq xk 1 |
| 149 | put g_omx_x add xoff j byte -128 |
| 150 | else |
| 151 | if eq xk 2 |
| 152 | put g_omx_x add xoff j byte 127 |
| 153 | else |
| 154 | if eq xk 3 |
| 155 | if eq and j 1 1 |
| 156 | put g_omx_x add xoff j byte 127 |
| 157 | else |
| 158 | put g_omx_x add xoff j byte -128 |
| 159 | end |
| 160 | else |
| 161 | if eq xk 4 |
| 162 | put g_omx_x add xoff j byte 0 |
| 163 | else |
| 164 | u = and ta_rnd 255 |
| 165 | if ge u 128 |
| 166 | put g_omx_x add xoff j byte sub long u 256 |
| 167 | else |
| 168 | put g_omx_x add xoff j byte long u |
| 169 | end |
| 170 | end |
| 171 | end |
| 172 | end |
| 173 | end |
| 174 | end |
| 175 | end |
| 176 | |
| 177 | fn ta_run_rep kind ulong m ulong xoff ulong yoff ulong to void |
| 178 | for i ulong m bound 65536 |
| 179 | put g_omx_y add yoff i int 0x5a5a5a5a |
| 180 | end |
| 181 | ta_chk eq omx_run_cand kind xoff yoff 1 1 OMX_OK |
| 182 | bad = ulong 0 |
| 183 | for i ulong m bound 65536 |
| 184 | if ne get g_omx_y add yoff i get g_omx_yref i |
| 185 | bad = add bad 1 |
| 186 | end |
| 187 | end |
| 188 | ta_chk eq bad 0 |
| 189 | end |
| 190 | |
| 191 | fn ta_check_impl kind ulong m ulong n ulong xoff ulong yoff ulong to void |
| 192 | rc = omx_pack_cand kind m n 1 |
| 193 | ta_chk eq rc OMX_OK |
| 194 | if ne rc OMX_OK |
| 195 | omx_plan_zero |
| 196 | ret |
| 197 | end |
| 198 | ta_chk and gt get g_omx_plan 2 0 ge get g_omx_plan 3 get g_omx_plan 2 |
| 199 | ta_run_rep kind m xoff yoff |
| 200 | ta_run_rep kind m xoff yoff |
| 201 | omx_plan_zero |
| 202 | put g_ta_st 2 add get g_ta_st 2 1 |
| 203 | end |
| 204 | |
| 205 | fn ta_run_case m ulong n ulong wk ulong sp f64 xk ulong to void |
| 206 | ta_fill_w mul m n wk sp |
| 207 | ta_fill_x 0 n xk |
| 208 | ta_chk eq omx_oracle m n 0 OMX_OK |
| 209 | ta_check_impl OMX_CAND_SDOT m n 0 0 |
| 210 | ta_check_impl OMX_CAND_CRUMB m n 0 0 |
| 211 | end |
| 212 | |
| 213 | fn ta_check_spill ybase ulong yend ulong ytot ulong to void |
| 214 | spill = ulong 0 |
| 215 | for i ulong ybase bound 65536 |
| 216 | if ne get g_omx_y i int -1515870811 |
| 217 | spill = add spill 1 |
| 218 | end |
| 219 | end |
| 220 | i = yend |
| 221 | while lt i ytot bound 65536 |
| 222 | if ne get g_omx_y i int -1515870811 |
| 223 | spill = add spill 1 |
| 224 | end |
| 225 | i = add i 1 |
| 226 | end |
| 227 | ta_chk eq spill 0 |
| 228 | end |
| 229 | |
| 230 | fn ta_run_random m ulong n ulong sp f64 xk ulong xo ulong yo ulong to void |
| 231 | ta_fill_w mul m n 0 sp |
| 232 | ta_fill_x xo n xk |
| 233 | ta_chk eq omx_oracle m n xo OMX_OK |
| 234 | ybase = add 16 yo |
| 235 | yend = add ybase m |
| 236 | ytot = add m 48 |
| 237 | for c ulong 2 |
| 238 | kind = OMX_CAND_SDOT |
| 239 | if eq c 1 |
| 240 | kind = OMX_CAND_CRUMB |
| 241 | end |
| 242 | for i ulong ytot bound 65536 |
| 243 | put g_omx_y i int -1515870811 |
| 244 | end |
| 245 | ta_check_impl kind m n xo ybase |
| 246 | ta_check_spill ybase yend ytot |
| 247 | end |
| 248 | end |
| 249 | |
| 250 | fn ta_test_errors to void |
| 251 | put g_omx_w 0 byte 1 |
| 252 | put g_omx_w 1 byte 0 |
| 253 | put g_omx_w 2 byte -1 |
| 254 | put g_omx_w 3 byte 1 |
| 255 | put g_omx_w 4 byte 0 |
| 256 | put g_omx_w 5 byte 1 |
| 257 | put g_omx_x 0 byte 1 |
| 258 | put g_omx_x 1 byte 2 |
| 259 | put g_omx_x 2 byte 3 |
| 260 | for c ulong 2 |
| 261 | kind = OMX_CAND_SDOT |
| 262 | if eq c 1 |
| 263 | kind = OMX_CAND_CRUMB |
| 264 | end |
| 265 | for b ulong 5 |
| 266 | put g_omx_w 3 get g_ta_bad b |
| 267 | put g_omx_plan 5 77 |
| 268 | ta_chk eq omx_pack_cand kind 2 3 1 OMX_E_TRIT |
| 269 | ta_chk eq omx_plan_is_zero 1 |
| 270 | end |
| 271 | put g_omx_w 3 byte 1 |
| 272 | put g_omx_plan 5 77 |
| 273 | ta_chk eq omx_pack_cand kind 0 3 1 OMX_E_ARG |
| 274 | ta_chk eq omx_plan_is_zero 1 |
| 275 | ta_chk eq omx_pack_cand kind 2 0 1 OMX_E_ARG |
| 276 | ta_chk eq omx_pack_cand kind 2 3 0 OMX_E_ARG |
| 277 | ta_chk eq omx_plan_is_zero 1 |
| 278 | ta_chk eq omx_pack_cand kind 1 add OMX_MAX_N 1 1 OMX_E_ARG |
| 279 | ta_chk eq omx_pack_cand kind 1 OMX_ULONG_MAX 1 OMX_E_ARG |
| 280 | ta_chk eq omx_pack_cand kind div OMX_ULONG_MAX 2 1000 1 OMX_E_OVERFLOW |
| 281 | ta_chk eq omx_plan_is_zero 1 |
| 282 | omx_plan_zero |
| 283 | ta_chk eq omx_run_cand kind 0 0 1 1 OMX_E_ARG |
| 284 | ta_chk eq omx_pack_cand kind 2 3 1 OMX_OK |
| 285 | ta_chk eq omx_run_cand kind 0 0 0 1 OMX_E_ARG |
| 286 | ta_chk eq omx_run_cand kind 0 0 1 0 OMX_E_ARG |
| 287 | put g_omx_plan 0 0 |
| 288 | ta_chk eq omx_run_cand kind 0 0 1 1 OMX_E_ARG |
| 289 | put g_omx_plan 0 2 |
| 290 | put g_omx_plan 1 0 |
| 291 | ta_chk eq omx_run_cand kind 0 0 1 1 OMX_E_ARG |
| 292 | put g_omx_plan 1 3 |
| 293 | ta_chk eq omx_run_cand kind 0 0 1 1 OMX_OK |
| 294 | ta_chk eq get g_omx_y 0 int -2 |
| 295 | ta_chk eq get g_omx_y 1 int 4 |
| 296 | omx_plan_zero |
| 297 | end |
| 298 | end |
| 299 | |
| 300 | fn main to int |
| 301 | ta_init_tables |
| 302 | ta_test_errors |
| 303 | c0 = get g_ta_st 0 |
| 304 | |
| 305 | note 1. MA-3 shape grid |
| 306 | for a ulong 31 |
| 307 | nv = get g_ta_ns a |
| 308 | for b ulong 10 |
| 309 | mv = get g_ta_ms b |
| 310 | ta_run_case mv nv 1 0.0f64 0 |
| 311 | ta_run_case mv nv 2 0.0f64 1 |
| 312 | ta_run_case mv nv 2 0.0f64 2 |
| 313 | ta_run_case mv nv 3 0.0f64 1 |
| 314 | ta_run_case mv nv 3 0.0f64 2 |
| 315 | ta_run_case mv nv 0 get g_ta_sps rem add a b 5 3 |
| 316 | ta_run_case mv nv 0 get g_ta_sps rem add mul a 3 b 5 0 |
| 317 | end |
| 318 | end |
| 319 | grid_cases = get g_ta_st 2 |
| 320 | |
| 321 | note 2. random cases with unaligned offsets & y canaries |
| 322 | for it ulong 2000 bound 2000 |
| 323 | n = add 1 rem ta_rnd 2100 |
| 324 | m = add 1 rem ta_rnd 70 |
| 325 | xk = ulong 0 |
| 326 | if eq rem ta_rnd 4 0 |
| 327 | xk = rem ta_rnd 5 |
| 328 | end |
| 329 | xo = add 1 rem ta_rnd 15 |
| 330 | yo = add 1 rem ta_rnd 15 |
| 331 | ta_run_random m n ta_rnd01 xk xo yo |
| 332 | end |
| 333 | random_cases = sub get g_ta_st 2 grid_cases |
| 334 | |
| 335 | note 3. large magnitudes up to OMX_MAX_N |
| 336 | ta_run_case 5 16384 3 0.0f64 1 |
| 337 | ta_run_case 5 16384 2 0.0f64 1 |
| 338 | ta_run_case 1 100003 3 0.0f64 1 |
| 339 | ta_run_case 6 1048613 0 0.3f64 0 |
| 340 | ta_run_case 17 4099 0 0.97f64 0 |
| 341 | ta_run_case 1 OMX_MAX_N 3 0.0f64 1 |
| 342 | ta_run_case 1 OMX_MAX_N 2 0.0f64 1 |
| 343 | ta_run_case 1 OMX_MAX_N 0 0.5f64 3 |
| 344 | large_cases = sub sub get g_ta_st 2 grid_cases random_cases |
| 345 | |
| 346 | omx_puts t_ta_hdr |
| 347 | if eq get g_ta_st 1 0 |
| 348 | omx_puts t_ta_pass |
| 349 | else |
| 350 | omx_puts t_ta_fail |
| 351 | end |
| 352 | omx_puts t_ta_sep1 |
| 353 | omx_putu get g_ta_st 0 |
| 354 | omx_puts t_ta_chk |
| 355 | omx_putu get g_ta_st 1 |
| 356 | omx_puts t_ta_fls |
| 357 | omx_putu grid_cases |
| 358 | omx_puts t_ta_rnd |
| 359 | omx_putu random_cases |
| 360 | omx_puts t_ta_lrg |
| 361 | omx_putu large_cases |
| 362 | omx_puts t_ta_err |
| 363 | omx_putu c0 |
| 364 | omx_nl |
| 365 | if ne get g_ta_st 1 0 |
| 366 | ret 1 |
| 367 | end |
| 368 | ret 0 |
| 369 | end |