FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

bpo-46504: faster code for trial quotient in x_divrem() by tim-one · Pull Request #30856 · python/cpython · GitHub

/ cpython Public
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension .c  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
Next Next commit
bpo-46504: faster code for trial quotient in x_divrem()
This brings x_divrem() back into synch with x_divrem1(), which was changed
in bpo-46406 to generate faster code to find machine-word division
quotients and remainders. Modern processors compute both with a single
machine instructioh, but convincing C to exploit that requires writing
_less_ "clever" C code.
  • Loading branch information
tim-one committed Jan 24, 2022
commit a4eea39d42f9f7feec51df8b3d66ccd44c33ffa5
9 changes: 8 additions & 1 deletion Objects/longobject.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -2767,8 +2767,15 @@ x_divrem(PyLongObject *v1, PyLongObject *w1, PyLongObject **prem)
vtop = vk[size_w];
assert(vtop <= wm1);
vv = ((twodigits)vtop << PyLong_SHIFT) | vk[size_w-1];
/* The code used to compute the remainder via
Comment thread
tim-one marked this conversation as resolved.
* r = (digit)(vv - (twodigits)wm1 * q);
* and compilers generally generated code to do the * and -.
* But modern p;ocessors generally compute q and r with a single
* instruction, and modern optimizing compilers exploit that if we
* _don't_ try to optimize it.
*/
q = (digit)(vv / wm1);
r = (digit)(vv - (twodigits)wm1 * q); /* r = vv % wm1 */
r = (digit)(vv % wm1);
while ((twodigits)wm2 * q > (((twodigits)r << PyLong_SHIFT)
| vk[size_w-2])) {
--q;
Expand Down

Back | FazBrowse Home | New Git URL