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 / native / models / mxfp4.om

52 lines · 1405 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2note MXFP4 E2M1 nibble plus E8M0 block scale to exact IEEE binary32 bits.
3note gpt-oss reference: openai/gpt-oss gpt_oss/torch/weights.py FP4_VALUES,
4note low nibble precedes high nibble; scales are biased by 127.
5note Returns bits so the identical integer unit runs on native and irspirv.
6note Scalar primitive, not GEMM or an inference engine. No device access.
7note Refuse non-nibbles and reserved E8M0 255 (NaN block) with trap 5.
8note Finite overflow produces signed infinity; signed zero is preserved.
9note Wolfram: Table[If[m==0,0,If[m==1,2^-1,(1+Mod[m,2]/2)
10note 2^(Quotient[m,2]-1)]],{m,0,7}] == {0,1/2,1,3/2,2,3,4,6} -> True.
11note Wolfram: {2^23,2^22,2^31} -> {8388608,4194304,2147483648}.
12fn mxfp4bits nib uint scale uint to uint
13if gt nib 15
14trap 5
15end
16if gt scale 254
17trap 5
18end
19sign = shl and nib 8 28
20mag = and nib 7
21if eq mag 0
22ret sign
23end
24expo = sub long scale 1
25frac = uint 0
26if ge mag 2
27t = shr mag 1
28expo = add expo long t
29frac = shl and mag 1 22
30end
31if ge expo 255
32ret or sign uint 2139095040
33end
34if le expo 0
35sig = or frac uint 8388608
36d = sub long 1 expo
37sig = shr sig uint d
38ret or sign sig
39end
40ret or sign or shl uint expo 23 frac
41end
42fn mxfp4byte packed uint lane uint scale uint to uint
43if gt packed 255
44trap 5
45end
46if gt lane 1
47trap 5
48end
49nib = and shr packed mul lane 4 15
50value = mxfp4bits nib scale
51ret value
52end