New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
libutils: util.h: fix the GENMASK_32(h, l) macro for been used in assembly file #6798
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand why the ASM implementation fails.
That said, this change looks ok to me. If it helps:
Acked-by: Etienne Carriere <etienne.carriere@foss.st.com>
.
workaround for the issue: OP-TEE#6798 Signed-off-by: Tony Han <tony.han@microchip.com>
Here is a test on branch test_genmask I did with adding GENMASK_32 to asm file.
|
lib/libutils/ext/include/util.h
Outdated
@@ -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))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are you shifting in two steps? Why not:
(((~UINT32_C(0)) << (l)) & ~(~UINT32_C(0) << (1 + (h))))
However, the root cause is that ~UINT32_C(0)
doesn't give 0xffffffff
as expected.
Wouldn't it make more sense to write ~UINT32_C(0)
as UINT32_C(0xffffffff)
?
It should give the expected result for both C code and assembly code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason of shifting in two steps is to avoid error: left shift count >= width of type [-Werror=shift-count-overflow]
.
Good suggestion! I'll update the macro to ((UINT32_C(0xffffffff) << (l)) & (UINT32_C(0xffffffff) >> (32 - 1 - (h))))
. Thank you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated and rebased on the latest master
.
258e223
to
e03abec
Compare
|
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>
Added the review tag. |
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.
Maybe it's a compiler issue and just do a workaround here.
The compiler I tested is
gcc-arm-8.2-2019.01-x86_64-arm-linux-gnueabi
.