The source is always 128-bits in little endian format. For big endian
hosts, we have to convert, or we print bogus numbers.
Sponsored by: Netflix
Differential D44651
nvmecontrol: Fix to128 for big endian targets imp on Apr 6 2024, 6:56 PM. Authored by Tags None Referenced Files
Subscribers
Details The source is always 128-bits in little endian format. For big endian Sponsored by: Netflix
Diff Detail
Event TimelineComment Actions This probably doesn't quite work for 32-bit big endian? At least, I used this: static __inline uint128_t to128(const void *p) { #if __SIZEOF_LONG__ == 4 return (le64dec(p)); #else uint64_t lo, hi; lo = le64dec(p); hi = le64dec((const char *)p + 8); return ((uint128_t)hi << 64 | lo); #endif } (I think it's a bit cleaner to use le64dec instead of assuming it is aligned). Also, if it weren't invasive to do the rename I would rather call this le128dec instead of to128 Comment Actions edited There's reasons I was so lazy... but they don't matter. Here's what I landed on... #if __STDC_VERSION__ >= 202311L typedef unsigned __BitInt(128) uint128_t; #elif defined(__SIZEOF_INT128__) typedef __uint128_t uint128_t; #else typedef uint64_t uint128_t; #endif static __inline uint128_t to128(void *p) { #if __STDC_VERSION__ >= 202311L || defined(__SIZEOF_INT128__) uint64_t lo, hi; lo = le64dec(p); hi = le64dec((const char *)p + 8); return ((uint128_t)hi << 64 | lo); #else return (le64dec(p)); #endif } but I think you need gcc14 or clang 18 though... We'd have to add CSTD=c23 to the Makefile too... Comment Actions ah, turns out
Comment Actions I do like the idea of using C23 for the future as a way to fix 32-bit platforms.
|