Skip to content

Commit

Permalink
libutils: util.h: fix the GENMASK_32(h, l) macro
Browse files Browse the repository at this point in the history
The macro has a problem when it is used in an assembly file:
.e.g ".word GENMASK_32(15, 8)" will be compiled to ".word 0xffffff00"

The issue is caused by the compiler shift right a 64-bit ~0 instead of
a 32-bit ~0. Fix it by using shift left.

Signed-off-by: Tony Han <tony.han@microchip.com>
  • Loading branch information
TonyHan11 committed Apr 19, 2024
1 parent 16fbd46 commit 56b078f
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/libutils/ext/include/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@
* GENMASK_64(39, 21) gives us the 64bit vector 0x000000ffffe00000.
*/
#define GENMASK_32(h, l) \
(((~UINT32_C(0)) << (l)) & (~UINT32_C(0) >> (32 - 1 - (h))))
(((~UINT32_C(0)) << (l)) & ~((~UINT32_C(0) << 1) << (h)))

#define GENMASK_64(h, l) \
(((~UINT64_C(0)) << (l)) & (~UINT64_C(0) >> (64 - 1 - (h))))
Expand Down

0 comments on commit 56b078f

Please sign in to comment.