{PIPE_FORMAT_R16_FLOAT, PACKED_1x16(0xffff), PACKED_1x16(0x7c00), UNPACKED_1x1( INF, 0.0, 0.0, 1.0)},
{PIPE_FORMAT_R16_FLOAT, PACKED_1x16(0xffff), PACKED_1x16(0xfc00), UNPACKED_1x1( -INF, 0.0, 0.0, 1.0)},
- {PIPE_FORMAT_R16_FLOAT, PACKED_1x16(0xffff), PACKED_1x16(0x8000), UNPACKED_1x1( 0.0, 0.0, 0.0, 1.0)},
- {PIPE_FORMAT_R16_FLOAT, PACKED_1x16(0xffff), PACKED_1x16(0x0000), UNPACKED_1x1( 0.0, 0.0, 0.0, 1.0)},
+ /* Zero, ignore sign */
+ {PIPE_FORMAT_R16_FLOAT, PACKED_1x16(0x7fff), PACKED_1x16(0x8000), UNPACKED_1x1( -0.0, 0.0, 0.0, 1.0)},
+ {PIPE_FORMAT_R16_FLOAT, PACKED_1x16(0x7fff), PACKED_1x16(0x0000), UNPACKED_1x1( 0.0, 0.0, 0.0, 1.0)},
+
{PIPE_FORMAT_R16_FLOAT, PACKED_1x16(0xffff), PACKED_1x16(0x3c00), UNPACKED_1x1( 1.0, 0.0, 0.0, 1.0)},
{PIPE_FORMAT_R16_FLOAT, PACKED_1x16(0xffff), PACKED_1x16(0xbc00), UNPACKED_1x1( -1.0, 0.0, 0.0, 1.0)},
match = TRUE;
for(k = 0; k < 4; ++k) {
int error = float_to_ubyte(test->unpacked[i][j][k]) - unpacked[k];
+
+ if (util_is_double_nan(test->unpacked[i][j][k]))
+ continue;
+
if (error < 0)
error = -error;
+
if (error > 1)
match = FALSE;
}
continue;
}
+
/*
* TODO: test more
*/
format_desc->block.width, format_desc->block.height);
success = TRUE;
- for (i = 0; i < format_desc->block.bits/8; ++i)
+ for (i = 0; i < format_desc->block.bits/8; ++i) {
if ((test->packed[i] & test->mask[i]) != (packed[i] & test->mask[i]))
success = FALSE;
+ }
+
+ /* Ignore NaN */
+ if (util_is_double_nan(test->unpacked[0][0][0]))
+ success = TRUE;
if (!success) {
print_packed(format_desc, "FAILED: ", packed, " obtained\n");
}
}
+ /* Ignore NaN */
+ if (util_is_double_nan(test->unpacked[0][0][0]))
+ success = TRUE;
+
if (!success) {
print_unpacked_rgba_8unorm(format_desc, "FAILED: ", unpacked, " obtained\n");
print_unpacked_rgba_8unorm(format_desc, " ", expected, " expected\n");
if ((test->packed[i] & test->mask[i]) != (packed[i] & test->mask[i]))
success = FALSE;
+ /* Ignore NaN */
+ if (util_is_double_nan(test->unpacked[0][0][0]))
+ success = TRUE;
+
+ /* Ignore failure cases due to unorm8 format */
+ if (test->unpacked[0][0][0] > 1.0f || test->unpacked[0][0][0] < 0.0f)
+ success = TRUE;
+
+ /* Multiple of 255 */
+ if ((test->unpacked[0][0][0] * 255.0) != (int)(test->unpacked[0][0][0] * 255.0))
+ success = TRUE;
+
if (!success) {
print_packed(format_desc, "FAILED: ", packed, " obtained\n");
print_packed(format_desc, " ", test->packed, " expected\n");
{
unsigned i;
unsigned roundtrip_fails = 0;
+
for(i = 0; i < 1 << 16; ++i)
{
uint16_t h = (uint16_t) i;
union fi f;
uint16_t rh;
- f.ui = util_half_to_floatui(h);
- rh = util_floatui_to_half(f.ui);
- if(h != rh)
- {
- printf("Roundtrip failed: %x -> %x = %f -> %x\n", h, f.ui, f.f, rh);
- ++roundtrip_fails;
+
+ f.f = util_half_to_float(h);
+ rh = util_float_to_half(f.f);
+
+ if (h != rh && !(util_is_half_nan(h) && util_is_half_nan(rh))) {
+ printf("Roundtrip failed: %x -> %x = %f -> %x\n", h, f.ui, f.f, rh);
+ ++roundtrip_fails;
}
}
printf("Failure! %u/65536 half floats failed a conversion to float and back.\n", roundtrip_fails);
else
printf("Success!\n");
+
return 0;
}