From 818f109bdec9659c05f9fd9a1de1db85ece65cbe Mon Sep 17 00:00:00 2001 From: Ebrahim Byagowi Date: Thu, 16 Apr 2020 21:25:32 +0430 Subject: [PATCH] Use float in avar calculation instead ints and checking their overflows --- src/hb-algs.hh | 12 ------------ src/hb-ot-var-avar-table.hh | 9 ++------- src/hb.hh | 4 ---- 3 files changed, 2 insertions(+), 23 deletions(-) diff --git a/src/hb-algs.hh b/src/hb-algs.hh index 898e27b03..5d2a48c46 100644 --- a/src/hb-algs.hh +++ b/src/hb-algs.hh @@ -645,18 +645,6 @@ hb_unsigned_mul_overflows (unsigned int count, unsigned int size) return (size > 0) && (count >= ((unsigned int) -1) / size); } -static inline bool -hb_int_mul_overflows (int x, int y, int &result) -{ -#if __has_builtin(__builtin_mul_overflow) - return __builtin_mul_overflow (x, y, &result); -#else - int64_t sink = (int64_t) x * y; - result = sink; - return result != sink; -#endif -} - /* * Sort and search. diff --git a/src/hb-ot-var-avar-table.hh b/src/hb-ot-var-avar-table.hh index d1f4ecaa2..29219adb0 100644 --- a/src/hb-ot-var-avar-table.hh +++ b/src/hb-ot-var-avar-table.hh @@ -89,14 +89,9 @@ struct SegmentMaps : ArrayOf if (unlikely (arrayZ[i-1].fromCoord == arrayZ[i].fromCoord)) return arrayZ[i-1].toCoord; - int factor; - if (unlikely (hb_int_mul_overflows (arrayZ[i].toCoord - arrayZ[i-1].toCoord, - value - arrayZ[i-1].fromCoord, - factor))) - return arrayZ[i-1].toCoord; - int denom = arrayZ[i].fromCoord - arrayZ[i-1].fromCoord; - return arrayZ[i-1].toCoord + (factor + denom/2) / denom; + return roundf (arrayZ[i-1].toCoord + ((float) (arrayZ[i].toCoord - arrayZ[i-1].toCoord) * + (value - arrayZ[i-1].fromCoord)) / denom); #undef toCoord #undef fromCoord } diff --git a/src/hb.hh b/src/hb.hh index d4b51cf67..fcbd33058 100644 --- a/src/hb.hh +++ b/src/hb.hh @@ -219,10 +219,6 @@ extern "C" void hb_free_impl(void *ptr); * Compiler attributes */ -#ifndef __has_builtin -# define __has_builtin(x) 0 -#endif - #if (defined(__GNUC__) || defined(__clang__)) && defined(__OPTIMIZE__) #define likely(expr) (__builtin_expect (!!(expr), 1)) #define unlikely(expr) (__builtin_expect (!!(expr), 0))