Hello everyone, I encounter one object with __uint128_t type in the following code. But I am not sure how to print the content of __uint128_t. struct user_fpsimd_state { __uint128_t vregs[32]; __u32 fpsr; __u32 fpcr; __u32 __reserved[2]; }; At first, I would like to use: pr_alert("0x%lx %lx\n", i, (uint64_t)(fpreg.vregs[i] >> 64), (uint64_t)(fpreg.vregs[i])); However, gcc reports error with "-Werror" enabled: In function ‘print_fpregs_in_coredump’: error: iteration 32 invokes undefined behavior [-Werror=aggressive-loop-optimizations] 89 | pr_alert("V%d 0x%lx %lx\n", i, (uint64_t)(fpreg.vregs[i] >> 64), Any idea to eliminate this error? -- My best regards to you. No System Is Safe! Dongliang Mu
On 9/18/21 3:35 PM, Dongliang Mu wrote:
Hello everyone,
I encounter one object with __uint128_t type in the following code. But I am not sure how to print the content of __uint128_t.
struct user_fpsimd_state { __uint128_t vregs[32]; __u32 fpsr; __u32 fpcr; __u32 __reserved[2]; };
At first, I would like to use: pr_alert("0x%lx %lx\n", i, (uint64_t)(fpreg.vregs[i] >> 64), (uint64_t)(fpreg.vregs[i]));
However, gcc reports error with "-Werror" enabled:
In function ‘print_fpregs_in_coredump’: error: iteration 32 invokes undefined behavior [-Werror=aggressive-loop-optimizations] 89 | pr_alert("V%d 0x%lx %lx\n", i, (uint64_t)(fpreg.vregs[i] >> 64),
Any idea to eliminate this error?
-- My best regards to you.
No System Is Safe! Dongliang Mu
Hi I do like this example: https://lwn.net/Articles/745261/ ... pr_err("%llx%llx\n", (u64) (val >> 64), (u64) val); pr_err("%llx%llx\n", (u64) (v >> 64), (u64) v); ... But I have not tried it. Bye Philipp
Philipp Hortmann <philipp.g.hortmann@gmail.com> writes:
I do like this example: https://lwn.net/Articles/745261/
... pr_err("%llx%llx\n", (u64) (val >> 64), (u64) val); pr_err("%llx%llx\n", (u64) (v >> 64), (u64) v); ...
This will produce the wrong output unless at least one of bit 60 - 63 is set and have a confusing leading zero unless one of the upper 64 bits is set. Running this test: #include <stdio.h> #include <stdlib.h> int main(int argc, char **argv) { __uint128_t foo; if (argc < 3) return -1; foo = (__uint128_t)strtoull(argv[1], NULL, 0) << 64 | strtoull(argv[2], NULL, 0); fprintf(stderr, "foo=0x%llx%llx\n", (__uint64_t) (foo >> 64), (__uint64_t) foo); fprintf(stderr, "foo=0x%016llx%016llx\n", (__uint64_t) (foo >> 64), (__uint64_t) foo); return 0; } Produces: bjorn@miraculix:~$ /tmp/x 1 0 foo=0x10 foo=0x00000000000000010000000000000000 bjorn@miraculix:~$ /tmp/x 1 2 foo=0x12 foo=0x00000000000000010000000000000002 bjorn@miraculix:~$ /tmp/x 0 2 foo=0x02 foo=0x00000000000000000000000000000002 Bjørn
participants (3)
-
Bjørn Mork -
Dongliang Mu -
Philipp Hortmann