Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.
/ druntime Public archive

Comments

core.checkedint.addu: Faster (like subu: only one compare-and-branch).#3496

Merged
dlang-bot merged 1 commit intodlang:masterfrom
DoctorNoobingstoneIPresume:210614_core_checkedint_addu_02h
Jul 5, 2021
Merged

core.checkedint.addu: Faster (like subu: only one compare-and-branch).#3496
dlang-bot merged 1 commit intodlang:masterfrom
DoctorNoobingstoneIPresume:210614_core_checkedint_addu_02h

Conversation

@DoctorNoobingstoneIPresume
Copy link

@DoctorNoobingstoneIPresume DoctorNoobingstoneIPresume commented Jun 14, 2021

Explanation of why a single compare-and-branch is enough for addu:

For unsigned integrals, if we add r = x + y:

  • if there is no carry, then r >= x and r >= y;
  • if there is carry, then r < x and r < y.

Also, let us look at the implementation of subu. One compare-and-branch suffices for subu. It should suffice for addu as well. (-:

Testing information 1 (correctness):

$ cd src/core/
$ rdmd -unittest --main checkedint.d
1 modules passed unittests

Testing information 2 (improvement of generated code):
Comparison of generated machine code (DMD for Win32):

$ dmd -O -release -unittest checkedint.d -of=checkedint.d.obj

For uint overload: Before: 2 cmp instructions, 2 conditional-jump instructions. After: 1 cmp instruction, 1 conditional-jump instruction.

For ulong overload: Before: 4 cmp instructions, 4 conditional-jump instructions. After: 2 cmp instructions, 2 conditional-jump instructions.

Thank you for considering this.

@dlang-bot
Copy link
Contributor

Thanks for your pull request and interest in making D better, @DoctorNoobingstoneIPresume! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please verify that your PR follows this checklist:

  • My PR is fully covered with tests (you can see the coverage diff by visiting the details link of the codecov check)
  • My PR is as minimal as possible (smaller, focused PRs are easier to review than big ones)
  • I have provided a detailed rationale explaining my changes
  • New or modified functions have Ddoc comments (with Params: and Returns:)

Please see CONTRIBUTING.md for more information.


If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment.

Bugzilla references

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub run digger -- build "master + druntime#3496"

@DoctorNoobingstoneIPresume
Copy link
Author

I wish to modify the pull request like this:

https://github.com/dlang/druntime/compare/master...DoctorNoobingstoneIPresume:210614_core_checkedint_addu_03h?expand=1

May I ask what is the best/preferred way to do this, please ?

E.g.:

(1) New PR (old PR closed with comment pointing to new PR) ? => Single commit, but comments/conversations are lost (or more difficult to reach) ?

(2) New commit on the current PR ? But then how to merge as single commit ?

(3) Some other suggestion ?

@thewilsonator
Copy link
Contributor

If HEAD is currently at 5b62e56 and the rest of changes in 7c4ce67 are uncommitted then do:
$ git reset HEAD~1 followed by a git commit, followed by git push -f

If HEAD is currently at 7c4ce67 and the previous commit is 5b62e56 then do $ git reset HEAD~2 followed by a git commit, followed by git push -f

@DoctorNoobingstoneIPresume DoctorNoobingstoneIPresume force-pushed the 210614_core_checkedint_addu_02h branch from 5b62e56 to e0a1abf Compare June 15, 2021 15:56
@DoctorNoobingstoneIPresume
Copy link
Author

@thewilsonator Thank you for the assistance ! I hope I have got it right.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants