interplane.Get Omega
Read in your language

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

branch main Branches Tags History

aien-train / evidence / ECOSYSTEM6 / ref32-review / mul-focused.om

134 lines · 2896 bytes Raw Blame History
1note SPDX-License-Identifier: AGPL-3.0-only
2note Native IEEE binary32 multiplication represented as bits; no host floating runtime.
3note Round-to-nearest ties-to-even, gradual underflow, signed zeros and infinities.
4note Canonical positive quiet NaN for every NaN result. Inputs are low32 bits.
5fn mround x ulong shift ulong to ulong
6if eq shift 0
7ret x
8end
9if gt shift 63
10ret 0
11end
12q = shr x shift
13mask = sub shl 1 shift 1
14r = and x mask
15half = shl 1 sub shift 1
16if or gt r half and eq r half ne and q 1 0
17q = add q 1
18end
19ret q
20end
21fn mul32 aa ulong bb ulong to ulong
22a = and aa 4294967295
23b = and bb 4294967295
24sign = and xor a b 2147483648
25ea = long and shr a 23 255
26eb = long and shr b 23 255
27ma = and a 8388607
28mb = and b 8388607
29if or and eq ea 255 ne ma 0 and eq eb 255 ne mb 0
30ret 2143289344
31end
32if or eq ea 255 eq eb 255
33if or eq and a 2147483647 0 eq and b 2147483647 0
34ret 2143289344
35end
36ret or sign 2139095040
37end
38if or eq and a 2147483647 0 eq and b 2147483647 0
39ret sign
40end
41if eq ea 0
42ea = 1
43while lt ma 8388608
44ma = shl ma 1
45ea = sub ea 1
46end
47else
48ma = or ma 8388608
49end
50if eq eb 0
51eb = 1
52while lt mb 8388608
53mb = shl mb 1
54eb = sub eb 1
55end
56else
57mb = or mb 8388608
58end
59product = mul ma mb
60e = sub add ea eb 127
61shift = long 23
62if ge product 140737488355328
63shift = 24
64e = add e 1
65end
66if lt e 1
67shift = add shift sub 1 e
68e = 0
69end
70q = mround product ulong shift
71if eq e 0
72if ge q 8388608
73e = 1
74end
75else
76if ge q 16777216
77q = shr q 1
78e = add e 1
79end
80end
81if ge e 255
82ret or sign 2139095040
83end
84q = and q 8388607
85e = shl e 23
86q = or q ulong e
87ret or sign q
88end
89note SPDX-License-Identifier: AGPL-3.0-only
90global failed ulong 1
91global tested ulong 1
92global line uchar 48
93fn report ok bool to void
94id = add get tested 0 1
95put tested 0 id
96put line 0 48
97put line 1 uchar add 48 rem div id 100 10
98put line 2 uchar add 48 rem div id 10 10
99put line 3 uchar add 48 rem id 10
100put line 4 32
101put line 5 48
102if not ok
103put line 5 49
104put failed 0 add get failed 0 1
105end
106put line 6 10
107w = write 1 line 0 7
108if ne w 7
109exit 74
110end
111end
112note Binary32 multiply RNE. Expected bits independently checked with IEEE host oracle.
113note All NaNs canonicalized to positive quiet NaN; gradual underflow; signed zero.
114fn main to int
115report eq mul32 1065353216 1073741824 1073741824
116report eq mul32 3212836864 1073741824 3221225472
117report eq mul32 0 3212836864 2147483648
118report eq mul32 2147483648 3212836864 0
119report eq mul32 2139095040 0 2143289344
120report eq mul32 2139095040 3212836864 4286578688
121report eq mul32 2143289345 1065353216 2143289344
122report eq mul32 1 1065353216 1
123report eq mul32 8388608 1056964608 4194304
124report eq mul32 8388607 1073741824 16777214
125report eq mul32 2139095039 1073741824 2139095040
126report eq mul32 1069547520 1069547520 1074790400
127report eq mul32 1065353217 1065353217 1065353218
128report eq mul32 1 1056964608 0
129report eq mul32 3 1056964608 2
130if ne get failed 0 0
131ret 1
132end
133ret 0
134end