From 37a8e4af54136ae422bbd32d07367d39b1c182bc Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 22 Jan 2025 05:34:30 -0700 Subject: [PATCH] [algs] Minor tweak to HBFloat --- src/hb-algs.hh | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/src/hb-algs.hh b/src/hb-algs.hh index d8d37b2e6..4deeec577 100644 --- a/src/hb-algs.hh +++ b/src/hb-algs.hh @@ -124,7 +124,7 @@ struct HBInt HBInt (Type V) #if HB_FAST_NUM_ACCESS { - bool be = __BYTE_ORDER == __BIG_ENDIAN; + constexpr bool be = __BYTE_ORDER == __BIG_ENDIAN; if (be == BE) ((hb_packed_t *) v)->v = V; else @@ -138,7 +138,7 @@ struct HBInt constexpr operator Type () const { #if HB_FAST_NUM_ACCESS - bool be = __BYTE_ORDER == __BIG_ENDIAN; + constexpr bool be = __BYTE_ORDER == __BIG_ENDIAN; if (be == BE) return ((hb_packed_t *) v)->v; else @@ -174,7 +174,7 @@ struct HBInt HBInt (Type V) #if HB_FAST_NUM_ACCESS { - bool be = __BYTE_ORDER == __BIG_ENDIAN; + constexpr bool be = __BYTE_ORDER == __BIG_ENDIAN; if (be == BE) ((hb_packed_t *) v)->v = V; else @@ -189,7 +189,7 @@ struct HBInt constexpr operator Type () const { #if HB_FAST_NUM_ACCESS - bool be = __BYTE_ORDER == __BIG_ENDIAN; + constexpr bool be = __BYTE_ORDER == __BIG_ENDIAN; if (be == BE) return ((hb_packed_t *) v)->v; else @@ -247,24 +247,22 @@ struct HBFloat HBFloat (Type V) { +#if HB_FAST_NUM_ACCESS + { + constexpr bool be = __BYTE_ORDER == __BIG_ENDIAN; + if (be == BE) + { + ((hb_packed_t *) v)->v = V; + return; + } + } +#endif + union { hb_packed_t f; hb_packed_t i; } u = {{V}}; -#if HB_FAST_NUM_ACCESS - { - bool be = __BYTE_ORDER == __BIG_ENDIAN; - if (be != BE) - { - hb_barrier (); - u.i.v = __builtin_bswap32 (u.i.v); - hb_barrier (); - } - ((hb_packed_t *) v)->v = u.f.v; - } -#endif - const HBInt I = u.i.v; for (unsigned i = 0; i < Bytes; i++) v[i] = I.v[i]; @@ -274,7 +272,7 @@ struct HBFloat { #if HB_FAST_NUM_ACCESS { - bool be = __BYTE_ORDER == __BIG_ENDIAN; + constexpr bool be = __BYTE_ORDER == __BIG_ENDIAN; if (be == BE) return ((hb_packed_t *) v)->v; }