forked from nim-works/nimskull
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mir: add built-in float arithmetic ops (nim-works#1172)
## Summary Introduce built-in MIR operators for basic floating-point arithmetic. Exceptional control-flow arising from float overflow checks (`infChecks`) is now also visible to data-flow analysis and destructor injection, fixing locals not being cleaned up when a scope is exited as the result of a failed float overflow check and there's no other unstructured scope exit. ## Details ### MIR * the existing signed integer arithmetic operators (`mnkNegI`, `mnkAddI`, `mnkSubI`, etc.) are extended to also cover float operands. The "I" suffix is removed from the names * the built-in arithmetic operators for floating-point operands are also without run-time checks ### AST-to-MIR translation * if float overflow checks are enabled, the float arithmetic magic calls are kept as calls (a checked call is used if panics are disabled) * if the checks are disabled, the float arithmetic magic calls are translated to the MIR's built-in operators * `mUnaryMinusF64` is always translated to `mnkNeg`, since overflow is not possible for floating-point negation ### C code generator * the built-in float arithmetic operation are translated in the same way that the originating-from magics were * for translating the built-in arithmetic operations (`cnkNeg`, `cnkAdd`, etc.), the expression's type is used for picking the correct translation * `binaryFloatArith`, which is only used for translating the magic calls, always emits float overflow checks ### JS code generator * except for division, the code so far generated for the built-in arithmetic operators is also valid for floats * overflow checks for floats aren't implemented for the JS backend at this time, so nothing changes for the magics ### VM code generator * code generation for the built-in arithmetic operators pick the correct opcode based on the type * emission of the `NarrowS` instructions (via `genNarrow`) is removed for the built-in arithmetic op code generation. They're unnecessary, and they'd also be invalid for float operands * overflow checks for floats aren't implemented for the VM backend at this time, so nothing changes for the magics There were also two issues with `cnkNeg` code generation that are now fixed: * the temporary register is freed properly (caused a minor register leak) * the destination register is set up properly (could cause the VM to crash) ### Tests * to act as a reminder that the float overflow check implementation is missing, the `float/tfloats1.nim` test is enabled for all targets. The expected output is changed such that it doesn't rely on backend-specific uncaught-exception rendering * a test case for ensuring that locals are cleaned up when their scope is left via exceptional control-flow
- Loading branch information
Showing
11 changed files
with
112 additions
and
63 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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