| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238 |
- /*
- * Copyright 2010-2013 Branimir Karadzic. All rights reserved.
- * License: http://www.opensource.org/licenses/BSD-2-Clause
- */
- #include "test.h"
- #include <bx/float4_t.h>
- #include <string.h>
- using namespace bx;
- union float4_cast
- {
- bx::float4_t f4;
- float f[4];
- uint32_t ui[4];
- int32_t i[4];
- char c[16];
- };
- void float4_check_int32(const char* _str, bx::float4_t _a, int32_t _0, int32_t _1, int32_t _2, int32_t _3)
- {
- float4_cast c; c.f4 = _a;
- DBG("%s (%d, %d, %d, %d) == (%d, %d, %d, %d)"
- , _str
- , c.i[0], c.i[1], c.i[2], c.i[3]
- , _0, _1, _2, _3
- );
- CHECK_EQUAL(c.i[0], _0);
- CHECK_EQUAL(c.i[1], _1);
- CHECK_EQUAL(c.i[2], _2);
- CHECK_EQUAL(c.i[3], _3);
- }
- void float4_check_uint32(const char* _str, bx::float4_t _a, uint32_t _0, uint32_t _1, uint32_t _2, uint32_t _3)
- {
- float4_cast c; c.f4 = _a;
- DBG("%s (0x%08x, 0x%08x, 0x%08x, 0x%08x) == (0x%08x, 0x%08x, 0x%08x, 0x%08x)"
- , _str
- , c.ui[0], c.ui[1], c.ui[2], c.ui[3]
- , _0, _1, _2, _3
- );
- CHECK_EQUAL(c.ui[0], _0);
- CHECK_EQUAL(c.ui[1], _1);
- CHECK_EQUAL(c.ui[2], _2);
- CHECK_EQUAL(c.ui[3], _3);
- }
- void float4_check_float(const char* _str, bx::float4_t _a, float _0, float _1, float _2, float _3)
- {
- float4_cast c; c.f4 = _a;
- DBG("%s (%f, %f, %f, %f) == (%f, %f, %f, %f)"
- , _str
- , c.f[0], c.f[1], c.f[2], c.f[3]
- , _0, _1, _2, _3
- );
- CHECK_EQUAL(c.f[0], _0);
- CHECK_EQUAL(c.f[1], _1);
- CHECK_EQUAL(c.f[2], _2);
- CHECK_EQUAL(c.f[3], _3);
- }
- void float4_check_string(const char* _str, bx::float4_t _a)
- {
- float4_cast c; c.f4 = _a;
- const char test[5] = { c.c[0], c.c[4], c.c[8], c.c[12], '\0' };
- DBG("%s %s", _str, test);
- CHECK(0 == strcmp(_str, test) );
- }
- TEST(float4_swizzle)
- {
- const float4_t xyzw = float4_ild(0x78787878, 0x79797979, 0x7a7a7a7a, 0x77777777);
- #define ELEMx 0
- #define ELEMy 1
- #define ELEMz 2
- #define ELEMw 3
- #define IMPLEMENT_SWIZZLE(_x, _y, _z, _w) \
- float4_check_string("" #_x #_y #_z #_w "", float4_swiz_##_x##_y##_z##_w(xyzw) ); \
- #include <bx/float4_swizzle.inl>
- #undef IMPLEMENT_SWIZZLE
- #undef ELEMw
- #undef ELEMz
- #undef ELEMy
- #undef ELEMx
- }
- TEST(float4_shuffle)
- {
- const float4_t xyzw = float4_ild(0x78787878, 0x79797979, 0x7a7a7a7a, 0x77777777);
- const float4_t ABCD = float4_ild(0x41414141, 0x42424242, 0x43434343, 0x44444444);
- float4_check_string("xyAB", float4_shuf_xyAB(xyzw, ABCD) );
- float4_check_string("ABxy", float4_shuf_ABxy(xyzw, ABCD) );
- float4_check_string("zwCD", float4_shuf_zwCD(xyzw, ABCD) );
- float4_check_string("CDzw", float4_shuf_CDzw(xyzw, ABCD) );
- float4_check_string("xAyB", float4_shuf_xAyB(xyzw, ABCD) );
- float4_check_string("zCwD", float4_shuf_zCwD(xyzw, ABCD) );
- float4_check_string("xAzC", float4_shuf_xAzC(xyzw, ABCD) );
- float4_check_string("yBwD", float4_shuf_yBwD(xyzw, ABCD) );
- float4_check_string("CzDw", float4_shuf_CzDw(xyzw, ABCD) );
- }
- TEST(float4_compare)
- {
- float4_check_uint32("cmpeq"
- , float4_cmpeq(float4_ld(1.0f, 2.0f, 3.0f, 4.0f), float4_ld(0.0f, 2.0f, 0.0f, 3.0f) )
- , 0, -1, 0, 0
- );
- float4_check_uint32("cmplt"
- , float4_cmplt(float4_ld(1.0f, 2.0f, 3.0f, 4.0f), float4_ld(0.0f, 2.0f, 0.0f, 3.0f) )
- , 0, 0, 0, 0
- );
- float4_check_uint32("cmple"
- , float4_cmple(float4_ld(1.0f, 2.0f, 3.0f, 4.0f), float4_ld(0.0f, 2.0f, 0.0f, 3.0f) )
- , 0, -1, 0, 0
- );
- float4_check_uint32("cmpgt"
- , float4_cmpgt(float4_ld(1.0f, 2.0f, 3.0f, 4.0f), float4_ld(0.0f, 2.0f, 0.0f, 3.0f) )
- , -1, 0, -1, -1
- );
- float4_check_uint32("cmpge"
- , float4_cmpge(float4_ld(1.0f, 2.0f, 3.0f, 4.0f), float4_ld(0.0f, 2.0f, 0.0f, 3.0f) )
- , -1, -1, -1, -1
- );
- float4_check_uint32("icmpeq"
- , float4_icmpeq(float4_ild(0, 1, 2, 3), float4_ild(0, -2, 1, 3) )
- , -1, 0, 0, -1
- );
- float4_check_uint32("icmplt"
- , float4_icmplt(float4_ild(0, 1, 2, 3), float4_ild(0, -2, 1, 3) )
- , 0, 0, 0, 0
- );
- float4_check_uint32("icmpgt"
- , float4_icmpgt(float4_ild(0, 1, 2, 3), float4_ild(0, -2, 1, 3) )
- , 0, -1, -1, 0
- );
- }
- TEST(float4_load)
- {
- float4_check_float("ld"
- , float4_ld(0.0f, 1.0f, 2.0f, 3.0f)
- , 0.0f, 1.0f, 2.0f, 3.0f
- );
- float4_check_int32("ild"
- , float4_ild(-1, 0, 1, 2)
- , -1, 0, 1, 2
- );
- float4_check_int32("ild"
- , float4_ild(-1, -2, -3, -4)
- , -1, -2, -3, -4
- );
- float4_check_uint32("zero", float4_zero()
- , 0, 0, 0, 0
- );
- float4_check_uint32("isplat", float4_isplat(0x80000001)
- , 0x80000001, 0x80000001, 0x80000001, 0x80000001
- );
- float4_check_float("isplat", float4_splat(1.0f)
- , 1.0f, 1.0f, 1.0f, 1.0f
- );
- }
- TEST(float4)
- {
- const float4_t isplat = float4_isplat(0x80000001);
- float4_check_uint32("sll"
- , float4_sll(isplat, 1)
- , 0x00000002, 0x00000002, 0x00000002, 0x00000002
- );
- float4_check_uint32("srl"
- , float4_srl(isplat, 1)
- , 0x40000000, 0x40000000, 0x40000000, 0x40000000
- );
- float4_check_uint32("sra"
- , float4_sra(isplat, 1)
- , 0xc0000000, 0xc0000000, 0xc0000000, 0xc0000000
- );
- float4_check_uint32("and"
- , float4_and(float4_isplat(0x55555555), float4_isplat(0xaaaaaaaa) )
- , 0, 0, 0, 0
- );
- float4_check_uint32("or "
- , float4_or(float4_isplat(0x55555555), float4_isplat(0xaaaaaaaa) )
- , -1, -1, -1, -1
- );
- float4_check_uint32("xor"
- , float4_or(float4_isplat(0x55555555), float4_isplat(0xaaaaaaaa) )
- , -1, -1, -1, -1
- );
- float4_check_int32("imin"
- , float4_imin(float4_ild(0, 1, 2, 3), float4_ild(-1, 2, -2, 1) )
- , -1, 1, -2, 1
- );
- float4_check_float("min"
- , float4_min(float4_ld(0.0f, 1.0f, 2.0f, 3.0f), float4_ld(-1.0f, 2.0f, -2.0f, 1.0f) )
- , -1.0f, 1.0f, -2.0f, 1.0f
- );
- float4_check_int32("imax"
- , float4_imax(float4_ild(0, 1, 2, 3), float4_ild(-1, 2, -2, 1) )
- , 0, 2, 2, 3
- );
- float4_check_float("max"
- , float4_max(float4_ld(0.0f, 1.0f, 2.0f, 3.0f), float4_ld(-1.0f, 2.0f, -2.0f, 1.0f) )
- , 0.0f, 2.0f, 2.0f, 3.0f
- );
- }
|