-
Notifications
You must be signed in to change notification settings - Fork 7.7k
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
ext/bcmath: Optimize bcdiv
processing
#14660
base: master
Are you sure you want to change the base?
Conversation
There was a mistake in some of the assumptions, which made the code unnecessarily complicated, so I will correct it. |
3e0c1df
to
f77cdf8
Compare
done |
5762267
to
4647323
Compare
BC_VECTOR bc_parse_chunk_chars(const char *str) | ||
{ | ||
BC_VECTOR tmp; | ||
memcpy(&tmp, str, sizeof(tmp)); | ||
#if !BC_LITTLE_ENDIAN | ||
tmp = BC_BSWAP(tmp); | ||
#endif |
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.
If I see correctly this part is the same for both sizes, so it can be excluded from the condition.
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 originally Niels' code, and is written this way for readability.
I would like to leave his code untouched.
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.
I doubt it's more readable when we repeat the second level if condition in both functions, but it's a subjective opinion. For sure cognitive complexity is lower without nesting if conditions. It's not a big deal though.
It could probably be made a bit less complicated. I'll fix it and rebase it. |
67b9e10
to
e442f59
Compare
done |
e442f59
to
7549b7b
Compare
7549b7b
to
6714a3b
Compare
BC_VECTOR div_carry = 0; | ||
|
||
/* | ||
* If calculate the temporary quotient using only one array of n1 and n2, the error will be greater |
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.
Does this rule have a name? If so, please let me know, as I can simply provide the URL.
First two commits are definitely fine to already land on master. I'll try to have a look at the actual algorithmic changes today. |
Changed to use
BC_VECTOR
to calculate faster.Since there is a considerable speed difference, the benchmark was roughly measured.
The division code was changed in the third commit.
benchmark code:
before:
after: