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 / ref32-review / mul-corpus.om
| 1 | note SPDX-License-Identifier: AGPL-3.0-only |
| 2 | note Native IEEE binary32 multiplication represented as bits; no host floating runtime. |
| 3 | note Round-to-nearest ties-to-even, gradual underflow, signed zeros and infinities. |
| 4 | note Canonical positive quiet NaN for every NaN result. Inputs are low32 bits. |
| 5 | fn mround x ulong shift ulong to ulong |
| 6 | if eq shift 0 |
| 7 | ret x |
| 8 | end |
| 9 | if gt shift 63 |
| 10 | ret 0 |
| 11 | end |
| 12 | q = shr x shift |
| 13 | mask = sub shl 1 shift 1 |
| 14 | r = and x mask |
| 15 | half = shl 1 sub shift 1 |
| 16 | if or gt r half and eq r half ne and q 1 0 |
| 17 | q = add q 1 |
| 18 | end |
| 19 | ret q |
| 20 | end |
| 21 | fn mul32 aa ulong bb ulong to ulong |
| 22 | a = and aa 4294967295 |
| 23 | b = and bb 4294967295 |
| 24 | sign = and xor a b 2147483648 |
| 25 | ea = long and shr a 23 255 |
| 26 | eb = long and shr b 23 255 |
| 27 | ma = and a 8388607 |
| 28 | mb = and b 8388607 |
| 29 | if or and eq ea 255 ne ma 0 and eq eb 255 ne mb 0 |
| 30 | ret 2143289344 |
| 31 | end |
| 32 | if or eq ea 255 eq eb 255 |
| 33 | if or eq and a 2147483647 0 eq and b 2147483647 0 |
| 34 | ret 2143289344 |
| 35 | end |
| 36 | ret or sign 2139095040 |
| 37 | end |
| 38 | if or eq and a 2147483647 0 eq and b 2147483647 0 |
| 39 | ret sign |
| 40 | end |
| 41 | if eq ea 0 |
| 42 | ea = 1 |
| 43 | while lt ma 8388608 |
| 44 | ma = shl ma 1 |
| 45 | ea = sub ea 1 |
| 46 | end |
| 47 | else |
| 48 | ma = or ma 8388608 |
| 49 | end |
| 50 | if eq eb 0 |
| 51 | eb = 1 |
| 52 | while lt mb 8388608 |
| 53 | mb = shl mb 1 |
| 54 | eb = sub eb 1 |
| 55 | end |
| 56 | else |
| 57 | mb = or mb 8388608 |
| 58 | end |
| 59 | product = mul ma mb |
| 60 | e = sub add ea eb 127 |
| 61 | shift = long 23 |
| 62 | if ge product 140737488355328 |
| 63 | shift = 24 |
| 64 | e = add e 1 |
| 65 | end |
| 66 | if lt e 1 |
| 67 | shift = add shift sub 1 e |
| 68 | e = 0 |
| 69 | end |
| 70 | q = mround product ulong shift |
| 71 | if eq e 0 |
| 72 | if ge q 8388608 |
| 73 | e = 1 |
| 74 | end |
| 75 | else |
| 76 | if ge q 16777216 |
| 77 | q = shr q 1 |
| 78 | e = add e 1 |
| 79 | end |
| 80 | end |
| 81 | if ge e 255 |
| 82 | ret or sign 2139095040 |
| 83 | end |
| 84 | q = and q 8388607 |
| 85 | e = shl e 23 |
| 86 | q = or q ulong e |
| 87 | ret or sign q |
| 88 | end |
| 89 | note SPDX-License-Identifier: AGPL-3.0-only |
| 90 | global failed ulong 1 |
| 91 | global tested ulong 1 |
| 92 | global line uchar 48 |
| 93 | fn report ok bool to void |
| 94 | id = add get tested 0 1 |
| 95 | put tested 0 id |
| 96 | put line 0 48 |
| 97 | put line 1 uchar add 48 rem div id 100 10 |
| 98 | put line 2 uchar add 48 rem div id 10 10 |
| 99 | put line 3 uchar add 48 rem id 10 |
| 100 | put line 4 32 |
| 101 | put line 5 48 |
| 102 | if not ok |
| 103 | put line 5 49 |
| 104 | put failed 0 add get failed 0 1 |
| 105 | end |
| 106 | put line 6 10 |
| 107 | w = write 1 line 0 7 |
| 108 | if ne w 7 |
| 109 | exit 74 |
| 110 | end |
| 111 | end |
| 112 | note Native corpus runner. Each record is a,b,expected IEEE binary32 LE bits. |
| 113 | global record uchar 12 |
| 114 | fn mword p ulong to ulong |
| 115 | v = ulong 0 |
| 116 | for i ulong 4 |
| 117 | v = or v shl ulong get record add p i mul i 8 |
| 118 | end |
| 119 | ret v |
| 120 | end |
| 121 | fn main to int |
| 122 | while true |
| 123 | p = ulong 0 |
| 124 | while lt p 12 |
| 125 | n = read 0 record p sub 12 p |
| 126 | if eq n 0 |
| 127 | if ne p 0 |
| 128 | ret 74 |
| 129 | end |
| 130 | if ne get failed 0 0 |
| 131 | ret 1 |
| 132 | end |
| 133 | ret 0 |
| 134 | end |
| 135 | if eq n -4 |
| 136 | n = 0 |
| 137 | else |
| 138 | if lt n 0 |
| 139 | ret 74 |
| 140 | end |
| 141 | end |
| 142 | p = add p ulong n |
| 143 | end |
| 144 | a = mword 0 |
| 145 | b = mword 4 |
| 146 | wanted = mword 8 |
| 147 | report eq mul32 a b wanted |
| 148 | end |
| 149 | ret 0 |
| 150 | end |