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

les: cosmetic rewrite of the arm64 float bug workaround #21960

Merged
merged 3 commits into from
Dec 7, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions les/utils/expiredvalue.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,9 @@ func (e *ExpiredValue) Add(amount int64, logOffset Fixed64) int64 {
if base >= 0 || uint64(-base) <= e.Base {
Copy link

@mengzhuo mengzhuo Dec 8, 2020

Choose a reason for hiding this comment

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

According to the Go spec:

In all non-constant conversions involving floating-point or complex values, if the result type cannot represent the value the conversion succeeds but the result value is implementation-dependent.

The Go arm64 compiler using C6.3.84 FCVTZU Floating-point convert to unsigned integer, rounding toward zero (scalar)
which is right for the "fraction is discarded (truncation towards zero)". It depends on when architecture choose "towards zero" therefor underflow is undefined behavior.

As for this issue, IMO, DO NOT convert float to uint, covert float to int and compare with int to avoid undefined behavior.

if base >= 0 {
     e.Base += uint64(base)
} else {
     e.Base += uint64(-base)
}

// This is a temporary fix to circumvent a golang
// uint conversion issue on arm64, which needs to
// be investigated further. FIXME
e.Base = uint64(int64(e.Base) + int64(base))
// be investigated further. More details at:
// https://github.com/golang/go/issues/43047
e.Base += uint64(int64(base))
return amount
}
net := int64(-float64(e.Base) / factor)
Expand Down