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;
47 value
+= mbits
/ 16.0f
;
51 vf_to_float
[vf
] = value
;
68 TEST_F(vf_float_conversion_test
, test_vf_to_float
)
70 for (int vf
= 0; vf
< 256; vf
++) {
71 float expected
= vf_to_float
[vf
% 128];
75 EXPECT_EQ(f2u(expected
), f2u(brw_vf_to_float(vf
)));
79 TEST_F(vf_float_conversion_test
, test_float_to_vf
)
81 for (int vf
= 0; vf
< 256; vf
++) {
82 float f
= vf_to_float
[vf
% 128];
86 EXPECT_EQ(vf
, brw_float_to_vf(f
));
90 TEST_F(vf_float_conversion_test
, test_special_case_0
)
92 /* ±0.0f are special cased to the VFs that would otherwise correspond
93 * to ±0.125f. Make sure we can't convert these values to VF.
95 EXPECT_EQ(brw_float_to_vf(+0.125f
), -1);
96 EXPECT_EQ(brw_float_to_vf(-0.125f
), -1);
98 EXPECT_EQ(f2u(brw_vf_to_float(brw_float_to_vf(+0.0f
))), f2u(+0.0f
));
99 EXPECT_EQ(f2u(brw_vf_to_float(brw_float_to_vf(-0.0f
))), f2u(-0.0f
));