[algs] Add 64bit int types fastpath

This commit is contained in:
Behdad Esfahbod committed 2025-12-23 15:38:18 -07:00
1 parent eb5caac243
commit dcc3e6d106
1 file changed
+19 -1
+19 -1
View File
@@ -98,7 +98,8 @@ struct __attribute__((packed)) hb_packed_t { Type v; };
(__BYTE_ORDER == __BIG_ENDIAN || \
(__BYTE_ORDER == __LITTLE_ENDIAN && \
hb_has_builtin(__builtin_bswap16) && \
hb_has_builtin(__builtin_bswap32)))
hb_has_builtin(__builtin_bswap32) && \
hb_has_builtin(__builtin_bswap64)))
#define HB_FAST_NUM_ACCESS 1
#else
#define HB_FAST_NUM_ACCESS 0
@@ -222,6 +223,14 @@ struct HBInt<BE, Type, 8>
HBInt () = default;
HBInt (Type V)
#if HB_FAST_NUM_ACCESS
{
if (BE == (__BYTE_ORDER == __BIG_ENDIAN))
((hb_packed_t<uint64_t> *) v)->v = V;
else
((hb_packed_t<uint64_t> *) v)->v = __builtin_bswap64 (V);
}
#else
: v {BE ? uint8_t ((V >> 56) & 0xFF) : uint8_t ((V ) & 0xFF),
BE ? uint8_t ((V >> 48) & 0xFF) : uint8_t ((V >> 8) & 0xFF),
BE ? uint8_t ((V >> 40) & 0xFF) : uint8_t ((V >> 16) & 0xFF),
@@ -230,8 +239,16 @@ struct HBInt<BE, Type, 8>
BE ? uint8_t ((V >> 16) & 0xFF) : uint8_t ((V >> 40) & 0xFF),
BE ? uint8_t ((V >> 8) & 0xFF) : uint8_t ((V >> 48) & 0xFF),
BE ? uint8_t ((V ) & 0xFF) : uint8_t ((V >> 56) & 0xFF)} {}
#endif
constexpr operator Type () const {
#if HB_FAST_NUM_ACCESS
return (BE == (__BYTE_ORDER == __BIG_ENDIAN)) ?
((const hb_packed_t<uint64_t> *) v)->v
:
__builtin_bswap64 (((const hb_packed_t<uint64_t> *) v)->v)
;
#else
return (BE ? (uint64_t (v[0]) << 56) : (uint64_t (v[0]) ))
+ (BE ? (uint64_t (v[1]) << 48) : (uint64_t (v[1]) << 8))
+ (BE ? (uint64_t (v[2]) << 40) : (uint64_t (v[2]) << 16))
@@ -240,6 +257,7 @@ struct HBInt<BE, Type, 8>
+ (BE ? (uint64_t (v[5]) << 16) : (uint64_t (v[5]) << 40))
+ (BE ? (uint64_t (v[6]) << 8) : (uint64_t (v[6]) << 48))
+ (BE ? (uint64_t (v[7]) ) : (uint64_t (v[7]) << 56));
#endif
}
private: uint8_t v[8];
};