Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stage2 can't negate a NaN at runtime #11853

Closed
Tracked by #11899 ...
Vexu opened this issue Jun 12, 2022 · 1 comment · Fixed by #11967
Closed
Tracked by #11899 ...

Stage2 can't negate a NaN at runtime #11853

Vexu opened this issue Jun 12, 2022 · 1 comment · Fixed by #11967
Assignees
Labels
backend-llvm The LLVM backend outputs an LLVM IR Module. frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Milestone

Comments

@Vexu
Copy link
Member

Vexu commented Jun 12, 2022

In the AIR negation is implemented as 0 - val which means that a NaN cannot be negated using the - operator. I'm not sure how desirable negative NaNs are but the behavior should be consistent at comptime and runtime.

test {
    std.debug.print("{d}\n", .{-math.nan(f32)}); // nan
    std.debug.print("{d}\n", .{-comptime math.nan(f32)}); // -nan
}
@Vexu Vexu added frontend Tokenization, parsing, AstGen, Sema, and Liveness. backend-llvm The LLVM backend outputs an LLVM IR Module. labels Jun 12, 2022
@Vexu Vexu added this to the 0.10.0 milestone Jun 12, 2022
@Vexu Vexu mentioned this issue Jun 20, 2022
7 tasks
@andrewrk andrewrk self-assigned this Jun 30, 2022
@andrewrk
Copy link
Member

stage1 lowers to

  %2 = fneg float %1

stage2 lowers to

  %2 = fsub float 0.000000e+00, %1

stage1 is correct

andrewrk added a commit that referenced this issue Jun 30, 2022
Rather than lowering float negation as `0.0 - x`.

 * Add AIR instruction for float negation.
 * Add compiler-rt functions for f128, f80 negation

closes #11853
andrewrk added a commit that referenced this issue Jul 19, 2022
Rather than lowering float negation as `0.0 - x`.

 * Add AIR instruction for float negation.
 * Add compiler-rt functions for f128, f80 negation

closes #11853
wooster0 pushed a commit to wooster0/zig that referenced this issue Jul 24, 2022
Rather than lowering float negation as `0.0 - x`.

 * Add AIR instruction for float negation.
 * Add compiler-rt functions for f128, f80 negation

closes ziglang#11853
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend-llvm The LLVM backend outputs an LLVM IR Module. frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants