Add hb_bitwise_neg

pull/1783/head
Behdad Esfahbod 5 years ago
parent 7cf9169078
commit 24060d3aa7
  1. 33
      src/hb-algs.hh

@ -940,6 +940,12 @@ struct hb_bitwise_sub
operator () (const T &a, const T &b) const HB_AUTO_RETURN (a & ~b) operator () (const T &a, const T &b) const HB_AUTO_RETURN (a & ~b)
} }
HB_FUNCOBJ (hb_bitwise_sub); HB_FUNCOBJ (hb_bitwise_sub);
struct
{
template <typename T> auto
operator () (const T &a) const HB_AUTO_RETURN (~a)
}
HB_FUNCOBJ (hb_bitwise_neg);
struct struct
{ HB_PARTIALIZE(2); { HB_PARTIALIZE(2);
@ -999,38 +1005,41 @@ struct hb_vector_size_t
void clear (unsigned char v = 0) { memset (this, v, sizeof (*this)); } void clear (unsigned char v = 0) { memset (this, v, sizeof (*this)); }
template <typename Op> template <typename Op>
hb_vector_size_t process (const Op& op, const hb_vector_size_t &o) const hb_vector_size_t process (const Op& op) const
{ {
hb_vector_size_t r; hb_vector_size_t r;
#if HB_VECTOR_SIZE #if HB_VECTOR_SIZE
if (HB_VECTOR_SIZE && 0 == (byte_size * 8) % HB_VECTOR_SIZE) if (HB_VECTOR_SIZE && 0 == (byte_size * 8) % HB_VECTOR_SIZE)
for (unsigned int i = 0; i < ARRAY_LENGTH (u.vec); i++) for (unsigned int i = 0; i < ARRAY_LENGTH (u.vec); i++)
r.u.vec[i] = op (u.vec[i], o.u.vec[i]); r.u.vec[i] = op (u.vec[i]);
else else
#endif #endif
for (unsigned int i = 0; i < ARRAY_LENGTH (u.v); i++) for (unsigned int i = 0; i < ARRAY_LENGTH (u.v); i++)
r.u.v[i] = op (u.v[i], o.u.v[i]); r.u.v[i] = op (u.v[i]);
return r; return r;
} }
hb_vector_size_t operator | (const hb_vector_size_t &o) const template <typename Op>
{ return process (hb_bitwise_or, o); } hb_vector_size_t process (const Op& op, const hb_vector_size_t &o) const
hb_vector_size_t operator & (const hb_vector_size_t &o) const
{ return process (hb_bitwise_and, o); }
hb_vector_size_t operator ^ (const hb_vector_size_t &o) const
{ return process (hb_bitwise_xor, o); }
hb_vector_size_t operator ~ () const
{ {
hb_vector_size_t r; hb_vector_size_t r;
#if HB_VECTOR_SIZE #if HB_VECTOR_SIZE
if (HB_VECTOR_SIZE && 0 == (byte_size * 8) % HB_VECTOR_SIZE) if (HB_VECTOR_SIZE && 0 == (byte_size * 8) % HB_VECTOR_SIZE)
for (unsigned int i = 0; i < ARRAY_LENGTH (u.vec); i++) for (unsigned int i = 0; i < ARRAY_LENGTH (u.vec); i++)
r.u.vec[i] = ~u.vec[i]; r.u.vec[i] = op (u.vec[i], o.u.vec[i]);
else else
#endif #endif
for (unsigned int i = 0; i < ARRAY_LENGTH (u.v); i++) for (unsigned int i = 0; i < ARRAY_LENGTH (u.v); i++)
r.u.v[i] = ~u.v[i]; r.u.v[i] = op (u.v[i], o.u.v[i]);
return r; return r;
} }
hb_vector_size_t operator | (const hb_vector_size_t &o) const
{ return process (hb_bitwise_or, o); }
hb_vector_size_t operator & (const hb_vector_size_t &o) const
{ return process (hb_bitwise_and, o); }
hb_vector_size_t operator ^ (const hb_vector_size_t &o) const
{ return process (hb_bitwise_xor, o); }
hb_vector_size_t operator ~ () const
{ return process (hb_bitwise_neg); }
private: private:
static_assert (byte_size / sizeof (elt_t) * sizeof (elt_t) == byte_size, ""); static_assert (byte_size / sizeof (elt_t) * sizeof (elt_t) == byte_size, "");

Loading…
Cancel
Save