Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 10 Jul 2022 02:27:02 +0700
From:      Eugene Grosbein <eugen@grosbein.net>
To:        Marc Veldman <marc@bumblingdork.com>, freebsd-hackers@freebsd.org
Subject:   Re: Canonical way / best practice for 128-bit integers
Message-ID:  <eac1a640-ab55-ffae-66e6-5e3405b0c2e2@grosbein.net>
In-Reply-To: <86CB4C22-9CAB-4578-8F11-962B4B08F756@bumblingdork.com>
References:  <86CB4C22-9CAB-4578-8F11-962B4B08F756@bumblingdork.com>

next in thread | previous in thread | raw e-mail | index | archive | help
09.07.2022 23:26, Marc Veldman wrote:
> Hello,
> 
> I’m working on some bluetooth code, and that involves handling 128-bit uuids.
> There are various ways to handle in the FreeBSD codebase, like in sdp.h:
> 
> /*
>  * SDP int128/uint128 parameter
>  */
>     
> struct int128 {
>         int8_t  b[16];
> };
> typedef struct int128   int128_t;
> typedef struct int128   uint128_t;
> 
> and in sys/dev/random/uint128.h
> 
> #ifdef USE_REAL_UINT128_T
> typedef __uint128_t uint128_t;
> #define UINT128_ZERO 0ULL
> #else
> typedef struct {
>         /* Ignore endianness */
>         uint64_t u128t_word0;
>         uint64_t u128t_word1;
> } uint128_t;
> static const uint128_t very_long_zero = {0UL,0UL};
> #define UINT128_ZERO very_long_zero
> #endif
> 
> Is there any recommended / standard way to handle 128 bit integers in a portable way?

UUIDs are not integer numbers with arithmetic, so you should not look for 128 bit ints, if you need portability.
For example, 32 bit i386 arch lacks hardware support for 128 bit ints,
so FreeBSD does not support 128 bit ints with arithmetic for i386
but it does not mean that you cannot use 128 bit UUIDs there.

We have uuid(3) manual for DCE 1.1 compliant UUID type uuid_t and functions.




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?eac1a640-ab55-ffae-66e6-5e3405b0c2e2>