mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-23 15:55:37 +01:00
mask_of_range: simplify high comparison
To test c <= high, instead of testing the sign of (high + 1) - c, negate the sign of high - c (as we're doing for c - low). This is a little easier to read and shaves 2 instructions off the arm thumb build with arm-none-eabi-gcc 7.3.1. Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
parent
831fd766f3
commit
a2dc0cc9ea
@ -44,9 +44,11 @@
|
||||
static unsigned char mask_of_range( unsigned char low, unsigned char high,
|
||||
unsigned char c )
|
||||
{
|
||||
unsigned low_mask = ( c - low ) >> 8;
|
||||
unsigned high_mask = ( c - high - 1 ) >> 8;
|
||||
return( ~low_mask & high_mask & 0xff );
|
||||
/* low_mask is: 0 if low <= c, 0x...ff if low > c */
|
||||
unsigned low_mask = ( (unsigned) c - low ) >> 8;
|
||||
/* high_mask is: 0 if c <= high, 0x...ff if high > c */
|
||||
unsigned high_mask = ( (unsigned) high - c ) >> 8;
|
||||
return( ~( low_mask | high_mask ) & 0xff );
|
||||
}
|
||||
|
||||
/* Given a value in the range 0..63, return the corresponding Base64 digit.
|
||||
|
Loading…
Reference in New Issue
Block a user