Skip to content

Change implementation of round_f* in CodeGen_C to use nearbyint() to match CodeGen_LLVM - #6406

Merged
vksnk merged 1 commit into
masterfrom
vksnk/c-round
Nov 12, 2021
Merged

Change implementation of round_f* in CodeGen_C to use nearbyint() to match CodeGen_LLVM#6406
vksnk merged 1 commit into
masterfrom
vksnk/c-round

Conversation

@vksnk

@vksnk vksnk commented Nov 11, 2021

Copy link
Copy Markdown
Member

round_f32/round_f64 implementations at

define weak_odr float @round_f32(float %x) nounwind uwtable readnone alwaysinline {
use nearbyint.

@steven-johnson

Copy link
Copy Markdown
Contributor

Wouldn't it be better to change LLVM to use round instead? (IIRC, nearbyint uses the current rounding mode)

@dsharletg

Copy link
Copy Markdown
Contributor

We thought that the LLVM backend is much more heavily used, so it would make sense to not change that behavior?

@dsharletg

Copy link
Copy Markdown
Contributor

That said: round does sound better than nearbyint (you are correct, round does not use the rounding mode, and nearbyint does not).

@steven-johnson

Copy link
Copy Markdown
Contributor

We thought that the LLVM backend is much more heavily used, so it would make sense to not change that behavior?

Agreed, so I guess this is really "should we migrate the behavior to match" -- IMHO stuff that relies on current rounding mode is a flaky test waiting to happen. Maybe we should consider adding nearbyint and then having each match their C++ equivalent?

@vksnk

vksnk commented Nov 11, 2021

Copy link
Copy Markdown
Member Author

Wouldn't it be better to change LLVM to use round instead? (IIRC, nearbyint uses the current rounding mode)

I guess it might be better in the sense that what round would be doing will be more aligned with expectations. On the other hand, LLVM backends are more widely used, so change in behavior there is riskier and in this case changing CodeGen_C to match is better.

In any case, the goal is to get matching behavior between two, so I'll be happy to change LLVM case instead if that's preferable.

@dsharletg

Copy link
Copy Markdown
Contributor

I think we should submit this (harmonizing LLVM and C without messing with the likely more common case), and then file an issue for switching from nearbyint to round (regardless of target).

@steven-johnson

Copy link
Copy Markdown
Contributor

I think we should submit this (harmonizing LLVM and C without messing with the likely more common case), and then file an issue for switching from nearbyint to round (regardless of target).

+1

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.

3 participants