2 * Copyright © 2014 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 #include <gtest/gtest.h>
28 class vf_float_conversion_test
: public ::testing::Test
{
32 float vf_to_float
[128];
35 void vf_float_conversion_test::SetUp() {
36 /* 0 is special cased. */
39 for (int vf
= 1; vf
< 128; vf
++) {
40 int ebits
= (vf
>> 4) & 0x7;
43 float x
= 1.0f
+ mbits
/ 16.0f
;
46 vf_to_float
[vf
] = ldexpf(x
, exp
);
63 TEST_F(vf_float_conversion_test
, test_vf_to_float
)
65 for (int vf
= 0; vf
< 256; vf
++) {
66 float expected
= vf_to_float
[vf
% 128];
70 EXPECT_EQ(f2u(expected
), f2u(brw_vf_to_float(vf
)));
74 TEST_F(vf_float_conversion_test
, test_float_to_vf
)
76 for (int vf
= 0; vf
< 256; vf
++) {
77 float f
= vf_to_float
[vf
% 128];
81 EXPECT_EQ(vf
, brw_float_to_vf(f
));
85 TEST_F(vf_float_conversion_test
, test_special_case_0
)
87 /* ±0.0f are special cased to the VFs that would otherwise correspond
88 * to ±0.125f. Make sure we can't convert these values to VF.
90 EXPECT_EQ(brw_float_to_vf(+0.125f
), -1);
91 EXPECT_EQ(brw_float_to_vf(-0.125f
), -1);
93 EXPECT_EQ(f2u(brw_vf_to_float(brw_float_to_vf(+0.0f
))), f2u(+0.0f
));
94 EXPECT_EQ(f2u(brw_vf_to_float(brw_float_to_vf(-0.0f
))), f2u(-0.0f
));
97 TEST_F(vf_float_conversion_test
, test_nonrepresentable_float_input
)
99 EXPECT_EQ(brw_float_to_vf(+32.0f
), -1);
100 EXPECT_EQ(brw_float_to_vf(-32.0f
), -1);
102 EXPECT_EQ(brw_float_to_vf(+16.5f
), -1);
103 EXPECT_EQ(brw_float_to_vf(-16.5f
), -1);
105 EXPECT_EQ(brw_float_to_vf(+8.25f
), -1);
106 EXPECT_EQ(brw_float_to_vf(-8.25f
), -1);
108 EXPECT_EQ(brw_float_to_vf(+4.125f
), -1);
109 EXPECT_EQ(brw_float_to_vf(-4.125f
), -1);