aien-train
AIEN training programme: language-model history, GB10 constraints and the route to training on the project engine. Plans and runnable checks are distinguished.
Brought by drakestapleton
aien-train / evidence / ECOSYSTEM6 / frozen / unit.om
| 1 | note SPDX-License-Identifier: AGPL-3.0-only |
| 2 | note Native IEEE binary32 addition over bit patterns, RNE and gradual underflow. |
| 3 | note Canonical positive quiet NaN; no foreign floating runtime or compiler f32 type. |
| 4 | fn ajam x ulong n ulong to ulong |
| 5 | if eq n 0 |
| 6 | ret x |
| 7 | end |
| 8 | if ge n 64 |
| 9 | if ne x 0 |
| 10 | ret 1 |
| 11 | end |
| 12 | ret 0 |
| 13 | end |
| 14 | q = shr x n |
| 15 | mask = sub shl 1 n 1 |
| 16 | if ne and x mask 0 |
| 17 | q = or q 1 |
| 18 | end |
| 19 | ret q |
| 20 | end |
| 21 | fn add32 aa ulong bb ulong to ulong |
| 22 | a = and aa 4294967295 |
| 23 | b = and bb 4294967295 |
| 24 | if or gt and a 2147483647 2139095040 gt and b 2147483647 2139095040 |
| 25 | ret 2143289344 |
| 26 | end |
| 27 | if lt and a 2147483647 and b 2147483647 |
| 28 | t = a |
| 29 | a = b |
| 30 | b = t |
| 31 | end |
| 32 | if eq and a 2147483647 2139095040 |
| 33 | if and eq and b 2147483647 2139095040 ne and xor a b 2147483648 0 |
| 34 | ret 2143289344 |
| 35 | end |
| 36 | ret a |
| 37 | end |
| 38 | if eq and b 2147483647 0 |
| 39 | if eq and a 2147483647 0 |
| 40 | ret and and a b 2147483648 |
| 41 | end |
| 42 | ret a |
| 43 | end |
| 44 | sign = and a 2147483648 |
| 45 | ea = and shr a 23 255 |
| 46 | eb = and shr b 23 255 |
| 47 | ma = and a 8388607 |
| 48 | mb = and b 8388607 |
| 49 | if eq ea 0 |
| 50 | ea = 1 |
| 51 | else |
| 52 | ma = or ma 8388608 |
| 53 | end |
| 54 | if eq eb 0 |
| 55 | eb = 1 |
| 56 | else |
| 57 | mb = or mb 8388608 |
| 58 | end |
| 59 | ma = shl ma 3 |
| 60 | mb = shl mb 3 |
| 61 | mb = ajam mb sub ea eb |
| 62 | if eq and xor a b 2147483648 0 |
| 63 | ma = add ma mb |
| 64 | if ge ma 134217728 |
| 65 | ma = ajam ma 1 |
| 66 | ea = add ea 1 |
| 67 | end |
| 68 | else |
| 69 | ma = sub ma mb |
| 70 | if eq ma 0 |
| 71 | ret 0 |
| 72 | end |
| 73 | while and lt ma 67108864 gt ea 1 |
| 74 | ma = shl ma 1 |
| 75 | ea = sub ea 1 |
| 76 | end |
| 77 | end |
| 78 | q = shr ma 3 |
| 79 | r = and ma 7 |
| 80 | if gt r 4 |
| 81 | q = add q 1 |
| 82 | else |
| 83 | if eq r 4 |
| 84 | if ne and q 1 0 |
| 85 | q = add q 1 |
| 86 | end |
| 87 | end |
| 88 | end |
| 89 | if ge q 16777216 |
| 90 | q = shr q 1 |
| 91 | ea = add ea 1 |
| 92 | end |
| 93 | if ge ea 255 |
| 94 | ret or sign 2139095040 |
| 95 | end |
| 96 | if lt q 8388608 |
| 97 | ea = 0 |
| 98 | end |
| 99 | q = and q 8388607 |
| 100 | ea = shl ea 23 |
| 101 | q = or q ea |
| 102 | ret or sign q |
| 103 | end |
| 104 | note SPDX-License-Identifier: AGPL-3.0-only |
| 105 | note Native IEEE binary32 multiplication represented as bits; no host floating runtime. |
| 106 | note Round-to-nearest ties-to-even, gradual underflow, signed zeros and infinities. |
| 107 | note Canonical positive quiet NaN for every NaN result. Inputs are low32 bits. |
| 108 | fn mround x ulong shift ulong to ulong |
| 109 | if eq shift 0 |
| 110 | ret x |
| 111 | end |
| 112 | if gt shift 63 |
| 113 | ret 0 |
| 114 | end |
| 115 | q = shr x shift |
| 116 | mask = sub shl 1 shift 1 |
| 117 | r = and x mask |
| 118 | half = shl 1 sub shift 1 |
| 119 | if or gt r half and eq r half ne and q 1 0 |
| 120 | q = add q 1 |
| 121 | end |
| 122 | ret q |
| 123 | end |
| 124 | fn mul32 aa ulong bb ulong to ulong |
| 125 | a = and aa 4294967295 |
| 126 | b = and bb 4294967295 |
| 127 | sign = and xor a b 2147483648 |
| 128 | ea = long and shr a 23 255 |
| 129 | eb = long and shr b 23 255 |
| 130 | ma = and a 8388607 |
| 131 | mb = and b 8388607 |
| 132 | if or and eq ea 255 ne ma 0 and eq eb 255 ne mb 0 |
| 133 | ret 2143289344 |
| 134 | end |
| 135 | if or eq ea 255 eq eb 255 |
| 136 | if or eq and a 2147483647 0 eq and b 2147483647 0 |
| 137 | ret 2143289344 |
| 138 | end |
| 139 | ret or sign 2139095040 |
| 140 | end |
| 141 | if or eq and a 2147483647 0 eq and b 2147483647 0 |
| 142 | ret sign |
| 143 | end |
| 144 | if eq ea 0 |
| 145 | ea = 1 |
| 146 | while lt ma 8388608 |
| 147 | ma = shl ma 1 |
| 148 | ea = sub ea 1 |
| 149 | end |
| 150 | else |
| 151 | ma = or ma 8388608 |
| 152 | end |
| 153 | if eq eb 0 |
| 154 | eb = 1 |
| 155 | while lt mb 8388608 |
| 156 | mb = shl mb 1 |
| 157 | eb = sub eb 1 |
| 158 | end |
| 159 | else |
| 160 | mb = or mb 8388608 |
| 161 | end |
| 162 | product = mul ma mb |
| 163 | e = sub add ea eb 127 |
| 164 | shift = long 23 |
| 165 | if ge product 140737488355328 |
| 166 | shift = 24 |
| 167 | e = add e 1 |
| 168 | end |
| 169 | if lt e 1 |
| 170 | shift = add shift sub 1 e |
| 171 | e = 0 |
| 172 | end |
| 173 | q = mround product ulong shift |
| 174 | if eq e 0 |
| 175 | if ge q 8388608 |
| 176 | e = 1 |
| 177 | end |
| 178 | else |
| 179 | if ge q 16777216 |
| 180 | q = shr q 1 |
| 181 | e = add e 1 |
| 182 | end |
| 183 | end |
| 184 | if ge e 255 |
| 185 | ret or sign 2139095040 |
| 186 | end |
| 187 | q = and q 8388607 |
| 188 | e = shl e 23 |
| 189 | q = or q ulong e |
| 190 | ret or sign q |
| 191 | end |
| 192 | note M20 metadata-v1. Integer metadata only; no allocator or numeric execution. |
| 193 | note ED: schema,dtype,rank,elements,offset,slot,generation,reserved,shape8,stride8. |
| 194 | note ES: live,retired,slot,generation,dtype,elements,reserved,reserved. |
| 195 | note ES is the caller-owned allocator snapshot. It is not untrusted wire input. |
| 196 | global ED ulong 24 |
| 197 | global ES ulong 8 |
| 198 | |
| 199 | fn emshape to int |
| 200 | rank = get ED 2 |
| 201 | if gt rank 8 |
| 202 | ret -2 |
| 203 | end |
| 204 | n = ulong 1 |
| 205 | for d ulong rank |
| 206 | size = get ED add 8 d |
| 207 | if eq size 0 |
| 208 | ret -3 |
| 209 | end |
| 210 | if gt size div 1073741824 n |
| 211 | ret -8 |
| 212 | end |
| 213 | n = mul n size |
| 214 | end |
| 215 | if ne get ED 3 n |
| 216 | ret -3 |
| 217 | end |
| 218 | ret 0 |
| 219 | end |
| 220 | |
| 221 | fn emlive slot ulong gen ulong to int |
| 222 | if gt slot 4294967295 |
| 223 | ret -5 |
| 224 | end |
| 225 | if or ne get ES 0 1 ne get ES 1 0 |
| 226 | ret -5 |
| 227 | end |
| 228 | if or eq gen 0 ne slot get ES 2 |
| 229 | ret -5 |
| 230 | end |
| 231 | if ne gen get ES 3 |
| 232 | ret -5 |
| 233 | end |
| 234 | ret 0 |
| 235 | end |
| 236 | |
| 237 | fn embounds to int |
| 238 | size = get ES 5 |
| 239 | offset = get ED 4 |
| 240 | if or eq size 0 gt size 1073741824 |
| 241 | ret -8 |
| 242 | end |
| 243 | if ge offset size |
| 244 | ret -6 |
| 245 | end |
| 246 | note Compare against remaining extent before multiplication, never overflow. |
| 247 | room = sub sub size 1 offset |
| 248 | for d ulong get ED 2 |
| 249 | count = sub get ED add 8 d 1 |
| 250 | stride = get ED add 16 d |
| 251 | if ne stride 0 |
| 252 | if gt count div room stride |
| 253 | ret -6 |
| 254 | end |
| 255 | room = sub room mul count stride |
| 256 | end |
| 257 | end |
| 258 | ret 0 |
| 259 | end |
| 260 | |
| 261 | fn emcheck to int |
| 262 | if or ne get ED 0 1 ne get ED 7 0 |
| 263 | ret -1 |
| 264 | end |
| 265 | if or ne get ES 6 0 ne get ES 7 0 |
| 266 | ret -1 |
| 267 | end |
| 268 | dtype = get ED 1 |
| 269 | if or lt dtype 1 gt dtype 3 |
| 270 | ret -4 |
| 271 | end |
| 272 | status = emshape |
| 273 | if ne status 0 |
| 274 | ret status |
| 275 | end |
| 276 | status = emlive get ED 5 get ED 6 |
| 277 | if ne status 0 |
| 278 | ret status |
| 279 | end |
| 280 | if ne dtype get ES 4 |
| 281 | ret -4 |
| 282 | end |
| 283 | ret embounds |
| 284 | end |
| 285 | |
| 286 | fn emrelease slot ulong gen ulong to int |
| 287 | status = emlive slot gen |
| 288 | if ne status 0 |
| 289 | ret status |
| 290 | end |
| 291 | note A maximal generation is retired, never wrapped into a valid old handle. |
| 292 | if eq gen 18446744073709551615 |
| 293 | put ES 1 1 |
| 294 | else |
| 295 | put ES 3 add gen 1 |
| 296 | end |
| 297 | put ES 0 0 |
| 298 | ret 0 |
| 299 | end |
| 300 | note SPDX-License-Identifier: AGPL-3.0-only |
| 301 | note Bounded host FP32 consumer. Uses external pinned L720 add32/mul32 and M20 emcheck. |
| 302 | note Eight independent tensors X,W,b,T,Y,dX,dW,db in 16-cell slots. |
| 303 | note Values are IEEE binary32 bits in ulong carriers, not integer fixed-point values. |
| 304 | note AD/AS are trusted local descriptor and allocator snapshots, not wire records. |
| 305 | global AD ulong 192 |
| 306 | global AS ulong 64 |
| 307 | global AP ulong 128 |
| 308 | global AQ ulong 128 |
| 309 | global AL ulong 1 |
| 310 | |
| 311 | fn afcount t ulong to ulong |
| 312 | if or eq t 2 eq t 7 |
| 313 | ret 2 |
| 314 | end |
| 315 | if or eq t 3 eq t 4 |
| 316 | ret 4 |
| 317 | end |
| 318 | ret 6 |
| 319 | end |
| 320 | |
| 321 | fn afget t ulong i ulong to ulong |
| 322 | ret get AP add mul t 16 i |
| 323 | end |
| 324 | |
| 325 | fn afq t ulong i ulong to ulong |
| 326 | ret get AQ add mul t 16 i |
| 327 | end |
| 328 | |
| 329 | fn afput t ulong i ulong v ulong to void |
| 330 | put AQ add mul t 16 i v |
| 331 | end |
| 332 | |
| 333 | fn affinite x ulong to bool |
| 334 | if gt x 4294967295 |
| 335 | ret false |
| 336 | end |
| 337 | ret lt and x 2147483647 2139095040 |
| 338 | end |
| 339 | |
| 340 | fn afvalidate to int |
| 341 | for t ulong 8 |
| 342 | for i ulong 24 |
| 343 | put ED i get AD add mul t 24 i |
| 344 | end |
| 345 | for i ulong 8 |
| 346 | put ES i get AS add mul t 8 i |
| 347 | end |
| 348 | status = emcheck |
| 349 | if ne status 0 |
| 350 | ret status |
| 351 | end |
| 352 | note Contiguous owned local carriers only. This does not claim strided numeric kernels. |
| 353 | if or ne get ED 1 1 ne get ED 4 0 |
| 354 | ret -20 |
| 355 | end |
| 356 | if or ne get ED 5 add t 1 ne get ES 5 afcount t |
| 357 | ret -20 |
| 358 | end |
| 359 | rank = ulong 2 |
| 360 | rows = ulong 2 |
| 361 | cols = ulong 3 |
| 362 | if or eq t 1 eq t 6 |
| 363 | rows = 3 |
| 364 | cols = 2 |
| 365 | end |
| 366 | if or eq t 3 eq t 4 |
| 367 | cols = 2 |
| 368 | end |
| 369 | if or eq t 2 eq t 7 |
| 370 | rank = 1 |
| 371 | cols = 1 |
| 372 | end |
| 373 | if or ne get ED 2 rank ne get ED 8 rows |
| 374 | ret -21 |
| 375 | end |
| 376 | if ne get ED 16 cols |
| 377 | ret -21 |
| 378 | end |
| 379 | if eq rank 2 |
| 380 | if or ne get ED 9 cols ne get ED 17 1 |
| 381 | ret -21 |
| 382 | end |
| 383 | end |
| 384 | end |
| 385 | ret 0 |
| 386 | end |
| 387 | |
| 388 | fn afstep lr ulong to int |
| 389 | status = afvalidate |
| 390 | if ne status 0 |
| 391 | ret status |
| 392 | end |
| 393 | if not affinite lr |
| 394 | ret -22 |
| 395 | end |
| 396 | if ne and lr 2147483648 0 |
| 397 | ret -22 |
| 398 | end |
| 399 | for t ulong 4 |
| 400 | for i ulong afcount t |
| 401 | if not affinite afget t i |
| 402 | ret -22 |
| 403 | end |
| 404 | end |
| 405 | end |
| 406 | for i ulong 128 |
| 407 | put AQ i 0 |
| 408 | end |
| 409 | loss = ulong 0 |
| 410 | for row ulong 2 |
| 411 | for col ulong 2 |
| 412 | v = afget 2 col |
| 413 | for k ulong 3 |
| 414 | x = afget 0 add mul row 3 k |
| 415 | w = afget 1 add mul k 2 col |
| 416 | v = add32 v mul32 x w |
| 417 | end |
| 418 | pos = add mul row 2 col |
| 419 | afput 4 pos v |
| 420 | r = add32 v xor afget 3 pos 2147483648 |
| 421 | loss = add32 loss mul32 r r |
| 422 | g = mul32 1073741824 r |
| 423 | afput 7 col add32 afq 7 col g |
| 424 | for k ulong 3 |
| 425 | xp = add mul row 3 k |
| 426 | wp = add mul k 2 col |
| 427 | gx = mul32 g afget 1 wp |
| 428 | gw = mul32 g afget 0 xp |
| 429 | afput 5 xp add32 afq 5 xp gx |
| 430 | afput 6 wp add32 afq 6 wp gw |
| 431 | end |
| 432 | end |
| 433 | end |
| 434 | note Commit only after all finite-result checks; rejected steps preserve AP and AL. |
| 435 | for i ulong 6 |
| 436 | delta = mul32 lr afq 6 i |
| 437 | afput 1 i add32 afget 1 i xor delta 2147483648 |
| 438 | end |
| 439 | for i ulong 2 |
| 440 | delta = mul32 lr afq 7 i |
| 441 | afput 2 i add32 afget 2 i xor delta 2147483648 |
| 442 | end |
| 443 | if not affinite loss |
| 444 | ret -23 |
| 445 | end |
| 446 | for t ulong 8 |
| 447 | if and ne t 0 ne t 3 |
| 448 | for i ulong afcount t |
| 449 | if not affinite afq t i |
| 450 | ret -23 |
| 451 | end |
| 452 | end |
| 453 | end |
| 454 | end |
| 455 | for t ulong 8 |
| 456 | if and ne t 0 ne t 3 |
| 457 | for i ulong afcount t |
| 458 | put AP add mul t 16 i afq t i |
| 459 | end |
| 460 | end |
| 461 | end |
| 462 | put AL 0 loss |
| 463 | ret 0 |
| 464 | end |
| 465 | note SPDX-License-Identifier: AGPL-3.0-only |
| 466 | note Independent exact rational oracle: X/8,W/16,b/128,T/128,learning rate1/32. |
| 467 | note Only the test oracle uses integer rationals. Production calls IEEE add32/mul32. |
| 468 | global C ulong 1 |
| 469 | global D uchar 24 |
| 470 | global RI long 18 |
| 471 | global RR long 4 |
| 472 | global SAV ulong 129 |
| 473 | global RNG ulong 1 |
| 474 | text PASS "NATIVE_AFFINE_FP32_PASS checks=" |
| 475 | text FAIL "NATIVE_AFFINE_FP32_FAIL check=" |
| 476 | text NL "\n" |
| 477 | |
| 478 | fn number n ulong to void |
| 479 | if eq n 0 |
| 480 | put D 0 48 |
| 481 | w = write 1 D 0 1 |
| 482 | if ne w 1 |
| 483 | exit 90 |
| 484 | end |
| 485 | ret |
| 486 | end |
| 487 | p = ulong 24 |
| 488 | while gt n 0 bound 24 |
| 489 | p = sub p 1 |
| 490 | put D p uchar add 48 rem n 10 |
| 491 | n = div n 10 |
| 492 | end |
| 493 | w = write 1 D p sub 24 p |
| 494 | if ne w long sub 24 p |
| 495 | exit 90 |
| 496 | end |
| 497 | end |
| 498 | |
| 499 | fn check ok bool to void |
| 500 | put C 0 add get C 0 1 |
| 501 | if not ok |
| 502 | w = write 1 FAIL 0 len FAIL |
| 503 | number get C 0 |
| 504 | w = write 1 NL 0 1 |
| 505 | exit 1 |
| 506 | end |
| 507 | end |
| 508 | |
| 509 | fn bits value long scale ulong to ulong |
| 510 | note Exact binary32 encoding of small dyadic test numbers; no production primitive. |
| 511 | if eq value 0 |
| 512 | ret 0 |
| 513 | end |
| 514 | sign = ulong 0 |
| 515 | if lt value 0 |
| 516 | sign = 2147483648 |
| 517 | value = neg value |
| 518 | end |
| 519 | n = ulong value |
| 520 | power = ulong 0 |
| 521 | q = n |
| 522 | while gt q 1 bound 24 |
| 523 | q = shr q 1 |
| 524 | power = add power 1 |
| 525 | end |
| 526 | check le power 23 |
| 527 | mantissa = sub shl n sub 23 power 8388608 |
| 528 | exponent = sub add power 127 scale |
| 529 | ret or sign or shl exponent 23 mantissa |
| 530 | end |
| 531 | |
| 532 | fn fixture to void |
| 533 | for i ulong 192 |
| 534 | put AD i 0 |
| 535 | end |
| 536 | for i ulong 64 |
| 537 | put AS i 0 |
| 538 | end |
| 539 | for i ulong 128 |
| 540 | put AP i 0 |
| 541 | end |
| 542 | put AL 0 0 |
| 543 | for t ulong 8 |
| 544 | rank = ulong 2 |
| 545 | rows = ulong 2 |
| 546 | cols = ulong 3 |
| 547 | count = ulong 6 |
| 548 | if or eq t 1 eq t 6 |
| 549 | rows = 3 |
| 550 | cols = 2 |
| 551 | end |
| 552 | if or eq t 3 eq t 4 |
| 553 | cols = 2 |
| 554 | count = 4 |
| 555 | end |
| 556 | if or eq t 2 eq t 7 |
| 557 | rank = 1 |
| 558 | cols = 1 |
| 559 | count = 2 |
| 560 | end |
| 561 | p = mul t 24 |
| 562 | put AD p 1 |
| 563 | put AD add p 1 1 |
| 564 | put AD add p 2 rank |
| 565 | put AD add p 3 count |
| 566 | put AD add p 5 add t 1 |
| 567 | put AD add p 6 17 |
| 568 | put AD add p 8 rows |
| 569 | put AD add p 16 cols |
| 570 | if eq rank 2 |
| 571 | put AD add p 9 cols |
| 572 | put AD add p 17 1 |
| 573 | end |
| 574 | p = mul t 8 |
| 575 | put AS p 1 |
| 576 | put AS add p 2 add t 1 |
| 577 | put AS add p 3 17 |
| 578 | put AS add p 4 1 |
| 579 | put AS add p 5 count |
| 580 | end |
| 581 | end |
| 582 | |
| 583 | fn save to void |
| 584 | for i ulong 128 |
| 585 | put SAV i get AP i |
| 586 | end |
| 587 | put SAV 128 get AL 0 |
| 588 | end |
| 589 | |
| 590 | fn unchanged to void |
| 591 | for i ulong 128 |
| 592 | check eq get SAV i get AP i |
| 593 | end |
| 594 | check eq get SAV 128 get AL 0 |
| 595 | end |
| 596 | |
| 597 | fn loadinputs to void |
| 598 | for i ulong 6 |
| 599 | put AP i bits get RI i 3 |
| 600 | put AP add 16 i bits get RI add 6 i 4 |
| 601 | end |
| 602 | for i ulong 2 |
| 603 | put AP add 32 i bits get RI add 12 i 7 |
| 604 | end |
| 605 | for i ulong 4 |
| 606 | put AP add 48 i bits get RI add 14 i 7 |
| 607 | end |
| 608 | end |
| 609 | |
| 610 | fn oracle to void |
| 611 | loss = long 0 |
| 612 | for row ulong 2 |
| 613 | for col ulong 2 |
| 614 | pos = add mul row 2 col |
| 615 | y = get RI add 12 col |
| 616 | for k ulong 3 |
| 617 | x = get RI add mul row 3 k |
| 618 | w = get RI add 6 add mul k 2 col |
| 619 | y = add y mul x w |
| 620 | end |
| 621 | check eq afget 4 pos bits y 7 |
| 622 | r = sub y get RI add 14 pos |
| 623 | put RR pos r |
| 624 | loss = add loss mul r r |
| 625 | end |
| 626 | end |
| 627 | check eq get AL 0 bits loss 14 |
| 628 | for k ulong 3 |
| 629 | for col ulong 2 |
| 630 | g = long 0 |
| 631 | for row ulong 2 |
| 632 | r = get RR add mul row 2 col |
| 633 | x = get RI add mul row 3 k |
| 634 | g = add g mul r x |
| 635 | end |
| 636 | pos = add mul k 2 col |
| 637 | check eq afget 6 pos bits g 9 |
| 638 | updated = sub mul get RI add 6 pos 1024 g |
| 639 | check eq afget 1 pos bits updated 14 |
| 640 | end |
| 641 | end |
| 642 | for col ulong 2 |
| 643 | g = add get RR col get RR add 2 col |
| 644 | check eq afget 7 col bits g 6 |
| 645 | updated = sub mul get RI add 12 col 16 g |
| 646 | check eq afget 2 col bits updated 11 |
| 647 | end |
| 648 | for row ulong 2 |
| 649 | for k ulong 3 |
| 650 | g = long 0 |
| 651 | for col ulong 2 |
| 652 | r = get RR add mul row 2 col |
| 653 | w = get RI add 6 add mul k 2 col |
| 654 | g = add g mul r w |
| 655 | end |
| 656 | pos = add mul row 3 k |
| 657 | check eq afget 5 pos bits g 10 |
| 658 | end |
| 659 | end |
| 660 | note Inputs and targets remain byte-identical after a successful step. |
| 661 | for i ulong 6 |
| 662 | check eq afget 0 i bits get RI i 3 |
| 663 | end |
| 664 | for i ulong 4 |
| 665 | check eq afget 3 i bits get RI add 14 i 7 |
| 666 | end |
| 667 | end |
| 668 | |
| 669 | fn direct to void |
| 670 | fixture |
| 671 | check eq afvalidate 0 |
| 672 | note X rows(1,-2,3),(2,0,-1); W(.5,-.25),(1,.75),(-.5,2). |
| 673 | put RI 0 8 |
| 674 | put RI 1 -16 |
| 675 | put RI 2 24 |
| 676 | put RI 3 16 |
| 677 | put RI 4 0 |
| 678 | put RI 5 -8 |
| 679 | put RI 6 8 |
| 680 | put RI 7 -4 |
| 681 | put RI 8 16 |
| 682 | put RI 9 12 |
| 683 | put RI 10 -8 |
| 684 | put RI 11 32 |
| 685 | put RI 12 16 |
| 686 | put RI 13 -64 |
| 687 | put RI 14 32 |
| 688 | put RI 15 128 |
| 689 | put RI 16 -128 |
| 690 | put RI 17 64 |
| 691 | loadinputs |
| 692 | check eq afstep 1023410176 0 |
| 693 | oracle |
| 694 | note Independently hand-calculated loss36.46875, not merely decreasing loss. |
| 695 | check eq get AL 0 1108467712 |
| 696 | end |
| 697 | |
| 698 | fn refusals to void |
| 699 | fixture |
| 700 | put AD 32 2 |
| 701 | put AD 33 3 |
| 702 | put AD 40 3 |
| 703 | save |
| 704 | check eq afstep 1023410176 -21 |
| 705 | unchanged |
| 706 | fixture |
| 707 | put AS 11 18 |
| 708 | save |
| 709 | check eq afstep 1023410176 -5 |
| 710 | unchanged |
| 711 | fixture |
| 712 | put AD 29 1 |
| 713 | put AS 10 1 |
| 714 | save |
| 715 | check eq afstep 1023410176 -20 |
| 716 | unchanged |
| 717 | fixture |
| 718 | put AP 0 2139095040 |
| 719 | save |
| 720 | check eq afstep 1023410176 -22 |
| 721 | unchanged |
| 722 | fixture |
| 723 | put AP 0 2143289344 |
| 724 | save |
| 725 | check eq afstep 1023410176 -22 |
| 726 | unchanged |
| 727 | fixture |
| 728 | put AP 0 4294967296 |
| 729 | save |
| 730 | check eq afstep 1023410176 -22 |
| 731 | unchanged |
| 732 | fixture |
| 733 | save |
| 734 | check eq afstep 3170893824 -22 |
| 735 | unchanged |
| 736 | fixture |
| 737 | put AP 0 2139095039 |
| 738 | put AP 16 1073741824 |
| 739 | save |
| 740 | check eq afstep 1023410176 -23 |
| 741 | unchanged |
| 742 | end |
| 743 | |
| 744 | fn next to long |
| 745 | n = add mul get RNG 0 1664525 1013904223 |
| 746 | n = and n 4294967295 |
| 747 | put RNG 0 n |
| 748 | ret sub long rem shr n 12 17 8 |
| 749 | end |
| 750 | |
| 751 | fn rounding to void |
| 752 | note Smallest subnormal through actual forward and input derivative, loss underflows. |
| 753 | fixture |
| 754 | put AP 0 1 |
| 755 | put AP 16 1065353216 |
| 756 | check eq afstep 0 0 |
| 757 | check eq afget 4 0 1 |
| 758 | check eq afget 5 0 2 |
| 759 | check eq afget 6 0 0 |
| 760 | check eq afget 7 0 2 |
| 761 | check eq get AL 0 0 |
| 762 | note Half a subnormal rounds to even zero. |
| 763 | fixture |
| 764 | put AP 0 1 |
| 765 | put AP 16 1056964608 |
| 766 | check eq afstep 0 0 |
| 767 | check eq afget 4 0 0 |
| 768 | note 1 + 2^-24 rounds to even1; 1 + 3*2^-24 rounds upward two ulps. |
| 769 | fixture |
| 770 | put AP 0 1065353216 |
| 771 | put AP 16 1065353216 |
| 772 | put AP 32 864026624 |
| 773 | check eq afstep 0 0 |
| 774 | check eq afget 4 0 1065353216 |
| 775 | check eq afget 1 0 1065353216 |
| 776 | fixture |
| 777 | put AP 0 1065353216 |
| 778 | put AP 16 1065353216 |
| 779 | put AP 32 876609536 |
| 780 | check eq afstep 0 0 |
| 781 | check eq afget 4 0 1065353218 |
| 782 | end |
| 783 | |
| 784 | fn corpus to void |
| 785 | put RNG 0 303660 |
| 786 | for trial ulong 4096 |
| 787 | fixture |
| 788 | for i ulong 18 |
| 789 | put RI i next |
| 790 | end |
| 791 | loadinputs |
| 792 | check eq afstep 1023410176 0 |
| 793 | oracle |
| 794 | end |
| 795 | end |
| 796 | |
| 797 | fn main to int |
| 798 | direct |
| 799 | refusals |
| 800 | rounding |
| 801 | corpus |
| 802 | w = write 1 PASS 0 len PASS |
| 803 | number get C 0 |
| 804 | w = write 1 NL 0 1 |
| 805 | if ne w 1 |
| 806 | ret 90 |
| 807 | end |
| 808 | ret 0 |
| 809 | end |