code wiki / (root) / nx_f32.nx

nx_f32.nx

buildroot/runtime/nx_f32.nx

20241 B628 linesdepth 2pulls 2 transitivereach 314 importersview sourcekind librarytopic f32
docsdependenciesstructsconstsfunctions

about

nx_f32.nx -- IEEE 754 binary32 (single-precision float) bits-up. L4 of the bits-up numeric tower (see docs/NISHI_BITS_UP_NUMERIC_TOWER_ROADMAP.md). Substrate-side IEEE 754 conformant f32 arithmetic on i64 backend. No libm, no soft-float linker stubs, no compiler-builtin lowerings. Bit layout (IEEE 754-2019): bit 31: sign (1 = negative) bits 30..23: exponent (biased by 127; 0 = subnormal/zero; 255 = inf/NaN) bits 22..0: mantissa (23 bits; implicit leading 1 for normal) Real value = (-1)^sign * 2^(exp - 127) * (1.mantissa) for normal = (-1)^sign * 2^-126 * (0.mantissa) for subnormal Storage convention: an f32 value is stored in the LOW 32 bits of an i64. Pack/unpack helpers enforce zero high bits. This brick ships multiplication first because it is THE load-bearing op for matmul (which is THE load-bearing op for ML inference). Add/sub/div/sqrt land in follow-on bricks (L4 v2-v5). Operations in v1: nx_f32_classify(x) -- NX_F32_CLS_* (zero / normal / subnormal / inf / nan) nx_f32_is_nan(x) nx_f32_is_inf(x) nx_f32_is_zero(x) nx_f32_neg(x) nx_f32_abs(x) nx_f32_eq(a, b) -- IEEE 754 equality (NaN != NaN) nx_f32_mul(a, b) -- IEEE 754 multiply, round-to-nearest-even nx_f32_add(a, b) -- IEEE 754 addition, round-to-nearest-even with guard/round/sticky alignment + cancellation nx_f32_sub(a, b) -- a + (-b) Reference (research absorbed bits-up; no code copied): IEEE 754-2019 standard Goldberg 1991 "What Every Computer Scientist Should Know..." Müller 2018 "Handbook of Floating-Point Arithmetic"

dependencies 2 imports · 225 importers

nx_syscalls.nx nx_tier.nx nx_f32.nx _autograd_authored.nx _tensor_grad_authored.nx nx_autograd.nx nx_autograd_tensor.nx nx_batched_gate.nx nx_batched_tput.nx nx_bigread_test.nx nx_chat_warmcache.nx nx_coco_oks.nx nx_coder_gen_f32.nx

diagram shows first 10 each side; +0 more imports, +215 more importers in the complete lists below.

imports: nx_syscalls.nxnx_tier.nx

