2014-11-11 14:16:42 +00:00
|
|
|
#include "Test.h"
|
|
|
|
#include "Sk4x.h"
|
|
|
|
|
|
|
|
#define ASSERT_EQ(a, b) REPORTER_ASSERT(r, a.equal(b).allTrue())
|
|
|
|
#define ASSERT_NE(a, b) REPORTER_ASSERT(r, a.notEqual(b).allTrue())
|
|
|
|
|
|
|
|
DEF_TEST(Sk4x_Construction, r) {
|
|
|
|
Sk4f uninitialized;
|
|
|
|
Sk4f zero(0,0,0,0);
|
|
|
|
Sk4f foo(1,2,3,4),
|
|
|
|
bar(foo),
|
|
|
|
baz = bar;
|
|
|
|
ASSERT_EQ(foo, bar);
|
|
|
|
ASSERT_EQ(bar, baz);
|
|
|
|
ASSERT_EQ(baz, foo);
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_TEST(Sk4x_LoadStore, r) {
|
|
|
|
// fs will be 16-byte aligned, fs+1 not.
|
|
|
|
float fs[] = { 5,6,7,8,9 };
|
|
|
|
|
|
|
|
Sk4f foo = Sk4f::Load(fs);
|
|
|
|
Sk4f bar = Sk4f::LoadAligned(fs);
|
|
|
|
ASSERT_EQ(foo, bar);
|
|
|
|
|
|
|
|
foo = Sk4f::Load(fs+1);
|
|
|
|
ASSERT_NE(foo, bar);
|
|
|
|
|
|
|
|
foo.storeAligned(fs);
|
|
|
|
bar.store(fs+1);
|
|
|
|
REPORTER_ASSERT(r, fs[0] == 6 &&
|
|
|
|
fs[1] == 5 &&
|
|
|
|
fs[2] == 6 &&
|
|
|
|
fs[3] == 7 &&
|
|
|
|
fs[4] == 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_TEST(Sk4x_Conversions, r) {
|
|
|
|
// Assuming IEEE floats.
|
|
|
|
Sk4f zerof(0,0,0,0);
|
|
|
|
Sk4i zeroi(0,0,0,0);
|
|
|
|
ASSERT_EQ(zeroi, zerof.cast<Sk4i>());
|
|
|
|
ASSERT_EQ(zeroi, zerof.reinterpret<Sk4i>());
|
2014-11-12 15:27:01 +00:00
|
|
|
ASSERT_EQ(zerof, zeroi.cast<Sk4f>());
|
|
|
|
ASSERT_EQ(zerof, zeroi.reinterpret<Sk4f>());
|
2014-11-11 14:16:42 +00:00
|
|
|
|
|
|
|
Sk4f twof(2,2,2,2);
|
|
|
|
Sk4i twoi(2,2,2,2);
|
|
|
|
ASSERT_EQ(twoi, twof.cast<Sk4i>());
|
|
|
|
ASSERT_NE(twoi, twof.reinterpret<Sk4i>());
|
2014-11-12 15:27:01 +00:00
|
|
|
ASSERT_EQ(twof, twoi.cast<Sk4f>());
|
|
|
|
ASSERT_NE(twof, twoi.reinterpret<Sk4f>());
|
2014-11-11 14:16:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DEF_TEST(Sk4x_Bits, r) {
|
|
|
|
ASSERT_EQ(Sk4i(0,0,0,0).bitNot(), Sk4i(-1,-1,-1,-1));
|
|
|
|
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
|
|
|
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)));
|
|
|
|
|
|
|
|
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)));
|
2014-11-12 15:27:01 +00:00
|
|
|
|
|
|
|
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)));
|
2014-11-11 14:16:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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,-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)));
|
2014-11-12 15:27:01 +00:00
|
|
|
|
|
|
|
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,-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)));
|
2014-11-11 14:16:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DEF_TEST(Sk4x_MinMax, r) {
|
|
|
|
ASSERT_EQ(Sk4f(1,2,2,1), Sk4f::Min(Sk4f(1,2,3,4), Sk4f(4,3,2,1)));
|
|
|
|
ASSERT_EQ(Sk4f(4,3,3,4), Sk4f::Max(Sk4f(1,2,3,4), Sk4f(4,3,2,1)));
|
2014-11-12 15:27:01 +00:00
|
|
|
ASSERT_EQ(Sk4i(1,2,2,1), Sk4i::Min(Sk4i(1,2,3,4), Sk4i(4,3,2,1)));
|
|
|
|
ASSERT_EQ(Sk4i(4,3,3,4), Sk4i::Max(Sk4i(1,2,3,4), Sk4i(4,3,2,1)));
|
2014-11-11 14:16:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DEF_TEST(Sk4x_Swizzle, r) {
|
|
|
|
ASSERT_EQ(Sk4f(3,4,1,2), Sk4f(1,2,3,4).zwxy());
|
|
|
|
ASSERT_EQ(Sk4f(1,2,5,6), Sk4f::XYAB(Sk4f(1,2,3,4), Sk4f(5,6,7,8)));
|
|
|
|
ASSERT_EQ(Sk4f(3,4,7,8), Sk4f::ZWCD(Sk4f(1,2,3,4), Sk4f(5,6,7,8)));
|
2014-11-12 15:27:01 +00:00
|
|
|
ASSERT_EQ(Sk4i(3,4,1,2), Sk4i(1,2,3,4).zwxy());
|
|
|
|
ASSERT_EQ(Sk4i(1,2,5,6), Sk4i::XYAB(Sk4i(1,2,3,4), Sk4i(5,6,7,8)));
|
|
|
|
ASSERT_EQ(Sk4i(3,4,7,8), Sk4i::ZWCD(Sk4i(1,2,3,4), Sk4i(5,6,7,8)));
|
2014-11-11 14:16:42 +00:00
|
|
|
}
|