-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
include: util: Add mem_xor functions #67159
Conversation
Add functions to do XOR on arrays of memory, with one that takes arbitrary sizes and one for 32 bits and 128 bits as those are common sizes for this functionality. Signed-off-by: Emil Gydesen <[email protected]>
*/ | ||
static inline void mem_xor_32(uint8_t dst[4], const uint8_t src1[4], const uint8_t src2[4]) | ||
{ | ||
mem_xor_n(dst, src1, src2, 4U); |
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.
One possible optimization here would be to cast to uint32_t and then xor directly.
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.
Not a bad suggestion. Since the code was copied from implementations from @cvinayak I'd like his input as to why it was not done like that in the first place.
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 to support CPUs needing 4-byte aligned memory read/write operations (ARM cortex-m0 variants etc...).
Fun fact, was my very first contribution to Zephyr Project! de999a8
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.
Probably solvable by using UNALIGNED_PUT/UNALIGNED_GET
macros.
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.
Sorry look at your comment on UNALIGNED_PUT/UNALIGNED_GET now. The implementation in our toolchain header has workarounds for compiler version, and my feeling goes towards sticking to simple old while loop for now.
*/ | ||
static inline void mem_xor_128(uint8_t dst[16], const uint8_t src1[16], const uint8_t src2[16]) | ||
{ | ||
mem_xor_n(dst, src1, src2, 16); |
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.
And here have a small loop and call the 32 variant instead.
*/ | ||
static inline void mem_xor_32(uint8_t dst[4], const uint8_t src1[4], const uint8_t src2[4]) | ||
{ | ||
mem_xor_n(dst, src1, src2, 4U); |
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 to support CPUs needing 4-byte aligned memory read/write operations (ARM cortex-m0 variants etc...).
Fun fact, was my very first contribution to Zephyr Project! de999a8
Add functions to do XOR on arrays of memory, with one that takes arbitrary sizes and one for 32 bits and 128 bits as those are common sizes for this functionality.