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 / algebra / test_ma_digital_bottom.om
| 1 | note SPDX-License-Identifier: Apache-2.0 |
| 2 | note Pure seeded OM-2 MA_DIGITAL_V1 bottom (perp) coverage test. |
| 3 | note Replaces tests/algebra/test_ma_digital_bottom.c. |
| 4 | note Concatenated after src/algebra/oma_lib.om + src/algebra/realize.om. |
| 5 | |
| 6 | global b_chk ulong 2 |
| 7 | global b_rng ulong 1 |
| 8 | global b_cnts ulong 2 |
| 9 | |
| 10 | text b_pass "PASS " |
| 11 | text b_fail "FAIL " |
| 12 | text b_s1 "H1 perp refused (encode/decode/add/mul/dot) " |
| 13 | text b_s2 "every non-trit int8 refused by every pack " |
| 14 | text b_s3 "packed H1 planes/LUT nibbles/crumbs no perp " |
| 15 | text b_chk_s " checks, " |
| 16 | text b_fail_s " failures\n" |
| 17 | text b_hdr_p "MA_DIGITAL_V1 bottom PASS: " |
| 18 | text b_hdr_f "MA_DIGITAL_V1 bottom FAIL: " |
| 19 | text b_rz_s " failures, 10 realizations\n" |
| 20 | |
| 21 | fn bchk ok bool to void |
| 22 | put b_chk 0 add get b_chk 0 1 |
| 23 | if not ok |
| 24 | put b_chk 1 add get b_chk 1 1 |
| 25 | end |
| 26 | end |
| 27 | |
| 28 | fn brnd to ulong |
| 29 | s = add get b_rng 0 0x9e3779b97f4a7c15 |
| 30 | put b_rng 0 s |
| 31 | z = mul xor s shr s 30 0xbf58476d1ce4e5b9 |
| 32 | z = mul xor z shr z 27 0x94d049bb133111eb |
| 33 | ret xor z shr z 31 |
| 34 | end |
| 35 | |
| 36 | fn b_fill_w cnt ulong kind int to void |
| 37 | for i ulong cnt bound 262144 |
| 38 | if eq kind 1 |
| 39 | put rz_w i byte 1 |
| 40 | else |
| 41 | if eq kind 2 |
| 42 | put rz_w i byte -1 |
| 43 | else |
| 44 | if eq kind 3 |
| 45 | put rz_w i byte 0 |
| 46 | else |
| 47 | put rz_w i byte sub int rem brnd 3 1 |
| 48 | end |
| 49 | end |
| 50 | end |
| 51 | end |
| 52 | end |
| 53 | |
| 54 | fn b_sec_print label view uchar * c0 ulong f0 ulong to void |
| 55 | dc = sub get b_chk 0 c0 |
| 56 | df = sub get b_chk 1 f0 |
| 57 | if eq df 0 |
| 58 | oma_put_str b_pass |
| 59 | else |
| 60 | oma_put_str b_fail |
| 61 | end |
| 62 | oma_put_str label |
| 63 | oma_put_u64 1 dc |
| 64 | oma_put_str b_chk_s |
| 65 | oma_put_u64 1 df |
| 66 | oma_put_str b_fail_s |
| 67 | end |
| 68 | |
| 69 | fn test_h1_bottom_lane k ulong to void |
| 70 | good = new ulong 2 0 |
| 71 | bad = new ulong 2 0 |
| 72 | mask = shl ulong 1 k |
| 73 | put bad 0 mask |
| 74 | put bad 1 mask |
| 75 | lanes = new byte 64 42 |
| 76 | bchk eq oma_block_decode bad lanes OMA_E_INVALID_PLANES |
| 77 | bchk and eq int get lanes 0 42 eq int get lanes 63 42 |
| 78 | bchk eq oma_unpack_bitplane bad 1 64 lanes OMA_E_INVALID_PLANES |
| 79 | bchk eq int get lanes k 42 |
| 80 | o1 = new ulong 2 5 |
| 81 | o2 = new ulong 2 6 |
| 82 | bchk eq oma_block_add bad good o1 o2 OMA_E_INVALID_PLANES |
| 83 | bchk and eq get o1 0 5 eq get o2 0 6 |
| 84 | bchk eq oma_block_add good bad o1 o2 OMA_E_INVALID_PLANES |
| 85 | bchk and eq get o1 1 5 eq get o2 1 6 |
| 86 | bchk eq oma_block_mul bad good o1 OMA_E_INVALID_PLANES |
| 87 | bchk eq get o1 0 5 |
| 88 | bchk eq oma_block_mul good bad o1 OMA_E_INVALID_PLANES |
| 89 | bchk eq get o1 1 5 |
| 90 | d = new int 1 42 |
| 91 | bchk eq oma_block_dot good bad d OMA_E_INVALID_PLANES |
| 92 | bchk eq get d 0 42 |
| 93 | end |
| 94 | |
| 95 | fn test_h1_codes to void |
| 96 | sc = new uchar 2 77 |
| 97 | m = new uchar 1 77 |
| 98 | for a int 4 |
| 99 | for b int 4 |
| 100 | if or eq a 3 eq b 3 |
| 101 | put sc 0 uchar 77 |
| 102 | put sc 1 uchar 77 |
| 103 | put m 0 uchar 77 |
| 104 | bchk eq oma_code_add a b sc OMA_E_INVALID_CODE |
| 105 | bchk and eq int get sc 0 77 eq int get sc 1 77 |
| 106 | bchk eq oma_code_mul a b m OMA_E_INVALID_CODE |
| 107 | bchk eq int get m 0 77 |
| 108 | end |
| 109 | end |
| 110 | end |
| 111 | end |
| 112 | |
| 113 | fn test_h1_bottom to void |
| 114 | c0 = get b_chk 0 |
| 115 | f0 = get b_chk 1 |
| 116 | code = new uchar 1 0 |
| 117 | t = new byte 1 0 |
| 118 | v = int -128 |
| 119 | while le v 127 bound 300 |
| 120 | put code 0 uchar 77 |
| 121 | rc = oma_trit_to_code v code |
| 122 | if and ge v -1 le v 1 |
| 123 | put t 0 byte 9 |
| 124 | bchk and eq rc 0 ne get code 0 3 |
| 125 | bchk and eq oma_code_to_trit int get code 0 t 0 eq int get t 0 v |
| 126 | else |
| 127 | bchk eq rc OMA_E_INVALID_TRIT |
| 128 | end |
| 129 | v = add v 1 |
| 130 | end |
| 131 | put t 0 byte 9 |
| 132 | bchk and eq oma_code_to_trit 3 t OMA_E_INVALID_CODE eq int get t 0 9 |
| 133 | test_h1_codes |
| 134 | for k ulong 64 |
| 135 | test_h1_bottom_lane k |
| 136 | end |
| 137 | b_sec_print b_s1 c0 f0 |
| 138 | end |
| 139 | |
| 140 | fn test_rz_refuse_non_trits to void |
| 141 | c0 = get b_chk 0 |
| 142 | f0 = get b_chk 1 |
| 143 | m = ulong 3 |
| 144 | n = ulong 131 |
| 145 | tot = mul m n |
| 146 | v = int -128 |
| 147 | while le v 127 bound 300 |
| 148 | if or lt v -1 gt v 1 |
| 149 | b_fill_w tot 0 |
| 150 | pos = rem brnd tot |
| 151 | put rz_w pos byte v |
| 152 | for rid ulong OMA_RZ_COUNT |
| 153 | bchk eq oma_rz_pack_g rid m n OMA_RZ_E_TRIT |
| 154 | end |
| 155 | end |
| 156 | v = add v 1 |
| 157 | end |
| 158 | b_sec_print b_s2 c0 f0 |
| 159 | end |
| 160 | |
| 161 | fn check_bp_lane row_off ulong base ulong col0 ulong n ulong to void |
| 162 | pj = ulong get rz_mem base |
| 163 | nj = ulong get rz_mem add base 16 |
| 164 | if ne and pj nj 0 |
| 165 | put b_cnts 0 add get b_cnts 0 1 |
| 166 | end |
| 167 | for k ulong 8 |
| 168 | col = add col0 mul 16 k |
| 169 | pv = int and shr pj k 1 |
| 170 | nv = int and shr nj k 1 |
| 171 | v = sub pv nv |
| 172 | want = int 0 |
| 173 | if lt col n |
| 174 | want = int get rz_w add row_off col |
| 175 | end |
| 176 | if ne v want |
| 177 | put b_cnts 1 add get b_cnts 1 1 |
| 178 | end |
| 179 | end |
| 180 | end |
| 181 | |
| 182 | fn check_bp_chunk i ulong c ulong n ulong rb ulong to void |
| 183 | row_off = mul i n |
| 184 | base_c = add mul i rb mul c 32 |
| 185 | cbase = mul c 128 |
| 186 | for j ulong 16 |
| 187 | check_bp_lane row_off add base_c j add cbase j n |
| 188 | end |
| 189 | end |
| 190 | |
| 191 | fn check_bitplane m ulong n ulong to void |
| 192 | bchk eq oma_rz_pack_g RZ_R2_BITPLANE m n OMA_RZ_OK |
| 193 | chunks = div add n 127 128 |
| 194 | rb = mul chunks 32 |
| 195 | put b_cnts 0 0 |
| 196 | put b_cnts 1 0 |
| 197 | for i ulong m bound 64 |
| 198 | for c ulong chunks bound 256 |
| 199 | check_bp_chunk i c n rb |
| 200 | end |
| 201 | end |
| 202 | bchk eq get b_cnts 0 0 |
| 203 | bchk eq get b_cnts 1 0 |
| 204 | end |
| 205 | |
| 206 | fn check_cr_lane row_off ulong bv ulong col0 ulong n ulong to void |
| 207 | for k ulong 4 |
| 208 | cr = and shr bv mul 2 k 3 |
| 209 | if eq cr 2 |
| 210 | put b_cnts 0 add get b_cnts 0 1 |
| 211 | end |
| 212 | v = int 99 |
| 213 | if eq cr 0 |
| 214 | v = 0 |
| 215 | else |
| 216 | if eq cr 1 |
| 217 | v = 1 |
| 218 | else |
| 219 | if eq cr 3 |
| 220 | v = -1 |
| 221 | end |
| 222 | end |
| 223 | end |
| 224 | col = add col0 mul 16 k |
| 225 | want = int 0 |
| 226 | if lt col n |
| 227 | want = int get rz_w add row_off col |
| 228 | end |
| 229 | if ne v want |
| 230 | put b_cnts 1 add get b_cnts 1 1 |
| 231 | end |
| 232 | end |
| 233 | end |
| 234 | |
| 235 | fn check_cr_chunk i ulong c ulong n ulong rb ulong to void |
| 236 | row_off = mul i n |
| 237 | base_c = add mul i rb mul c 16 |
| 238 | cbase = mul c 64 |
| 239 | for j ulong 16 |
| 240 | bv = ulong get rz_mem add base_c j |
| 241 | check_cr_lane row_off bv add cbase j n |
| 242 | end |
| 243 | end |
| 244 | |
| 245 | fn check_crumb m ulong n ulong to void |
| 246 | bchk eq oma_rz_pack_g RZ_R2C_CRUMB m n OMA_RZ_OK |
| 247 | chunks = div add n 63 64 |
| 248 | rb = mul chunks 16 |
| 249 | put b_cnts 0 0 |
| 250 | put b_cnts 1 0 |
| 251 | for i ulong m bound 64 |
| 252 | for c ulong chunks bound 512 |
| 253 | check_cr_chunk i c n rb |
| 254 | end |
| 255 | end |
| 256 | bchk eq get b_cnts 0 0 |
| 257 | bchk eq get b_cnts 1 0 |
| 258 | end |
| 259 | |
| 260 | fn check_lut_byte row ulong col0 ulong m ulong n ulong bv ulong to void |
| 261 | if ne and and bv 15 shr bv 4 0 |
| 262 | put b_cnts 0 add get b_cnts 0 1 |
| 263 | end |
| 264 | for q ulong 4 |
| 265 | col = add col0 q |
| 266 | pv = int and shr bv q 1 |
| 267 | nv = int and shr bv add 4 q 1 |
| 268 | v = sub pv nv |
| 269 | want = int 0 |
| 270 | if lt row m |
| 271 | if lt col n |
| 272 | want = int get rz_w add mul row n col |
| 273 | end |
| 274 | end |
| 275 | if ne v want |
| 276 | put b_cnts 1 add get b_cnts 1 1 |
| 277 | end |
| 278 | end |
| 279 | end |
| 280 | |
| 281 | fn check_lut_row row ulong g ulong m ulong n ulong base_off ulong to void |
| 282 | for j ulong 4 |
| 283 | bv = ulong get rz_mem add base_off j |
| 284 | col0 = add mul g 16 mul 4 j |
| 285 | check_lut_byte row col0 m n bv |
| 286 | end |
| 287 | end |
| 288 | |
| 289 | fn check_lut_blk bl ulong g ulong m ulong n ulong sg ulong to void |
| 290 | blk_off = mul add mul bl sg g 64 |
| 291 | for r ulong 16 |
| 292 | row = add mul bl 16 r |
| 293 | check_lut_row row g m n add blk_off rz_lut_ro r |
| 294 | end |
| 295 | end |
| 296 | |
| 297 | fn check_lut m ulong n ulong to void |
| 298 | bchk eq oma_rz_pack_g RZ_R2B_LUT m n OMA_RZ_OK |
| 299 | sg = div add n 15 16 |
| 300 | mb = div add m 15 16 |
| 301 | bchk eq get rz_plan 2 mul mul mb sg 64 |
| 302 | put b_cnts 0 0 |
| 303 | put b_cnts 1 0 |
| 304 | for bl ulong mb bound 16 |
| 305 | for g ulong sg bound 2048 |
| 306 | check_lut_blk bl g m n sg |
| 307 | end |
| 308 | end |
| 309 | bchk eq get b_cnts 0 0 |
| 310 | bchk eq get b_cnts 1 0 |
| 311 | end |
| 312 | |
| 313 | fn check_all_packed m ulong n ulong kind int to void |
| 314 | b_fill_w mul m n kind |
| 315 | check_bitplane m n |
| 316 | check_crumb m n |
| 317 | check_lut m n |
| 318 | end |
| 319 | |
| 320 | fn test_packed_no_bottom to void |
| 321 | c0 = get b_chk 0 |
| 322 | f0 = get b_chk 1 |
| 323 | ns = new ulong 15 0 |
| 324 | put ns 0 1 |
| 325 | put ns 1 15 |
| 326 | put ns 2 16 |
| 327 | put ns 3 17 |
| 328 | put ns 4 63 |
| 329 | put ns 5 64 |
| 330 | put ns 6 65 |
| 331 | put ns 7 127 |
| 332 | put ns 8 128 |
| 333 | put ns 9 129 |
| 334 | put ns 10 255 |
| 335 | put ns 11 256 |
| 336 | put ns 12 257 |
| 337 | put ns 13 1000 |
| 338 | put ns 14 4099 |
| 339 | ms = new ulong 5 0 |
| 340 | put ms 0 1 |
| 341 | put ms 1 2 |
| 342 | put ms 2 3 |
| 343 | put ms 3 5 |
| 344 | put ms 4 17 |
| 345 | for a ulong 15 |
| 346 | for bi ulong 5 |
| 347 | for kind int 4 |
| 348 | check_all_packed get ms bi get ns a kind |
| 349 | end |
| 350 | end |
| 351 | end |
| 352 | for it ulong 200 |
| 353 | n = add 1 rem brnd 3000 |
| 354 | m = add 1 rem brnd 40 |
| 355 | check_all_packed m n 0 |
| 356 | end |
| 357 | check_all_packed 2 16384 0 |
| 358 | b_sec_print b_s3 c0 f0 |
| 359 | end |
| 360 | |
| 361 | fn main to int |
| 362 | put b_rng 0 ulong 0x4d412d4456312d42 |
| 363 | test_h1_bottom |
| 364 | test_rz_refuse_non_trits |
| 365 | test_packed_no_bottom |
| 366 | if eq get b_chk 1 0 |
| 367 | oma_put_str b_hdr_p |
| 368 | else |
| 369 | oma_put_str b_hdr_f |
| 370 | end |
| 371 | oma_put_u64 1 get b_chk 0 |
| 372 | oma_put_str b_chk_s |
| 373 | oma_put_u64 1 get b_chk 1 |
| 374 | oma_put_str b_rz_s |
| 375 | if eq get b_chk 1 0 |
| 376 | ret 0 |
| 377 | end |
| 378 | ret 1 |
| 379 | end |