-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[WIP] [stdlib] Implement more efficient DoubleWidth division and fix division-related bugs #13784
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
Conversation
/// | ||
/// The resulting quotient must be representable within the bounds of the | ||
/// type. If the quotient of dividing `dividend` by this value is too large | ||
/// to represent in the type, a runtime error may occur. | ||
/// | ||
/// - Parameter dividend: A tuple containing the high and low parts of a | ||
/// double-width integer. The `high` component of the value carries the | ||
/// sign, if the type is signed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a potentially confusing remark because it is not found anywhere else, even though a similar tuple is accepted as an argument or returned in many other places.
The two's complement value will differ from its magnitude in both the high and low parts, and it's highly doubtful that anyone will wonder if it's the low component that carries the actual sign bit itself.
Still missing tests, but let's see how this does. |
@swift-ci Please smoke test OS X platform |
@_inlineable // FIXME(sil-serialize-all) | ||
public // @testable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although it appears that this initializer was originally not intended for public consumption, the documentation tells users to use it. In fact, this initializer is promoted as part of the main use case for DoubleWidth
(and I would agree with that characterization).
@swift-ci Please smoke benchmark |
1 similar comment
@swift-ci Please smoke benchmark |
!!! Couldn't read commit file !!! |
@shahmishal What does it mean when swift-ci says "!!! Couldn't read commit file !!!" and refuses to benchmark? Or, more to the point, what can I do about it? |
@swift-ci Please smoke benchmark |
@swift-ci Please smoke test OS X platform |
1 similar comment
@swift-ci Please smoke test OS X platform |
Yikes, why is CI failing... |
@swift-ci Please clean smoke test OS X platform |
!!! Couldn't read commit file !!! |
This PR implements more efficient
DoubleWidth
division using full-width division primitives available onBase
.Also in this PR:
DoubleWidth.swift.gyb
.DoubleWidth
documentation.DoubleWidth
masking shifts.remainderReportingOverflow
anddividedReportingOverflow
.remainderReportingOverflow
for builtin types when dividing by-1
.{U}Int64.dividingFullWidth
in terms ofDoubleWidth<{U}Int32>.dividingFullWidth
.DoubleWidth.dividingFullWidth
andDoubleWidth.quotientAndRemainder
.Not in this PR:
dividingFullWidth
overflow by using_checked_trunc_
instead of_truncOrBitCast_
operations, and add tests for overflow.