* How to print __u128_t in kernel?
@ 2021-09-18 13:35 Dongliang Mu
2021-09-20 19:39 ` Philipp Hortmann
0 siblings, 1 reply; 3+ messages in thread
From: Dongliang Mu @ 2021-09-18 13:35 UTC (permalink / raw)
To: kernelnewbies
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
_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: How to print __u128_t in kernel?
2021-09-18 13:35 How to print __u128_t in kernel? Dongliang Mu
@ 2021-09-20 19:39 ` Philipp Hortmann
2021-09-21 7:21 ` Bjørn Mork
0 siblings, 1 reply; 3+ messages in thread
From: Philipp Hortmann @ 2021-09-20 19:39 UTC (permalink / raw)
To: kernelnewbies
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
_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: How to print __u128_t in kernel?
2021-09-20 19:39 ` Philipp Hortmann
@ 2021-09-21 7:21 ` Bjørn Mork
0 siblings, 0 replies; 3+ messages in thread
From: Bjørn Mork @ 2021-09-21 7:21 UTC (permalink / raw)
To: Philipp Hortmann; +Cc: kernelnewbies
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
_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-09-21 7:22 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-18 13:35 How to print __u128_t in kernel? Dongliang Mu
2021-09-20 19:39 ` Philipp Hortmann
2021-09-21 7:21 ` Bjørn Mork
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.