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 always treating ~0 as a 64-bit
value. Fix it by replacing '~UINT32_C(0)' with 'UINT32_C(0xffffffff)'.

Signed-off-by: Tony Han <tony.han@microchip.com>
Acked-by: Etienne Carriere <etienne.carriere@foss.st.com>
Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
  • Loading branch information
TonyHan11 committed May 8, 2024
1 parent a359f7d commit 6c20491
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/libutils/ext/include/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@
* 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(0xffffffff) << (l)) & \
(UINT32_C(0xffffffff) >> (32 - 1 - (h))))

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

0 comments on commit 6c20491

Please sign in to comment.