Skip to content
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

randomx_reciprocal is slow #283

Closed
tevador opened this issue Oct 20, 2023 · 1 comment · Fixed by #284
Closed

randomx_reciprocal is slow #283

tevador opened this issue Oct 20, 2023 · 1 comment · Fixed by #284
Assignees

Comments

@tevador
Copy link
Owner

tevador commented Oct 20, 2023

This function is not optimized:

RandomX/src/reciprocal.c

Lines 47 to 72 in d3c9648

uint64_t randomx_reciprocal(uint64_t divisor) {
assert(divisor != 0);
const uint64_t p2exp63 = 1ULL << 63;
uint64_t quotient = p2exp63 / divisor, remainder = p2exp63 % divisor;
unsigned bsr = 0; //highest set bit in divisor
for (uint64_t bit = divisor; bit > 0; bit >>= 1)
bsr++;
for (unsigned shift = 0; shift < bsr; shift++) {
if (remainder >= divisor - remainder) {
quotient = quotient * 2 + 1;
remainder = remainder * 2 - divisor;
}
else {
quotient = quotient * 2;
remainder = remainder * 2;
}
}
return quotient;
}

There is an optimized version inside the ARM64 JIT compiler implemented by @SChernykh . It would be better to optimize randomx_reciprocal rather than duplicating the code inline.

@SChernykh
Copy link
Collaborator

#284

@tevador tevador linked a pull request Oct 20, 2023 that will close this issue
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 a pull request may close this issue.

2 participants