Re: How to print __u128_t in kernel?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Philipp Hortmann <philipp.g.hortmann@xxxxxxxxx> 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@xxxxxxxxxxxxxxxxx
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies




[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]

  Powered by Linux