This repository was archived by the owner on Apr 8, 2026. It is now read-only.
Add float32 IR support and scalar float lowering for the C backend#68
Merged
Conversation
Greptile SummaryThis PR adds end-to-end Key changes:
Confidence Score: 4/5
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
SRC["Go source with float32/float64"]
PARSER["parser.go\naccepts float32 type\n(removes old rejection)"]
FRONTEND["compiler.go\nfloat32 type registered\nmergeFloatTypeNames\nemitConvertForExpr"]
IR["IR: OP_CONST_F32 / OP_CONST_F64\nOP_ADD/SUB/MUL/DIV name=float32|float64\nOP_CONVERT Val=SRC_FLOAT32|SRC_FLOAT64\nIRLocal.FloatKind=TY_FLOAT32|TY_FLOAT64"]
TEXT["ir_text_codec\nrtgir 3\nfloat_kind= attribute"]
BIN["ir_binary_codec\nRTGIRB2\nFloatKind integer field"]
CHECK["backend_c.go\ncModuleNeedsFloatKinds()\nerror if word < float width"]
CBACK["C backend\nrtg_f32_bits / rtg_bits_f32\nrtg_f64_bits / rtg_bits_f64\nfloat arith/cmp/convert"]
ARM64["AArch64 backend\nFMOV / FADD / FSUB / FMUL\nFDIV / FNEG / FCMP\nFCVT / SCVTF / UCVTF"]
SRC --> PARSER --> FRONTEND --> IR
IR --> TEXT
IR --> BIN
IR --> CHECK
CHECK -->|"bits>=32 for f32\nbits>=64 for f64"| CBACK
IR --> ARM64
Last reviewed commit: c865547 |
Contributor
Author
|
@greptile review agian please. |
Comment on lines
+511
to
+516
| case ir.OP_LT, ir.OP_JMP_LT: | ||
| return COND_MI | ||
| case ir.OP_GT, ir.OP_JMP_GT: | ||
| return COND_GT | ||
| case ir.OP_LEQ, ir.OP_JMP_LEQ: | ||
| return COND_LS |
There was a problem hiding this comment.
The condition codes chosen here are correct for IEEE 754 NaN handling, but the rationale should be documented to prevent a future maintainer from "fixing" them to the seemingly equivalent COND_LT/COND_LE.
After an AArch64 FCMP where either operand is NaN, the flags are N=0, Z=0, C=1, V=1. Under those flags:
COND_LT(N≠V) →0≠1→ true — incorrect; Go requiresNaN < x= falseCOND_LE(Z=1 or N≠V) →false or true→ true — incorrect; Go requiresNaN <= x= false
The chosen conditions correctly avoid the N≠V test:
COND_MI(N=1): NaN gives N=0 → false ✓COND_LS(C=0 or Z=1): NaN gives C=1, Z=0 → false ✓
Consider adding a brief comment on each case:
Suggested change
| case ir.OP_LT, ir.OP_JMP_LT: | |
| return COND_MI | |
| case ir.OP_GT, ir.OP_JMP_GT: | |
| return COND_GT | |
| case ir.OP_LEQ, ir.OP_JMP_LEQ: | |
| return COND_LS | |
| case ir.OP_LT, ir.OP_JMP_LT: | |
| return COND_MI // N=1: correct for ordered LT; NaN gives N=0 → false (not COND_LT which triggers on N≠V, true for NaN) | |
| case ir.OP_GT, ir.OP_JMP_GT: | |
| return COND_GT | |
| case ir.OP_LEQ, ir.OP_JMP_LEQ: | |
| return COND_LS // C=0|Z=1: correct for ordered LE; NaN gives C=1,Z=0 → false (not COND_LE which triggers on N≠V, true for NaN) | |
| case ir.OP_GEQ, ir.OP_JMP_GEQ: | |
| return COND_GE |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
float32IR/frontend support alongside the existingfloat64workTY_FLOAT32,OP_CONST_F32, and float local metadatafloat32/float64lowering for the C backend using raw-bit transport inrtg_word, including float arithmetic, compares, jumps, conversions, and sized load/store fixesfloat64requiresc/64, andfloat32requires at leastc/32Validation
./build/build build./build/rtg -T ir -o - tmp/float_smoke.go./build/rtg -T c/64 tmp/float_smoke.go -o tmp/float_smoke.ccc -O0 tmp/float_smoke.c -o tmp/float_smoke.bin./tmp/float_smoke.bin./build/build test-fullcompiler-c./build/build selfhost-c