Skip to content

[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

Closed
wants to merge 6 commits into from

Conversation

xwu
Copy link
Collaborator

@xwu xwu commented Jan 6, 2018

This PR implements more efficient DoubleWidth division using full-width division primitives available on Base.

Also in this PR:

  • De-gyb DoubleWidth.swift.gyb.
  • Update and expand DoubleWidth documentation.
  • Correct implementation of DoubleWidth masking shifts.
  • Fix documentation on remainderReportingOverflow and dividedReportingOverflow.
  • Correct, clarify, and update miscellaneous other documentation and comments.
  • Fix bug in remainderReportingOverflow for builtin types when dividing by -1.
  • Re-implement {U}Int64.dividingFullWidth in terms of DoubleWidth<{U}Int32>.dividingFullWidth.
  • Add more tests for DoubleWidth.dividingFullWidth and DoubleWidth.quotientAndRemainder.

Not in this PR:

  • For builtin types, consider handling dividingFullWidth overflow by using _checked_trunc_ instead of _truncOrBitCast_ operations, and add tests for overflow.

///
/// 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.
Copy link
Collaborator Author

@xwu xwu Jan 25, 2018

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.

@xwu xwu changed the title [Don't merge] [WIP] [stdlib] Implement more efficient DoubleWidth division [WIP] [stdlib] Implement more efficient DoubleWidth division Jan 25, 2018
@xwu
Copy link
Collaborator Author

xwu commented Jan 25, 2018

Still missing tests, but let's see how this does.

@xwu
Copy link
Collaborator Author

xwu commented Jan 25, 2018

@swift-ci Please smoke test OS X platform

@_inlineable // FIXME(sil-serialize-all)
public // @testable
Copy link
Collaborator Author

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).

@xwu xwu changed the title [WIP] [stdlib] Implement more efficient DoubleWidth division [WIP] [stdlib] Implement more efficient DoubleWidth division and fix division-related bugs Jan 25, 2018
@xwu
Copy link
Collaborator Author

xwu commented Jan 25, 2018

@swift-ci Please smoke benchmark

1 similar comment
@xwu
Copy link
Collaborator Author

xwu commented Jan 25, 2018

@swift-ci Please smoke benchmark

@swift-ci
Copy link
Contributor

!!! Couldn't read commit file !!!

@xwu
Copy link
Collaborator Author

xwu commented Jan 25, 2018

@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?

@xwu
Copy link
Collaborator Author

xwu commented Jan 26, 2018

@swift-ci Please smoke benchmark

@xwu
Copy link
Collaborator Author

xwu commented Jan 27, 2018

@swift-ci Please smoke test OS X platform

1 similar comment
@xwu
Copy link
Collaborator Author

xwu commented Jan 27, 2018

@swift-ci Please smoke test OS X platform

@xwu
Copy link
Collaborator Author

xwu commented Jan 27, 2018

Yikes, why is CI failing...

@xwu
Copy link
Collaborator Author

xwu commented Jan 27, 2018

@swift-ci Please clean smoke test OS X platform

@swift-ci
Copy link
Contributor

!!! Couldn't read commit file !!!

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.

2 participants