Skip to content

Comments

feat: add float math intrinsics#47

Merged
tetsuo-cpp merged 2 commits intocanonfrom
worktree-feat/float-math-intrinsics
Feb 21, 2026
Merged

feat: add float math intrinsics#47
tetsuo-cpp merged 2 commits intocanonfrom
worktree-feat/float-math-intrinsics

Conversation

@tetsuo-cpp
Copy link
Owner

Summary

  • Add 7 float math intrinsic words: FEXP, FSQRT, FLOG, FABS, FNEG (unary) and FMAX, FMIN (binary)
  • Lower unary ops via math.exp/math.sqrt/math.log/math.absf/arith.negf with i64↔f64 bitcast pattern
  • Lower binary ops via arith.maximumf/arith.minimumf reusing existing BinaryArithOpConversion template
  • Add convert-math-to-llvm pass in pipeline for GPU lowering

Test plan

  • Translation test: all 7 words parse to correct forth.* ops
  • Conversion test: unary/binary ops produce expected bitcast + math/arith patterns
  • Pipeline test: end-to-end lowering to gpu.binary
  • All 105 tests pass

Copy link
Owner Author

@tetsuo-cpp tetsuo-cpp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

Clean, well-structured PR that follows established patterns closely. LGTM overall.

Strengths

  • Good template factoring — UnaryFloatOpConversion mirrors the existing BinaryArithOpConversion nicely
  • MaxF/MinF correctly reuse the binary template instead of duplicating code
  • Test coverage across all three layers (translation, conversion, pipeline)
  • Pipeline ordering is correct: math-to-llvm after gpu-to-nvvm but before nvvm-to-llvm

One bug: duplicate stage number

Passes.cpp:53 — comment says "Stage 8" for gpu.binary compilation, but the preceding reconcile-unrealized-casts is also labeled "Stage 8". Should be "Stage 9".

Nit

arith::MaximumFOp / arith::MinimumFOp follow IEEE 754-2019 semantics (NaN-propagating). This is probably the right default for GPU math, but worth noting — if FMAX NaN 1.0 should return 1.0 (like CUDA's fmax), you'd want arith::MaxNumFOp instead. The current choice matches standard IEEE behavior though, so fine as-is.

@tetsuo-cpp tetsuo-cpp merged commit 1a8bcc5 into canon Feb 21, 2026
1 check passed
@tetsuo-cpp tetsuo-cpp deleted the worktree-feat/float-math-intrinsics branch February 21, 2026 12:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant