From 7737e87ac4582d57945f3ffbbae1012f62c6b482 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sun, 15 Oct 2017 16:21:03 -0400 Subject: [PATCH] Properly detect vector_size attribute and use fallback otherwise --- src/hb-private.hh | 67 +++++++++++++++++++++++++++++++++++++++++++ src/hb-set-private.hh | 62 ++------------------------------------- 2 files changed, 69 insertions(+), 60 deletions(-) diff --git a/src/hb-private.hh b/src/hb-private.hh index 46bffac28..3cf8b8d3e 100644 --- a/src/hb-private.hh +++ b/src/hb-private.hh @@ -1058,6 +1058,73 @@ hb_codepoint_parse (const char *s, unsigned int len, int base, hb_codepoint_t *o } +/* Vectorization */ + +struct HbOpOr +{ + static const bool passthru_left = true; + static const bool passthru_right = true; + template static void process (T &o, const T &a, const T &b) { o = a | b; } +}; +struct HbOpAnd +{ + static const bool passthru_left = false; + static const bool passthru_right = false; + template static void process (T &o, const T &a, const T &b) { o = a & b; } +}; +struct HbOpMinus +{ + static const bool passthru_left = true; + static const bool passthru_right = false; + template static void process (T &o, const T &a, const T &b) { o = a & ~b; } +}; +struct HbOpXor +{ + static const bool passthru_left = true; + static const bool passthru_right = true; + template static void process (T &o, const T &a, const T &b) { o = a ^ b; } +}; + +/* Type behaving similar to vectorized vars defined using __attribute__((vector_size(...))). */ +template +struct hb_vector_size_t +{ + elt_t& operator [] (unsigned int i) { return v[i]; } + const elt_t& operator [] (unsigned int i) const { return v[i]; } + + template + inline hb_vector_size_t process (const hb_vector_size_t &o) const + { + hb_vector_size_t r; + for (unsigned int i = 0; i < ARRAY_LENGTH (v); i++) + Op::process (r.v[i], v[i], o.v[i]); + return r; + } + inline hb_vector_size_t operator | (const hb_vector_size_t &o) const + { return process (o); } + inline hb_vector_size_t operator & (const hb_vector_size_t &o) const + { return process (o); } + inline hb_vector_size_t operator ^ (const hb_vector_size_t &o) const + { return process (o); } + inline hb_vector_size_t operator ~ () const + { + hb_vector_size_t r; + for (unsigned int i = 0; i < ARRAY_LENGTH (v); i++) + r.v[i] = ~v[i]; + return r; + } + + private: + static_assert (byte_size / sizeof (elt_t) * sizeof (elt_t) == byte_size); + elt_t v[byte_size / sizeof (elt_t)]; +}; + +/* The `vector_size' attribute was introduced in gcc 3.1. */ +#if defined( __GNUC__ ) && ( __GNUC__ >= 4 ) +#define HAVE_VECTOR_SIZE 1 +#endif + + /* Global runtime options. */ struct hb_options_t diff --git a/src/hb-set-private.hh b/src/hb-set-private.hh index 227a5507a..7bb57d9f4 100644 --- a/src/hb-set-private.hh +++ b/src/hb-set-private.hh @@ -35,64 +35,6 @@ * hb_set_t */ -struct HbOpOr -{ - static const bool passthru_left = true; - static const bool passthru_right = true; - template static void process (T &o, const T &a, const T &b) { o = a | b; } -}; -struct HbOpAnd -{ - static const bool passthru_left = false; - static const bool passthru_right = false; - template static void process (T &o, const T &a, const T &b) { o = a & b; } -}; -struct HbOpMinus -{ - static const bool passthru_left = true; - static const bool passthru_right = false; - template static void process (T &o, const T &a, const T &b) { o = a & ~b; } -}; -struct HbOpXor -{ - static const bool passthru_left = true; - static const bool passthru_right = true; - template static void process (T &o, const T &a, const T &b) { o = a ^ b; } -}; - -template -struct vector_like_t -{ - elt_t& operator [] (unsigned int i) { return v[i]; } - const elt_t& operator [] (unsigned int i) const { return v[i]; } - - template - inline vector_like_t process (const vector_like_t &o) const - { - vector_like_t r; - for (unsigned int i = 0; i < ARRAY_LENGTH (v); i++) - Op::process (r.v[i], v[i], o.v[i]); - return r; - } - inline vector_like_t operator | (const vector_like_t &o) const - { return process (o); } - inline vector_like_t operator & (const vector_like_t &o) const - { return process (o); } - inline vector_like_t operator ^ (const vector_like_t &o) const - { return process (o); } - inline vector_like_t operator ~ () const - { - vector_like_t r; - for (unsigned int i = 0; i < ARRAY_LENGTH (v); i++) - r.v[i] = ~v[i]; - return r; - } - - private: - static_assert (byte_size / sizeof (elt_t) * sizeof (elt_t) == byte_size); - elt_t v[byte_size / sizeof (elt_t)]; -}; - struct hb_set_t { struct page_map_t @@ -194,10 +136,10 @@ struct hb_set_t typedef uint64_t elt_t; -#if 0 +#if HAVE_VECTOR_SIZE typedef elt_t vector_t __attribute__((vector_size (PAGE_BITS / 8))); #else - typedef vector_like_t vector_t; + typedef hb_vector_size_t vector_t; #endif vector_t v;