From 4a719a7f4c997ea7e47588bc0288c97706dae015 Mon Sep 17 00:00:00 2001 From: Adenilson Cavalcanti Date: Tue, 20 Nov 2018 14:41:19 -0800 Subject: [PATCH 1/2] Optimize harfbuzz big integer conversions Profiling showed that type conversions were adding considerable cycles in time spent doing text shaping. The idea is to optimize it using native processor instructions to help Blink layout performance. Doing further investigation revelead that compilers may not use the proper instruction on ARM 32bits builds (i.e. REV16). One way to insure that the generated ASM was ideal for both gcc/clang was using __builtin_bswap16. Added bonus is that we no longer need to test for CPU architecture. --- src/hb-machinery.hh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/hb-machinery.hh b/src/hb-machinery.hh index 3c11243f5..c38484158 100644 --- a/src/hb-machinery.hh +++ b/src/hb-machinery.hh @@ -691,6 +691,10 @@ struct BEInt } inline operator Type (void) const { +#if defined(__GNUC__) || defined(__clang__) + struct __attribute__((packed)) packed_uint16_t { uint16_t v; }; + return __builtin_bswap16(((packed_uint16_t *) this)->v); +#endif return (v[0] << 8) + (v[1] ); } From 4e2a03b6b6e0c0d1c4edea10dc1aae63eeb6c581 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 27 Nov 2018 17:40:09 -0500 Subject: [PATCH 2/2] Comment --- src/hb-machinery.hh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/hb-machinery.hh b/src/hb-machinery.hh index c38484158..0e75c8246 100644 --- a/src/hb-machinery.hh +++ b/src/hb-machinery.hh @@ -692,8 +692,10 @@ struct BEInt inline operator Type (void) const { #if defined(__GNUC__) || defined(__clang__) + /* Spoon-feed the compiler a big-endian integer with alignment 1. + * https://github.com/harfbuzz/harfbuzz/pull/1398 */ struct __attribute__((packed)) packed_uint16_t { uint16_t v; }; - return __builtin_bswap16(((packed_uint16_t *) this)->v); + return __builtin_bswap16 (((packed_uint16_t *) this)->v); #endif return (v[0] << 8) + (v[1] );