]> www.infradead.org Git - users/sagi/nvme-cli.git/commit
utils: Fix uint128_t usage
authorJeremy Kerr <jk@codeconstruct.com.au>
Sun, 25 Sep 2022 12:12:34 +0000 (20:12 +0800)
committerJeremy Kerr <jk@codeconstruct.com.au>
Sun, 25 Sep 2022 12:25:56 +0000 (20:25 +0800)
commitb509ccb39a8ca242a0c42400408d1a8d86911ba1
treec89512f1ff31d4811f7413588a748c18a6348a06
parent9f87d61af9f9051d9b018a8b5195fc8c929dcd0b
utils: Fix uint128_t usage

Currently, nvme-cli will not compile on 32-bit platforms, as uint128_t
is not available.

This change, based on suggestions from Daniel Wagner <dwagner@suse.de>,
adds our own nvme_uint128_t type, which needs a custom to_string()
function.

In order to make the latter straightforward, we use four 32-bit words
for the internal representation of the 128-bit type. We then use 64-bit
arithmetic to avoid having to handle the carry-bit explicitly.

Also, add a small test case for the printing.

Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
nvme-print.c
tests/meson.build
tests/test-uint128.c [new file with mode: 0644]
util/json.c
util/json.h
util/types.c
util/types.h