diff options
-rw-r--r-- | src/core/Sk4x.h | 23 | ||||
-rw-r--r-- | tests/PMFloatTest.cpp | 2 | ||||
-rw-r--r-- | tests/Sk2xTest.cpp | 6 | ||||
-rw-r--r-- | tests/Sk4xTest.cpp | 42 |
4 files changed, 46 insertions, 27 deletions
diff --git a/src/core/Sk4x.h b/src/core/Sk4x.h index d280c1b378..f006d70e24 100644 --- a/src/core/Sk4x.h +++ b/src/core/Sk4x.h @@ -52,6 +52,22 @@ public: Sk4x multiply(const Sk4x&) const; Sk4x divide(const Sk4x&) const; + // TODO: why doesn't MSVC like operator~() ? + //Sk4x operator ~() const { return this->bitNot(); } + Sk4x operator &(const Sk4x& o) const { return this->bitAnd(o); } + Sk4x operator |(const Sk4x& o) const { return this->bitOr (o); } + Sk4x operator +(const Sk4x& o) const { return this->add(o); } + Sk4x operator -(const Sk4x& o) const { return this->subtract(o); } + Sk4x operator *(const Sk4x& o) const { return this->multiply(o); } + Sk4x operator /(const Sk4x& o) const { return this->divide(o); } + + Sk4x& operator &=(const Sk4x& o) { return (*this = *this & o); } + Sk4x& operator |=(const Sk4x& o) { return (*this = *this | o); } + Sk4x& operator +=(const Sk4x& o) { return (*this = *this + o); } + Sk4x& operator -=(const Sk4x& o) { return (*this = *this - o); } + Sk4x& operator *=(const Sk4x& o) { return (*this = *this * o); } + Sk4x& operator /=(const Sk4x& o) { return (*this = *this / o); } + Sk4x rsqrt() const; // Approximate reciprocal sqrt(). Sk4x sqrt() const; // this->multiply(this->rsqrt()) may be faster, but less precise. @@ -62,6 +78,13 @@ public: Sk4i lessThanEqual(const Sk4x&) const; Sk4i greaterThanEqual(const Sk4x&) const; + Sk4i operator ==(const Sk4x& o) const { return this->equal(o); } + Sk4i operator !=(const Sk4x& o) const { return this->notEqual(o); } + Sk4i operator <(const Sk4x& o) const { return this->lessThan(o); } + Sk4i operator >(const Sk4x& o) const { return this->greaterThan(o); } + Sk4i operator <=(const Sk4x& o) const { return this->lessThanEqual(o); } + Sk4i operator >=(const Sk4x& o) const { return this->greaterThanEqual(o); } + static Sk4x Min(const Sk4x& a, const Sk4x& b); static Sk4x Max(const Sk4x& a, const Sk4x& b); diff --git a/tests/PMFloatTest.cpp b/tests/PMFloatTest.cpp index f370b39c66..5ce6e42854 100644 --- a/tests/PMFloatTest.cpp +++ b/tests/PMFloatTest.cpp @@ -24,7 +24,7 @@ DEF_TEST(SkPMFloat, r) { // Test SkPMFloat <-> Sk4f conversion. Sk4f fs = clamped; - SkPMFloat scaled = fs.multiply(Sk4f(0.25f)); + SkPMFloat scaled = fs * Sk4f(0.25f); REPORTER_ASSERT(r, SkScalarNearlyEqual(63.75f, scaled.a())); REPORTER_ASSERT(r, SkScalarNearlyEqual(38.25f, scaled.r())); REPORTER_ASSERT(r, SkScalarNearlyEqual( 0.25f, scaled.g())); diff --git a/tests/Sk2xTest.cpp b/tests/Sk2xTest.cpp index c0cfef36f1..4cecc0711a 100644 --- a/tests/Sk2xTest.cpp +++ b/tests/Sk2xTest.cpp @@ -41,10 +41,6 @@ static void test(skiatest::Reporter* r) { REPORTER_ASSERT(r, vals[0] == 4 && vals[1] == 4); // Math - REPORTER_ASSERT(r, eq(a.add(d), 6, 9)); - REPORTER_ASSERT(r, eq(a.subtract(d), 2, -1)); - REPORTER_ASSERT(r, eq(a.multiply(d), 8, 20)); - REPORTER_ASSERT(r, eq(a + d, 6, 9)); REPORTER_ASSERT(r, eq(a - d, 2, -1)); REPORTER_ASSERT(r, eq(a * d, 8, 20)); @@ -59,7 +55,7 @@ static void test(skiatest::Reporter* r) { a += d; a *= d; a -= d; - REPORTER_ASSERT(r, eq(a, 10,40)); + REPORTER_ASSERT(r, eq(a, 10, 40)); } DEF_TEST(Sk2f, r) { test< float>(r); } diff --git a/tests/Sk4xTest.cpp b/tests/Sk4xTest.cpp index 1cecd4f1fc..f25339bd94 100644 --- a/tests/Sk4xTest.cpp +++ b/tests/Sk4xTest.cpp @@ -66,24 +66,24 @@ DEF_TEST(Sk4x_Bits, r) { Sk4i a(2,3,4,5), b(1,3,5,7); - ASSERT_EQ(Sk4i(0,3,4,5), a.bitAnd(b)); - ASSERT_EQ(Sk4i(3,3,5,7), a.bitOr(b)); + ASSERT_EQ(Sk4i(0,3,4,5), a & b); + ASSERT_EQ(Sk4i(3,3,5,7), a | b); } DEF_TEST(Sk4x_Arith, r) { - ASSERT_EQ(Sk4f(4,6,8,10), Sk4f(1,2,3,4).add(Sk4f(3,4,5,6))); - ASSERT_EQ(Sk4f(-2,-2,-2,-2), Sk4f(1,2,3,4).subtract(Sk4f(3,4,5,6))); - ASSERT_EQ(Sk4f(3,8,15,24), Sk4f(1,2,3,4).multiply(Sk4f(3,4,5,6))); + ASSERT_EQ(Sk4f(4,6,8,10), Sk4f(1,2,3,4) + Sk4f(3,4,5,6)); + ASSERT_EQ(Sk4f(-2,-2,-2,-2), Sk4f(1,2,3,4) - Sk4f(3,4,5,6)); + ASSERT_EQ(Sk4f(3,8,15,24), Sk4f(1,2,3,4) * Sk4f(3,4,5,6)); float third = 1.0f/3.0f; - ASSERT_EQ(Sk4f(1*third, 0.5f, 0.6f, 2*third), Sk4f(1,2,3,4).divide(Sk4f(3,4,5,6))); - ASSERT_EQ(Sk4i(4,6,8,10), Sk4i(1,2,3,4).add(Sk4i(3,4,5,6))); - ASSERT_EQ(Sk4i(-2,-2,-2,-2), Sk4i(1,2,3,4).subtract(Sk4i(3,4,5,6))); - ASSERT_EQ(Sk4i(3,8,15,24), Sk4i(1,2,3,4).multiply(Sk4i(3,4,5,6))); + ASSERT_EQ(Sk4f(1*third, 0.5f, 0.6f, 2*third), Sk4f(1,2,3,4) / Sk4f(3,4,5,6)); + ASSERT_EQ(Sk4i(4,6,8,10), Sk4i(1,2,3,4) + Sk4i(3,4,5,6)); + ASSERT_EQ(Sk4i(-2,-2,-2,-2), Sk4i(1,2,3,4) - Sk4i(3,4,5,6)); + ASSERT_EQ(Sk4i(3,8,15,24), Sk4i(1,2,3,4) * Sk4i(3,4,5,6)); } -DEF_TEST(Sk4x_ImplicitPromotion, r) { - ASSERT_EQ(Sk4f(2,4,6,8), Sk4f(1,2,3,4).multiply(Sk4f(2.0f))); +DEF_TEST(Sk4x_ExplicitPromotion, r) { + ASSERT_EQ(Sk4f(2,4,6,8), Sk4f(1,2,3,4) * Sk4f(2.0f)); } DEF_TEST(Sk4x_Sqrt, r) { @@ -104,22 +104,22 @@ DEF_TEST(Sk4x_Comparison, r) { ASSERT_EQ(Sk4f(1,2,3,4), Sk4f(1,2,3,4)); ASSERT_NE(Sk4f(4,3,2,1), Sk4f(1,2,3,4)); - ASSERT_EQ(Sk4i(-1,-1,0,-1), Sk4f(1,2,5,4).equal(Sk4f(1,2,3,4))); + ASSERT_EQ(Sk4i(-1,-1,0,-1), Sk4f(1,2,5,4) == Sk4f(1,2,3,4)); - ASSERT_EQ(Sk4i(-1,-1,-1,-1), Sk4f(1,2,3,4).lessThan(Sk4f(2,3,4,5))); - ASSERT_EQ(Sk4i(-1,-1,-1,-1), Sk4f(1,2,3,4).lessThanEqual(Sk4f(2,3,4,5))); - ASSERT_EQ(Sk4i(0,0,0,0), Sk4f(1,2,3,4).greaterThan(Sk4f(2,3,4,5))); - ASSERT_EQ(Sk4i(0,0,0,0), Sk4f(1,2,3,4).greaterThanEqual(Sk4f(2,3,4,5))); + ASSERT_EQ(Sk4i(-1,-1,-1,-1), Sk4f(1,2,3,4) < Sk4f(2,3,4,5)); + ASSERT_EQ(Sk4i(-1,-1,-1,-1), Sk4f(1,2,3,4) <= Sk4f(2,3,4,5)); + ASSERT_EQ(Sk4i(0,0,0,0), Sk4f(1,2,3,4) > Sk4f(2,3,4,5)); + ASSERT_EQ(Sk4i(0,0,0,0), Sk4f(1,2,3,4) >= Sk4f(2,3,4,5)); ASSERT_EQ(Sk4i(1,2,3,4), Sk4i(1,2,3,4)); ASSERT_NE(Sk4i(4,3,2,1), Sk4i(1,2,3,4)); - ASSERT_EQ(Sk4i(-1,-1,0,-1), Sk4i(1,2,5,4).equal(Sk4i(1,2,3,4))); + ASSERT_EQ(Sk4i(-1,-1,0,-1), Sk4i(1,2,5,4) == Sk4i(1,2,3,4)); - ASSERT_EQ(Sk4i(-1,-1,-1,-1), Sk4i(1,2,3,4).lessThan(Sk4i(2,3,4,5))); - ASSERT_EQ(Sk4i(-1,-1,-1,-1), Sk4i(1,2,3,4).lessThanEqual(Sk4i(2,3,4,5))); - ASSERT_EQ(Sk4i(0,0,0,0), Sk4i(1,2,3,4).greaterThan(Sk4i(2,3,4,5))); - ASSERT_EQ(Sk4i(0,0,0,0), Sk4i(1,2,3,4).greaterThanEqual(Sk4i(2,3,4,5))); + ASSERT_EQ(Sk4i(-1,-1,-1,-1), Sk4i(1,2,3,4) < Sk4i(2,3,4,5)); + ASSERT_EQ(Sk4i(-1,-1,-1,-1), Sk4i(1,2,3,4) <= Sk4i(2,3,4,5)); + ASSERT_EQ(Sk4i(0,0,0,0), Sk4i(1,2,3,4) > Sk4i(2,3,4,5)); + ASSERT_EQ(Sk4i(0,0,0,0), Sk4i(1,2,3,4) >= Sk4i(2,3,4,5)); } DEF_TEST(Sk4x_MinMax, r) { |