interplane.Get Omega
Read in your language

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

branch main Branches Tags History

omega-mv / gpu / nvidia / om / api / apish_pack.om

81 lines · 1719 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2note FP8 e4m3 pack decisions. Bits in, bits out.
3note op 1 ref bits, 2 kernel bits, 3 nan, 4 scale fold, 5 x f32 fold, 6 x bf16 fold.
4note NaN is only exponent 15 and mantissa 7. Subnormals are the integer mantissa times 2^-9.
5note Scale fold is bf16 bits times 2^56, refused when the magnitude exceeds 3.0e38.
6note A refusal sets bit 32. A success returns the f32 bits.
7
8fn refb b uint to uint
9s = and b 128
10e = and shr b 3 15
11m = and b 7
12if and eq e 15 eq m 7
13ret 2143289344
14end
15if eq e 0
16z = mul f32 m bitcast f32 shl sub uint 127 9 23
17if ne s 0
18ret xor bitcast uint z shl uint 1 31
19end
20ret bitcast uint z
21end
22base = add bitcast f32 shl uint 127 23 div f32 m 8.0f32
23val = mul base bitcast f32 shl add uint 120 e 23
24if ne s 0
25ret xor bitcast uint val shl uint 1 31
26end
27ret bitcast uint val
28end
29
30fn kbits b uint to uint
31ret or shl and b 127 20 shl and b 128 24
32end
33
34fn isnanb b uint to uint
35if eq and b 127 127
36ret 1
37end
38ret 0
39end
40
41fn scalef b uint mut uint to ulong
42f = bitcast f32 shl b 16
43if not le fabs f 3.0e38f32
44ret shl ulong 1 32
45end
46fold = bitcast f32 shl add uint 127 56 23
47if ne mut 0
48fold = bitcast f32 shl uint 127 23
49end
50g = mul f fold
51if not le fabs g 3.0e38f32
52ret shl ulong 1 32
53end
54ret ulong bitcast uint g
55end
56
57fn xfold u uint exp uint to uint
58ret bitcast uint mul bitcast f32 u bitcast f32 shl add uint 127 exp 23
59end
60
61fn apishk op uint a uint b uint c uint d uint e uint to ulong
62if eq op 1
63ret ulong refb a
64end
65if eq op 2
66ret ulong kbits a
67end
68if eq op 3
69ret ulong isnanb a
70end
71if eq op 4
72ret scalef a b
73end
74if eq op 5
75ret ulong xfold a 64
76end
77if eq op 6
78ret ulong xfold bitcast uint bitcast f32 shl a 16 64
79end
80ret shl ulong 1 32
81end