diff options
author | Mattias Andrée <maandree@kth.se> | 2023-12-17 13:23:51 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2023-12-17 13:23:51 +0100 |
commit | 2e7b4df9f7dfd6a4a6796cd2fcee010ea78427ea (patch) | |
tree | a321a6a0b4bc93cbc1b7704239a675c490383b6d /libsyscalls_section_value.c | |
parent | Tell the user whether signals and errors are signed or unsigned (diff) | |
download | libsyscalls-2e7b4df9f7dfd6a4a6796cd2fcee010ea78427ea.tar.gz libsyscalls-2e7b4df9f7dfd6a4a6796cd2fcee010ea78427ea.tar.bz2 libsyscalls-2e7b4df9f7dfd6a4a6796cd2fcee010ea78427ea.tar.xz |
Miscellaneous improvements
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'libsyscalls_section_value.c')
-rw-r--r-- | libsyscalls_section_value.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/libsyscalls_section_value.c b/libsyscalls_section_value.c index dc86cca..6cdb787 100644 --- a/libsyscalls_section_value.c +++ b/libsyscalls_section_value.c @@ -4,9 +4,11 @@ enum libsyscalls_error libsyscalls_section_value(unsigned long long int value_in, size_t bits, - enum libsyscalls_datatype_section section, unsigned long long int *value_out) + enum libsyscalls_datatype_section section, + unsigned long long int *value_out) { unsigned long long int value = value_in, mask, shift; + size_t hbits; if (bits > sizeof(value) / sizeof(char) * CHAR_BIT || bits & (size_t)(LIBSYSCALLS_GET_SECTION_FRACTION(section) - 1U)) @@ -43,14 +45,18 @@ libsyscalls_section_value(unsigned long long int value_in, size_t bits, break; case LIBSYSCALLS_SECTION_OUTER_HALF: /* 0xFFFF00000000FFFF */ - value = ((value & (mask << (bits + bits / 2))) >> bits) | (value & (mask >> (bits / 2))); + hbits = bits / 2; + value = ((value & (mask << (bits + hbits))) >> bits) + | (value & (mask >> hbits)); break; case LIBSYSCALLS_SECTION_ODD_QUARTERS_AS_HALF: /* 0xFFFF0000FFFF0000 */ value >>= bits / 2; /* fall through */ case LIBSYSCALLS_SECTION_EVEN_QUARTERS_AS_HALF: /* 0x0000FFFF0000FFFF */ - value = ((value & (mask << (bits / 2)) & ~mask) >> (bits / 2)) | (value & (mask >> (bits / 2))); + hbits = bits / 2; + value = ((value & (mask << hbits) & ~mask) >> hbits) + | (value & (mask >> hbits)); break; case LIBSYSCALLS_SECTION_ODD_BYTES_AS_HALF: /* 0xFF00FF00FF00FF00 */ |