Changeset 870 for trunk/test
- Timestamp:
- Aug 28, 2011, 11:07:09 PM (11 years ago)
- Location:
- trunk/test
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/half.cpp
r868 r870 29 29 CPPUNIT_TEST(test_half_makeslow); 30 30 CPPUNIT_TEST(test_half_makefast); 31 CPPUNIT_TEST(test_half_isnan); 32 CPPUNIT_TEST(test_half_isinf); 33 CPPUNIT_TEST(test_half_isfinite); 34 CPPUNIT_TEST(test_half_isnormal); 35 CPPUNIT_TEST(test_half_classify); 31 36 CPPUNIT_TEST(test_half_to_float); 37 CPPUNIT_TEST(test_half_to_int); 32 38 CPPUNIT_TEST_SUITE_END(); 33 39 … … 53 59 void test_half_makeslow() 54 60 { 55 for (size_t i = 0; i < 8; i++)56 { 57 half a = half::makeslow( array1[i].f);58 uint16_t b = array1[i].x;61 for (size_t i = 0; i < sizeof(pairs) / sizeof(*pairs); i++) 62 { 63 half a = half::makeslow(pairs[i].f); 64 uint16_t b = pairs[i].x; 59 65 CPPUNIT_ASSERT_EQUAL(a.bits(), b); 60 66 } … … 63 69 void test_half_makefast() 64 70 { 65 for (size_t i = 0; i < 8; i++)66 { 67 half a = half::makefast( array1[i].f);68 uint16_t b = array1[i].x;71 for (size_t i = 0; i < sizeof(pairs) / sizeof(*pairs); i++) 72 { 73 half a = half::makefast(pairs[i].f); 74 uint16_t b = pairs[i].x; 69 75 CPPUNIT_ASSERT_EQUAL(a.bits(), b); 70 76 } 71 77 } 72 78 79 void test_half_isnan() 80 { 81 CPPUNIT_ASSERT(half::makebits(0x7c01).isnan()); 82 CPPUNIT_ASSERT(half::makebits(0xfc01).isnan()); 83 CPPUNIT_ASSERT(half::makebits(0x7e00).isnan()); 84 CPPUNIT_ASSERT(half::makebits(0xfe00).isnan()); 85 86 CPPUNIT_ASSERT(!half::makebits(0x7c00).isnan()); 87 CPPUNIT_ASSERT(!half::makebits(0xfc00).isnan()); 88 89 CPPUNIT_ASSERT(!half(0.0f).isnan()); 90 CPPUNIT_ASSERT(!half(-0.0f).isnan()); 91 CPPUNIT_ASSERT(!half(2.0f).isnan()); 92 CPPUNIT_ASSERT(!half(-2.0f).isnan()); 93 } 94 95 void test_half_isinf() 96 { 97 CPPUNIT_ASSERT(half(65536.0f).isinf()); 98 CPPUNIT_ASSERT(half(-65536.0f).isinf()); 99 100 CPPUNIT_ASSERT(!half(0.0f).isinf()); 101 CPPUNIT_ASSERT(!half(-0.0f).isinf()); 102 CPPUNIT_ASSERT(!half(65535.0f).isinf()); 103 CPPUNIT_ASSERT(!half(-65535.0f).isinf()); 104 105 CPPUNIT_ASSERT(half::makebits(0x7c00).isinf()); 106 CPPUNIT_ASSERT(half::makebits(0xfc00).isinf()); 107 108 CPPUNIT_ASSERT(!half::makebits(0x7e00).isinf()); 109 CPPUNIT_ASSERT(!half::makebits(0xfe00).isinf()); 110 } 111 112 void test_half_isfinite() 113 { 114 CPPUNIT_ASSERT(half(0.0f).isfinite()); 115 CPPUNIT_ASSERT(half(-0.0f).isfinite()); 116 CPPUNIT_ASSERT(half(65535.0f).isfinite()); 117 CPPUNIT_ASSERT(half(-65535.0f).isfinite()); 118 119 CPPUNIT_ASSERT(!half(65536.0f).isfinite()); 120 CPPUNIT_ASSERT(!half(-65536.0f).isfinite()); 121 122 CPPUNIT_ASSERT(!half::makebits(0x7c00).isfinite()); 123 CPPUNIT_ASSERT(!half::makebits(0xfc00).isfinite()); 124 125 CPPUNIT_ASSERT(!half::makebits(0x7e00).isfinite()); 126 CPPUNIT_ASSERT(!half::makebits(0xfe00).isfinite()); 127 } 128 129 void test_half_isnormal() 130 { 131 CPPUNIT_ASSERT(half(0.0f).isnormal()); 132 CPPUNIT_ASSERT(half(-0.0f).isnormal()); 133 CPPUNIT_ASSERT(half(65535.0f).isnormal()); 134 CPPUNIT_ASSERT(half(-65535.0f).isnormal()); 135 136 CPPUNIT_ASSERT(!half(65536.0f).isnormal()); 137 CPPUNIT_ASSERT(!half(-65536.0f).isnormal()); 138 139 CPPUNIT_ASSERT(!half::makebits(0x7c00).isnormal()); 140 CPPUNIT_ASSERT(!half::makebits(0xfc00).isnormal()); 141 142 CPPUNIT_ASSERT(!half::makebits(0x7e00).isnormal()); 143 CPPUNIT_ASSERT(!half::makebits(0xfe00).isnormal()); 144 } 145 146 void test_half_classify() 147 { 148 for (uint32_t i = 0; i < 0x10000; i++) 149 { 150 half h = half::makebits(i); 151 if (h.isnan()) 152 { 153 CPPUNIT_ASSERT(!h.isinf()); 154 CPPUNIT_ASSERT(!h.isnormal()); 155 CPPUNIT_ASSERT(!h.isfinite()); 156 } 157 else if (h.isinf()) 158 { 159 CPPUNIT_ASSERT(!h.isnormal()); 160 CPPUNIT_ASSERT(!h.isfinite()); 161 } 162 else 163 { 164 CPPUNIT_ASSERT(h.isfinite()); 165 } 166 } 167 } 168 73 169 void test_half_to_float() 74 170 { 75 #if 0 76 for (unsigned int i = 0; i < 0x10000; i++) 77 { 78 half a = half::makebits(i); 79 half b = half::makefast((float)a); 80 //CPPUNIT_ASSERT_EQUAL(a.bits(), b.bits()); 81 } 82 } 83 #endif 171 for (size_t i = 0; i < sizeof(pairs) / sizeof(*pairs); i++) 172 { 173 float a = (float)half::makebits(pairs[i].x); 174 float b = pairs[i].f; 175 CPPUNIT_ASSERT_EQUAL(a, b); 176 } 177 178 for (uint32_t i = 0; i < 0x10000; i++) 179 { 180 half h = half::makebits(i); 181 float f = (float)h; 182 half g = (half)f; 183 if (h.isnan()) 184 { 185 CPPUNIT_ASSERT(isnan(f)); 186 CPPUNIT_ASSERT(g.isnan()); 187 } 188 else 189 { 190 CPPUNIT_ASSERT(!isnan(f)); 191 CPPUNIT_ASSERT_EQUAL(g.bits(), h.bits()); 192 } 193 } 194 } 195 196 void test_half_to_int() 197 { 198 CPPUNIT_ASSERT_EQUAL((int)(half)(0.0f), 0); 199 CPPUNIT_ASSERT_EQUAL((int)(half)(-0.0f), 0); 200 CPPUNIT_ASSERT_EQUAL((int)(half)(0.9f), 0); 201 CPPUNIT_ASSERT_EQUAL((int)(half)(-0.9f), 0); 202 CPPUNIT_ASSERT_EQUAL((int)(half)(1.0f), 1); 203 CPPUNIT_ASSERT_EQUAL((int)(half)(-1.0f), -1); 204 CPPUNIT_ASSERT_EQUAL((int)(half)(1.9f), 1); 205 CPPUNIT_ASSERT_EQUAL((int)(half)(-1.9f), -1); 206 CPPUNIT_ASSERT_EQUAL((int)(half)(65504.0f), 65504); 207 CPPUNIT_ASSERT_EQUAL((int)(half)(-65504.0f), -65504); 84 208 } 85 209 … … 87 211 struct TestPair { float f; uint16_t x; }; 88 212 89 static TestPair const array1[];213 static TestPair const pairs[11]; 90 214 }; 91 215 92 HalfTest::TestPair const HalfTest:: array1[] =216 HalfTest::TestPair const HalfTest::pairs[] = 93 217 { 94 { 0.0f, 0x0000 }, 95 { -0.0f, 0x8000 }, 96 { 1.0f, 0x3c00 }, 97 { -1.0f, 0xbc00 }, 98 { 2.0f, 0x4000 }, 99 { 0.5f, 0x3800 }, 100 { 0.125f, 0x3000 }, 101 { 15.9375f, 0x4bf8 }, 218 /* All these values have exact half representations */ 219 { 0.0f, 0x0000 }, 220 { -0.0f, 0x8000 }, /* negative zero */ 221 { 1.0f, 0x3c00 }, 222 { -1.0f, 0xbc00 }, 223 { 2.0f, 0x4000 }, 224 { 0.5f, 0x3800 }, 225 { 0.125f, 0x3000 }, 226 { 15.9375f, 0x4bf8 }, 227 { 0x1.fp-10, 0x17c0 }, 228 { 0x1.fp-14, 0x07c0 }, /* denormal */ 229 { 0x1.fp-15, 0x03e0 }, /* denormal */ 102 230 }; 103 231 -
trunk/test/lol-bench.cpp
r868 r870 23 23 Timer timer; 24 24 25 float ftotal = 0.0f; 26 for (uint32_t i = 0; i < 0xffffffffu; i += 7) 27 { 28 union { float f; uint32_t x; } u; 29 u.x = i; 30 31 float h = (float)half::makefast(u.f); 32 ftotal += h; 33 } 34 Log::Info("time for makeslow: %f (hash %f)\n", timer.GetMs(), ftotal); 35 25 36 uint16_t total = 0; 26 for (uint32_t i = 0; i < 0xffffffffu; i ++)37 for (uint32_t i = 0; i < 0xffffffffu; i += 7) 27 38 { 28 39 union { float f; uint32_t x; } u; … … 34 45 Log::Info("time for makeslow: %f (hash %04x)\n", timer.GetMs(), total); 35 46 36 for (uint32_t i = 0; i < 0xffffffffu; i ++)47 for (uint32_t i = 0; i < 0xffffffffu; i += 7) 37 48 { 38 49 union { float f; uint32_t x; } u;
Note: See TracChangeset
for help on using the changeset viewer.