All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Bjørn Mork" <bjorn@mork.no>
To: Philipp Hortmann <philipp.g.hortmann@gmail.com>
Cc: kernelnewbies@kernelnewbies.org
Subject: Re: How to print __u128_t in kernel?
Date: Tue, 21 Sep 2021 09:21:40 +0200	[thread overview]
Message-ID: <87o88mqtq3.fsf@miraculix.mork.no> (raw)
In-Reply-To: <6a2ec637-8ae4-a8ed-888f-652f078bb831@gmail.com> (Philipp Hortmann's message of "Mon, 20 Sep 2021 21:39:15 +0200")

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

      reply	other threads:[~2021-09-21  7:22 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87o88mqtq3.fsf@miraculix.mork.no \
    --to=bjorn@mork.no \
    --cc=kernelnewbies@kernelnewbies.org \
    --cc=philipp.g.hortmann@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.