Amos Jeffries <[email protected]> writes:
> Is the compiler optimized code for that for loop faster or slower than a
> loop suming the differentials?
Not sure. But I don't think performance is very important here, the
function is going to be used on pretty small inputs.
> volatile unsigned char d;
> for (d = 0; ap >= a; ap--, bp--)
> d += (*ap - *bp);
I don't think that is correct, since d may wrap around to zero. One
would need to accumulate into a larger variable, something like
unsigned d;
for (d = 0; ap >= a; ap--, bp--)
d += (uint8_t)(*ap - *bp);
which, if unsigned int is 32 bits, would be correct for n up to 2^24. (I
think the cast necessary, to avoid values being promoted to *signed*
int). Using | is simpler and more robust.
> NP: That would allow this function to take the uint8_t that most of
> nettle operates with.
Like memxor, this function tries to mimic the conventions of the libc
mem* functions, not nettle's conventions.
Regards,
/Niels
--
Niels Möller. PGP-encrypted email is preferred. Keyid C0B98E26.
Internet email is subject to wholesale government surveillance.
_______________________________________________
nettle-bugs mailing list
[email protected]
http://lists.lysator.liu.se/mailman/listinfo/nettle-bugs