imported by: _autograd_authored.nx_tensor_grad_authored.nxnx_autograd.nxnx_autograd_tensor.nxnx_batched_gate.nxnx_batched_tput.nxnx_bigread_test.nxnx_chat_warmcache.nxnx_coco_oks.nxnx_coder_gen_f32.nxnx_companion_chat.nxnx_companion_voice.nxnx_conv1d.nxnx_conv_transpose1d.nxnx_embed_bench.nxnx_embed_train.nxnx_exp_ab.nxnx_exploop_test.nxnx_f32_activations.nxnx_f32_activations_test.nxnx_f32_adaln.nxnx_f32_attention.nxnx_f32_attn_cached.nxnx_f32_attn_cached_test.nxnx_f32_attn_multi.nxnx_f32_attn_multi_test.nxnx_f32_bn_fold.nxnx_f32_bn_fold_gate.nxnx_f32_conv2d.nxnx_f32_conv2d_backward.nxnx_f32_conv2d_backward_fast.nxnx_f32_conv2d_fast.nxnx_f32_conv2d_grouped.nxnx_f32_conv_train_gate.nxnx_f32_conv_transpose2d.nxnx_f32_cvt.nxnx_f32_cvt_test.nxnx_f32_dit_block_linear.nxnx_f32_dit_block_simd.nxnx_f32_dit_block_tiny.nxnx_f32_div.nxnx_f32_div_test.nxnx_f32_embed_gate.nxnx_f32_exp.nxnx_f32_exp_test.nxnx_f32_gelu.nxnx_f32_gelu_gate.nxnx_f32_gqa_attention.nxnx_f32_groupnorm.nxnx_f32_image_to_bmp.nxnx_f32_layernorm.nxnx_f32_layernorm_lib_gate.nxnx_f32_lazy_weight_test.nxnx_f32_linear_attention.nxnx_f32_linear_simd.nxnx_f32_llama_block.nxnx_f32_llama_block_test.nxnx_f32_llama_block_v4.nxnx_f32_llama_block_v4_test.nxnx_f32_llama_stack.nxnx_f32_llama_stack_test.nxnx_f32_llama_stack_v4.nxnx_f32_llama_stack_v4_test.nxnx_f32_llama_v4b.nxnx_f32_llama_v4p.nxnx_f32_llm.nxnx_f32_llm_chat_test.nxnx_f32_llm_cohere_test.nxnx_f32_llm_embed_diag_test.nxnx_f32_llm_live_gen_test.nxnx_f32_llm_live_load_only_test.nxnx_f32_llm_live_load_test.nxnx_f32_llm_probe.nxnx_f32_llm_run_v2.nxnx_f32_llm_run_v3.nxnx_f32_llm_serve.nxnx_f32_llm_test.nxnx_f32_llm_v4.nxnx_f32_log.nxnx_f32_log_test.nxnx_f32_lora_linear.nxnx_f32_matmul.nxnx_f32_matmul_t.nxnx_f32_matmul_t_test.nxnx_f32_matmul_test.nxnx_f32_maxpool2d.nxnx_f32_mha.nxnx_f32_mha_multi.nxnx_f32_mha_multi_test.nxnx_f32_mha_test.nxnx_f32_parity.nxnx_f32_q4k_matmul.nxnx_f32_q4k_matmul_test.nxnx_f32_qwen_capital_gate.nxnx_f32_qwen_encoder.nxnx_f32_qwen_layer.nxnx_f32_rectflow_denoise.nxnx_f32_resblock.nxnx_f32_rmsnorm.nxnx_f32_rmsnorm_test.nx +125 more (shown cap 100 declared)

structs

none

consts

65const NX_F32_CLS_ZERO: nx_int = 0
66const NX_F32_CLS_NORMAL: nx_int = 1
67const NX_F32_CLS_SUBNORMAL: nx_int = 2
68const NX_F32_CLS_INF: nx_int = 3
69const NX_F32_CLS_NAN: nx_int = 4
70const NX_F32_CLS_N: nx_int = 5
80const NX_F32_SIGN_MASK: i64 = 0x80000000
81const NX_F32_EXP_MASK: i64 = 0x7F800000
82const NX_F32_MANT_MASK: i64 = 0x007FFFFF
83const NX_F32_EXP_SHIFT: i64 = 23
84const NX_F32_EXP_BIAS: i64 = 127
85const NX_F32_MANT_BITS: i64 = 23
86const NX_F32_IMPLICIT_1: i64 = 0x00800000 // 1 << 23
87const NX_F32_INF_RAW: i64 = 0x7F800000
88const NX_F32_NAN_RAW: i64 = 0x7FC00000 // canonical quiet NaN
89const NX_F32_TOP_BIT_47: i64 = 0x800000000000 // 1 << 47

functions

72func nx_f32_cls_is_valid(c: nx_int) -> nx_int
called by 1: main
93func nx_f32_sign(raw: i64) -> i64
97func nx_f32_exp_field(raw: i64) -> i64
101func nx_f32_mant_field(raw: i64) -> i64
107func nx_f32_classify(raw: i64) -> nx_int
121func nx_f32_is_nan(raw: i64) -> nx_int
126func nx_f32_is_inf(raw: i64) -> nx_int
called by 4: mainmainmainmain calls 1: nx_f32_classify
131func nx_f32_is_zero(raw: i64) -> nx_int
138func nx_f32_neg(raw: i64) -> i64
142func nx_f32_abs(raw: i64) -> i64
150func nx_f32_eq(a: i64, b: i64) -> nx_int
169func nx_f32_lt(a: i64, b: i64) -> nx_int
191func nx_f32_gt(a: i64, b: i64) -> nx_int
209func nx_f32_mul(a: i64, b: i64) -> i64
341func nx_f32_add(a: i64, b: i64) -> i64
515func nx_f32_sub(a: i64, b: i64) -> i64
529func _f32_isqrt(n: i64) -> i64
called by 1: nx_f32_sqrt
589func nx_f32_sqrt(a: i64) -> i64