Skip to content

Floating-point support (f32/f64 types and operations) #6

@tetsuo-cpp

Description

@tetsuo-cpp

Summary

Add floating-point type support. Currently everything is i64-only, but real GPU kernels (especially matmul) operate on f32/f64.

What's needed

  • Float literals (or int-to-float conversion words)
  • Float arithmetic: F+ F- F* F/
  • Float load/store: F@ F!
  • Type conversion: S>F (int to float), F>S (float to int)

Design considerations

The Forth stack is currently untyped (!forth.stack backed by memref<256xi64>). Options for float support:

  1. Bit-casting approach: Store f32/f64 as i64 bit patterns on the stack, with F-prefixed ops doing reinterpret casts before/after arithmetic. Simple but loses type safety.
  2. Tagged stack: Add runtime type tags. More Forth-like but adds overhead on GPU.
  3. Separate float stack: Traditional Forth has a separate FP stack. Clean separation but doubles the plumbing.
  4. Type-parameterized stack: Make stack element type configurable. Cleanest MLIR approach but bigger refactor.

Implementation notes

  • Float arithmetic maps to arith.addf, arith.subf, arith.mulf, arith.divf
  • Float load/store needs memref with f32/f64 element type, or bitcast at boundaries
  • Float literals need parser support (detecting . or e in numbers)

Priority

Important — needed for any real-world matmul or ML kernel.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions