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

Follow-up: Use load_be more efficiently #4085

Merged
merged 1 commit into from
Jun 1, 2024

Conversation

reneme
Copy link
Collaborator

@reneme reneme commented May 29, 2024

See: #4056 (comment)

Closes #4080

@coveralls
Copy link

Coverage Status

coverage: 91.821% (+0.009%) from 91.812%
when pulling b314ce4 on Rohde-Schwarz:fix/use_load_be_in_bigint
into 35c8bd1 on randombit:master.

@@ -420,13 +420,15 @@ void BigInt::assign_from_bytes(std::span<const uint8_t> bytes) {
secure_vector<word> reg((round_up(full_words + (extra_bytes > 0 ? 1 : 0), 8)));

for(size_t i = 0; i != full_words; ++i) {
reg[i] = load_be<word>(&bytes[length - sizeof(word) * (i + 1)], 0);
reg[i] = load_be<word>(bytes.last<sizeof(word)>());
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm so the loaders can omit the index when loading from a span but not an array?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If by "array" you mean "raw pointer to data", yes. My guess is, that this wasn't possible before the load/store refactoring either. Or perhaps I forgot to translate a legacy overload; but given that the rest of the code base compiled, I doubt that.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's true, the index was always required previously. My point is now the behavior is inconsistent depending on the type of argument, which is obviously surprising.

https://en.wikipedia.org/wiki/Principle_of_least_astonishment

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, right. I believe, leaving out the index-overload for ranges was my deliberate decision. I.e. rather set up the range or view accordingly before invoking the loader than pass an offset/index.

On more general terms: The structure of the loaders (with detail::load_any and the constexpr-magic) has the disadvantage that it is fairly hard to see for us which overloads are actually legal. 🤔

Copy link
Owner

@randombit randombit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not super happy about the inconsistent behavior depending on the argument, that was definitely not clear to me in the initial PR. That said this change looks fine.

@reneme reneme merged commit 5649a10 into randombit:master Jun 1, 2024
43 checks passed
@reneme
Copy link
Collaborator Author

reneme commented Jun 1, 2024

FWIW: I would hope to eventually purge the raw-pointer overloads altogether; making it consistent again...

@reneme reneme deleted the fix/use_load_be_in_bigint branch June 3, 2024 06:53
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.

Somehow load_{be,le} of integer without offset doesn't work
3 participants