xref: /aosp_15_r20/external/mesa3d/src/compiler/nir/tests/lower_alu_width_tests.cpp (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * Copyright © 2023 Valve Corporation
3  *
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:
10  *
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
13  * Software.
14  *
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
21  * DEALINGS IN THE SOFTWARE.
22  */
23 
24 #include "nir_test.h"
25 
26 namespace {
27 
28 class nir_lower_alu_width_test : public nir_test {
29 protected:
nir_lower_alu_width_test()30    nir_lower_alu_width_test()
31       : nir_test::nir_test("nir_lower_alu_width_test")
32    {
33    }
34 };
35 
TEST_F(nir_lower_alu_width_test,fdot_order)36 TEST_F(nir_lower_alu_width_test, fdot_order)
37 {
38    nir_variable *res_var = nir_local_variable_create(b->impl, glsl_float_type(), "res");
39 
40    b->exact = true;
41 
42    /* If this isn't done in xyz order, it evaluates to infinity. */
43    nir_def *val = nir_fdot(
44       b, nir_imm_vec3(b, 1.7014118346046923e+38, 1.7014118346046923e+38, 8.507059173023462e+37),
45       nir_imm_vec3(b, -0.5, 1.5, 1.0));
46    nir_intrinsic_instr *store =
47       nir_build_store_deref(b, &nir_build_deref_var(b, res_var)->def, val);
48 
49    nir_lower_alu_width(b->shader, NULL, NULL);
50    nir_opt_constant_folding(b->shader);
51 
52    ASSERT_TRUE(nir_src_is_const(store->src[1]));
53    EXPECT_EQ(nir_src_as_float(store->src[1]), 2.5521177519070385e+38);
54 }
55 
56 }
57