1bf215546Sopenharmony_ci/* 2bf215546Sopenharmony_ci * Copyright © 2013 Intel Corporation 3bf215546Sopenharmony_ci * 4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 5bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 6bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation 7bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 9bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 10bf215546Sopenharmony_ci * 11bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next 12bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the 13bf215546Sopenharmony_ci * Software. 14bf215546Sopenharmony_ci * 15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20bf215546Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 21bf215546Sopenharmony_ci * DEALINGS IN THE SOFTWARE. 22bf215546Sopenharmony_ci */ 23bf215546Sopenharmony_ci#include <gtest/gtest.h> 24bf215546Sopenharmony_ci#include "util/compiler.h" 25bf215546Sopenharmony_ci#include "main/macros.h" 26bf215546Sopenharmony_ci#include "ir.h" 27bf215546Sopenharmony_ci#include "ir_builder.h" 28bf215546Sopenharmony_ci 29bf215546Sopenharmony_ciusing namespace ir_builder; 30bf215546Sopenharmony_ci 31bf215546Sopenharmony_cinamespace lower_64bit { 32bf215546Sopenharmony_civoid expand_source(ir_factory &body, 33bf215546Sopenharmony_ci ir_rvalue *val, 34bf215546Sopenharmony_ci ir_variable **expanded_src); 35bf215546Sopenharmony_ci 36bf215546Sopenharmony_ciir_dereference_variable *compact_destination(ir_factory &body, 37bf215546Sopenharmony_ci const glsl_type *type, 38bf215546Sopenharmony_ci ir_variable *result[4]); 39bf215546Sopenharmony_ci 40bf215546Sopenharmony_ciir_rvalue *lower_op_to_function_call(ir_instruction *base_ir, 41bf215546Sopenharmony_ci ir_expression *ir, 42bf215546Sopenharmony_ci ir_function_signature *callee); 43bf215546Sopenharmony_ci}; 44bf215546Sopenharmony_ci 45bf215546Sopenharmony_ciclass expand_source : public ::testing::Test { 46bf215546Sopenharmony_cipublic: 47bf215546Sopenharmony_ci virtual void SetUp(); 48bf215546Sopenharmony_ci virtual void TearDown(); 49bf215546Sopenharmony_ci 50bf215546Sopenharmony_ci exec_list instructions; 51bf215546Sopenharmony_ci ir_factory *body; 52bf215546Sopenharmony_ci ir_variable *expanded_src[4]; 53bf215546Sopenharmony_ci void *mem_ctx; 54bf215546Sopenharmony_ci}; 55bf215546Sopenharmony_ci 56bf215546Sopenharmony_civoid 57bf215546Sopenharmony_ciexpand_source::SetUp() 58bf215546Sopenharmony_ci{ 59bf215546Sopenharmony_ci glsl_type_singleton_init_or_ref(); 60bf215546Sopenharmony_ci 61bf215546Sopenharmony_ci mem_ctx = ralloc_context(NULL); 62bf215546Sopenharmony_ci 63bf215546Sopenharmony_ci memset(expanded_src, 0, sizeof(expanded_src)); 64bf215546Sopenharmony_ci instructions.make_empty(); 65bf215546Sopenharmony_ci body = new ir_factory(&instructions, mem_ctx); 66bf215546Sopenharmony_ci} 67bf215546Sopenharmony_ci 68bf215546Sopenharmony_civoid 69bf215546Sopenharmony_ciexpand_source::TearDown() 70bf215546Sopenharmony_ci{ 71bf215546Sopenharmony_ci delete body; 72bf215546Sopenharmony_ci body = NULL; 73bf215546Sopenharmony_ci 74bf215546Sopenharmony_ci ralloc_free(mem_ctx); 75bf215546Sopenharmony_ci mem_ctx = NULL; 76bf215546Sopenharmony_ci 77bf215546Sopenharmony_ci glsl_type_singleton_decref(); 78bf215546Sopenharmony_ci} 79bf215546Sopenharmony_ci 80bf215546Sopenharmony_cistatic ir_dereference_variable * 81bf215546Sopenharmony_cicreate_variable(void *mem_ctx, const glsl_type *type) 82bf215546Sopenharmony_ci{ 83bf215546Sopenharmony_ci ir_variable *var = new(mem_ctx) ir_variable(type, 84bf215546Sopenharmony_ci "variable", 85bf215546Sopenharmony_ci ir_var_temporary); 86bf215546Sopenharmony_ci 87bf215546Sopenharmony_ci return new(mem_ctx) ir_dereference_variable(var); 88bf215546Sopenharmony_ci} 89bf215546Sopenharmony_ci 90bf215546Sopenharmony_cistatic ir_expression * 91bf215546Sopenharmony_cicreate_expression(void *mem_ctx, const glsl_type *type) 92bf215546Sopenharmony_ci{ 93bf215546Sopenharmony_ci return new(mem_ctx) ir_expression(ir_unop_neg, 94bf215546Sopenharmony_ci create_variable(mem_ctx, type)); 95bf215546Sopenharmony_ci} 96bf215546Sopenharmony_ci 97bf215546Sopenharmony_cistatic void 98bf215546Sopenharmony_cicheck_expanded_source(const glsl_type *type, 99bf215546Sopenharmony_ci ir_variable *expanded_src[4]) 100bf215546Sopenharmony_ci{ 101bf215546Sopenharmony_ci const glsl_type *const expanded_type = 102bf215546Sopenharmony_ci type->base_type == GLSL_TYPE_UINT64 103bf215546Sopenharmony_ci ? glsl_type::uvec2_type :glsl_type::ivec2_type; 104bf215546Sopenharmony_ci 105bf215546Sopenharmony_ci for (int i = 0; i < type->vector_elements; i++) { 106bf215546Sopenharmony_ci EXPECT_EQ(expanded_type, expanded_src[i]->type); 107bf215546Sopenharmony_ci 108bf215546Sopenharmony_ci /* All elements that are part of the vector must be unique. */ 109bf215546Sopenharmony_ci for (int j = i - 1; j >= 0; j--) { 110bf215546Sopenharmony_ci EXPECT_NE(expanded_src[i], expanded_src[j]) 111bf215546Sopenharmony_ci << " Element " << i << " is the same as element " << j; 112bf215546Sopenharmony_ci } 113bf215546Sopenharmony_ci } 114bf215546Sopenharmony_ci 115bf215546Sopenharmony_ci /* All elements that are not part of the vector must be the same as element 116bf215546Sopenharmony_ci * 0. This is primarily for scalars (where every element is the same). 117bf215546Sopenharmony_ci */ 118bf215546Sopenharmony_ci for (int i = type->vector_elements; i < 4; i++) { 119bf215546Sopenharmony_ci EXPECT_EQ(expanded_src[0], expanded_src[i]) 120bf215546Sopenharmony_ci << " Element " << i << " should be the same as element 0"; 121bf215546Sopenharmony_ci } 122bf215546Sopenharmony_ci} 123bf215546Sopenharmony_ci 124bf215546Sopenharmony_cistatic void 125bf215546Sopenharmony_cicheck_instructions(exec_list *instructions, 126bf215546Sopenharmony_ci const glsl_type *type, 127bf215546Sopenharmony_ci const ir_instruction *source) 128bf215546Sopenharmony_ci{ 129bf215546Sopenharmony_ci const glsl_type *const expanded_type = 130bf215546Sopenharmony_ci type->base_type == GLSL_TYPE_UINT64 131bf215546Sopenharmony_ci ? glsl_type::uvec2_type : glsl_type::ivec2_type; 132bf215546Sopenharmony_ci 133bf215546Sopenharmony_ci const ir_expression_operation unpack_opcode = 134bf215546Sopenharmony_ci type->base_type == GLSL_TYPE_UINT64 135bf215546Sopenharmony_ci ? ir_unop_unpack_uint_2x32 : ir_unop_unpack_int_2x32; 136bf215546Sopenharmony_ci 137bf215546Sopenharmony_ci ir_instruction *ir; 138bf215546Sopenharmony_ci 139bf215546Sopenharmony_ci /* The instruction list should contain IR to represent: 140bf215546Sopenharmony_ci * 141bf215546Sopenharmony_ci * type tmp1; 142bf215546Sopenharmony_ci * tmp1 = source; 143bf215546Sopenharmony_ci * uvec2 tmp2; 144bf215546Sopenharmony_ci * tmp2 = unpackUint2x32(tmp1.x); 145bf215546Sopenharmony_ci * uvec2 tmp3; 146bf215546Sopenharmony_ci * tmp3 = unpackUint2x32(tmp1.y); 147bf215546Sopenharmony_ci * uvec2 tmp4; 148bf215546Sopenharmony_ci * tmp4 = unpackUint2x32(tmp1.z); 149bf215546Sopenharmony_ci * uvec2 tmp5; 150bf215546Sopenharmony_ci * tmp5 = unpackUint2x32(tmp1.w); 151bf215546Sopenharmony_ci */ 152bf215546Sopenharmony_ci ASSERT_FALSE(instructions->is_empty()); 153bf215546Sopenharmony_ci ir = (ir_instruction *) instructions->pop_head(); 154bf215546Sopenharmony_ci ir_variable *const tmp1 = ir->as_variable(); 155bf215546Sopenharmony_ci EXPECT_EQ(ir_type_variable, ir->ir_type); 156bf215546Sopenharmony_ci EXPECT_EQ(type, tmp1->type) << 157bf215546Sopenharmony_ci " Got " << 158bf215546Sopenharmony_ci tmp1->type->name << 159bf215546Sopenharmony_ci ", expected " << 160bf215546Sopenharmony_ci type->name; 161bf215546Sopenharmony_ci 162bf215546Sopenharmony_ci ASSERT_FALSE(instructions->is_empty()); 163bf215546Sopenharmony_ci ir = (ir_instruction *) instructions->pop_head(); 164bf215546Sopenharmony_ci ir_assignment *const assign1 = ir->as_assignment(); 165bf215546Sopenharmony_ci EXPECT_EQ(ir_type_assignment, ir->ir_type); 166bf215546Sopenharmony_ci ASSERT_NE((void *)0, assign1); 167bf215546Sopenharmony_ci EXPECT_EQ(tmp1, assign1->lhs->variable_referenced()); 168bf215546Sopenharmony_ci EXPECT_EQ(source, assign1->rhs); 169bf215546Sopenharmony_ci 170bf215546Sopenharmony_ci for (unsigned i = 0; i < type->vector_elements; i++) { 171bf215546Sopenharmony_ci ASSERT_FALSE(instructions->is_empty()); 172bf215546Sopenharmony_ci ir = (ir_instruction *) instructions->pop_head(); 173bf215546Sopenharmony_ci ir_variable *const tmp2 = ir->as_variable(); 174bf215546Sopenharmony_ci EXPECT_EQ(ir_type_variable, ir->ir_type); 175bf215546Sopenharmony_ci EXPECT_EQ(expanded_type, tmp2->type); 176bf215546Sopenharmony_ci 177bf215546Sopenharmony_ci ASSERT_FALSE(instructions->is_empty()); 178bf215546Sopenharmony_ci ir = (ir_instruction *) instructions->pop_head(); 179bf215546Sopenharmony_ci ir_assignment *const assign2 = ir->as_assignment(); 180bf215546Sopenharmony_ci EXPECT_EQ(ir_type_assignment, ir->ir_type); 181bf215546Sopenharmony_ci ASSERT_NE((void *)0, assign2); 182bf215546Sopenharmony_ci EXPECT_EQ(tmp2, assign2->lhs->variable_referenced()); 183bf215546Sopenharmony_ci ir_expression *unpack = assign2->rhs->as_expression(); 184bf215546Sopenharmony_ci ASSERT_NE((void *)0, unpack); 185bf215546Sopenharmony_ci EXPECT_EQ(unpack_opcode, unpack->operation); 186bf215546Sopenharmony_ci EXPECT_EQ(tmp1, unpack->operands[0]->variable_referenced()); 187bf215546Sopenharmony_ci } 188bf215546Sopenharmony_ci 189bf215546Sopenharmony_ci EXPECT_TRUE(instructions->is_empty()); 190bf215546Sopenharmony_ci} 191bf215546Sopenharmony_ci 192bf215546Sopenharmony_ciTEST_F(expand_source, uint64_variable) 193bf215546Sopenharmony_ci{ 194bf215546Sopenharmony_ci const glsl_type *const type = glsl_type::uint64_t_type; 195bf215546Sopenharmony_ci ir_dereference_variable *const deref = create_variable(mem_ctx, type); 196bf215546Sopenharmony_ci 197bf215546Sopenharmony_ci lower_64bit::expand_source(*body, deref, expanded_src); 198bf215546Sopenharmony_ci 199bf215546Sopenharmony_ci check_expanded_source(type, expanded_src); 200bf215546Sopenharmony_ci check_instructions(&instructions, type, deref); 201bf215546Sopenharmony_ci} 202bf215546Sopenharmony_ci 203bf215546Sopenharmony_ciTEST_F(expand_source, u64vec2_variable) 204bf215546Sopenharmony_ci{ 205bf215546Sopenharmony_ci const glsl_type *const type = glsl_type::u64vec2_type; 206bf215546Sopenharmony_ci ir_dereference_variable *const deref = create_variable(mem_ctx, type); 207bf215546Sopenharmony_ci 208bf215546Sopenharmony_ci lower_64bit::expand_source(*body, deref, expanded_src); 209bf215546Sopenharmony_ci 210bf215546Sopenharmony_ci check_expanded_source(type, expanded_src); 211bf215546Sopenharmony_ci check_instructions(&instructions, type, deref); 212bf215546Sopenharmony_ci} 213bf215546Sopenharmony_ci 214bf215546Sopenharmony_ciTEST_F(expand_source, u64vec3_variable) 215bf215546Sopenharmony_ci{ 216bf215546Sopenharmony_ci const glsl_type *const type = glsl_type::u64vec3_type; 217bf215546Sopenharmony_ci 218bf215546Sopenharmony_ci /* Generate an operand that is a scalar variable dereference. */ 219bf215546Sopenharmony_ci ir_variable *const var = new(mem_ctx) ir_variable(type, 220bf215546Sopenharmony_ci "variable", 221bf215546Sopenharmony_ci ir_var_temporary); 222bf215546Sopenharmony_ci 223bf215546Sopenharmony_ci ir_dereference_variable *const deref = 224bf215546Sopenharmony_ci new(mem_ctx) ir_dereference_variable(var); 225bf215546Sopenharmony_ci 226bf215546Sopenharmony_ci lower_64bit::expand_source(*body, deref, expanded_src); 227bf215546Sopenharmony_ci 228bf215546Sopenharmony_ci check_expanded_source(type, expanded_src); 229bf215546Sopenharmony_ci check_instructions(&instructions, type, deref); 230bf215546Sopenharmony_ci} 231bf215546Sopenharmony_ci 232bf215546Sopenharmony_ciTEST_F(expand_source, u64vec4_variable) 233bf215546Sopenharmony_ci{ 234bf215546Sopenharmony_ci const glsl_type *const type = glsl_type::u64vec4_type; 235bf215546Sopenharmony_ci ir_dereference_variable *const deref = create_variable(mem_ctx, type); 236bf215546Sopenharmony_ci 237bf215546Sopenharmony_ci lower_64bit::expand_source(*body, deref, expanded_src); 238bf215546Sopenharmony_ci 239bf215546Sopenharmony_ci check_expanded_source(type, expanded_src); 240bf215546Sopenharmony_ci check_instructions(&instructions, type, deref); 241bf215546Sopenharmony_ci} 242bf215546Sopenharmony_ci 243bf215546Sopenharmony_ciTEST_F(expand_source, int64_variable) 244bf215546Sopenharmony_ci{ 245bf215546Sopenharmony_ci const glsl_type *const type = glsl_type::int64_t_type; 246bf215546Sopenharmony_ci ir_dereference_variable *const deref = create_variable(mem_ctx, type); 247bf215546Sopenharmony_ci 248bf215546Sopenharmony_ci lower_64bit::expand_source(*body, deref, expanded_src); 249bf215546Sopenharmony_ci 250bf215546Sopenharmony_ci check_expanded_source(type, expanded_src); 251bf215546Sopenharmony_ci check_instructions(&instructions, type, deref); 252bf215546Sopenharmony_ci} 253bf215546Sopenharmony_ci 254bf215546Sopenharmony_ciTEST_F(expand_source, i64vec2_variable) 255bf215546Sopenharmony_ci{ 256bf215546Sopenharmony_ci const glsl_type *const type = glsl_type::i64vec2_type; 257bf215546Sopenharmony_ci ir_dereference_variable *const deref = create_variable(mem_ctx, type); 258bf215546Sopenharmony_ci 259bf215546Sopenharmony_ci lower_64bit::expand_source(*body, deref, expanded_src); 260bf215546Sopenharmony_ci 261bf215546Sopenharmony_ci check_expanded_source(type, expanded_src); 262bf215546Sopenharmony_ci check_instructions(&instructions, type, deref); 263bf215546Sopenharmony_ci} 264bf215546Sopenharmony_ci 265bf215546Sopenharmony_ciTEST_F(expand_source, i64vec3_variable) 266bf215546Sopenharmony_ci{ 267bf215546Sopenharmony_ci const glsl_type *const type = glsl_type::i64vec3_type; 268bf215546Sopenharmony_ci ir_dereference_variable *const deref = create_variable(mem_ctx, type); 269bf215546Sopenharmony_ci 270bf215546Sopenharmony_ci lower_64bit::expand_source(*body, deref, expanded_src); 271bf215546Sopenharmony_ci 272bf215546Sopenharmony_ci check_expanded_source(type, expanded_src); 273bf215546Sopenharmony_ci check_instructions(&instructions, type, deref); 274bf215546Sopenharmony_ci} 275bf215546Sopenharmony_ci 276bf215546Sopenharmony_ciTEST_F(expand_source, i64vec4_variable) 277bf215546Sopenharmony_ci{ 278bf215546Sopenharmony_ci const glsl_type *const type = glsl_type::i64vec4_type; 279bf215546Sopenharmony_ci ir_dereference_variable *const deref = create_variable(mem_ctx, type); 280bf215546Sopenharmony_ci 281bf215546Sopenharmony_ci lower_64bit::expand_source(*body, deref, expanded_src); 282bf215546Sopenharmony_ci 283bf215546Sopenharmony_ci check_expanded_source(type, expanded_src); 284bf215546Sopenharmony_ci check_instructions(&instructions, type, deref); 285bf215546Sopenharmony_ci} 286bf215546Sopenharmony_ci 287bf215546Sopenharmony_ciTEST_F(expand_source, uint64_expression) 288bf215546Sopenharmony_ci{ 289bf215546Sopenharmony_ci const glsl_type *const type = glsl_type::uint64_t_type; 290bf215546Sopenharmony_ci ir_expression *const expr = create_expression(mem_ctx, type); 291bf215546Sopenharmony_ci 292bf215546Sopenharmony_ci lower_64bit::expand_source(*body, expr, expanded_src); 293bf215546Sopenharmony_ci 294bf215546Sopenharmony_ci check_expanded_source(type, expanded_src); 295bf215546Sopenharmony_ci check_instructions(&instructions, type, expr); 296bf215546Sopenharmony_ci} 297bf215546Sopenharmony_ci 298bf215546Sopenharmony_ciTEST_F(expand_source, u64vec2_expression) 299bf215546Sopenharmony_ci{ 300bf215546Sopenharmony_ci const glsl_type *const type = glsl_type::u64vec2_type; 301bf215546Sopenharmony_ci ir_expression *const expr = create_expression(mem_ctx, type); 302bf215546Sopenharmony_ci 303bf215546Sopenharmony_ci lower_64bit::expand_source(*body, expr, expanded_src); 304bf215546Sopenharmony_ci 305bf215546Sopenharmony_ci check_expanded_source(type, expanded_src); 306bf215546Sopenharmony_ci check_instructions(&instructions, type, expr); 307bf215546Sopenharmony_ci} 308bf215546Sopenharmony_ci 309bf215546Sopenharmony_ciTEST_F(expand_source, u64vec3_expression) 310bf215546Sopenharmony_ci{ 311bf215546Sopenharmony_ci const glsl_type *const type = glsl_type::u64vec3_type; 312bf215546Sopenharmony_ci ir_expression *const expr = create_expression(mem_ctx, type); 313bf215546Sopenharmony_ci 314bf215546Sopenharmony_ci lower_64bit::expand_source(*body, expr, expanded_src); 315bf215546Sopenharmony_ci 316bf215546Sopenharmony_ci check_expanded_source(type, expanded_src); 317bf215546Sopenharmony_ci check_instructions(&instructions, type, expr); 318bf215546Sopenharmony_ci} 319bf215546Sopenharmony_ci 320bf215546Sopenharmony_ciTEST_F(expand_source, u64vec4_expression) 321bf215546Sopenharmony_ci{ 322bf215546Sopenharmony_ci const glsl_type *const type = glsl_type::u64vec4_type; 323bf215546Sopenharmony_ci ir_expression *const expr = create_expression(mem_ctx, type); 324bf215546Sopenharmony_ci 325bf215546Sopenharmony_ci lower_64bit::expand_source(*body, expr, expanded_src); 326bf215546Sopenharmony_ci 327bf215546Sopenharmony_ci check_expanded_source(type, expanded_src); 328bf215546Sopenharmony_ci check_instructions(&instructions, type, expr); 329bf215546Sopenharmony_ci} 330bf215546Sopenharmony_ci 331bf215546Sopenharmony_ciTEST_F(expand_source, int64_expression) 332bf215546Sopenharmony_ci{ 333bf215546Sopenharmony_ci const glsl_type *const type = glsl_type::int64_t_type; 334bf215546Sopenharmony_ci ir_expression *const expr = create_expression(mem_ctx, type); 335bf215546Sopenharmony_ci 336bf215546Sopenharmony_ci lower_64bit::expand_source(*body, expr, expanded_src); 337bf215546Sopenharmony_ci 338bf215546Sopenharmony_ci check_expanded_source(type, expanded_src); 339bf215546Sopenharmony_ci check_instructions(&instructions, type, expr); 340bf215546Sopenharmony_ci} 341bf215546Sopenharmony_ci 342bf215546Sopenharmony_ciTEST_F(expand_source, i64vec2_expression) 343bf215546Sopenharmony_ci{ 344bf215546Sopenharmony_ci const glsl_type *const type = glsl_type::i64vec2_type; 345bf215546Sopenharmony_ci ir_expression *const expr = create_expression(mem_ctx, type); 346bf215546Sopenharmony_ci 347bf215546Sopenharmony_ci lower_64bit::expand_source(*body, expr, expanded_src); 348bf215546Sopenharmony_ci 349bf215546Sopenharmony_ci check_expanded_source(type, expanded_src); 350bf215546Sopenharmony_ci check_instructions(&instructions, type, expr); 351bf215546Sopenharmony_ci} 352bf215546Sopenharmony_ci 353bf215546Sopenharmony_ciTEST_F(expand_source, i64vec3_expression) 354bf215546Sopenharmony_ci{ 355bf215546Sopenharmony_ci const glsl_type *const type = glsl_type::i64vec3_type; 356bf215546Sopenharmony_ci ir_expression *const expr = create_expression(mem_ctx, type); 357bf215546Sopenharmony_ci 358bf215546Sopenharmony_ci lower_64bit::expand_source(*body, expr, expanded_src); 359bf215546Sopenharmony_ci 360bf215546Sopenharmony_ci check_expanded_source(type, expanded_src); 361bf215546Sopenharmony_ci check_instructions(&instructions, type, expr); 362bf215546Sopenharmony_ci} 363bf215546Sopenharmony_ci 364bf215546Sopenharmony_ciTEST_F(expand_source, i64vec4_expression) 365bf215546Sopenharmony_ci{ 366bf215546Sopenharmony_ci const glsl_type *const type = glsl_type::i64vec4_type; 367bf215546Sopenharmony_ci ir_expression *const expr = create_expression(mem_ctx, type); 368bf215546Sopenharmony_ci 369bf215546Sopenharmony_ci lower_64bit::expand_source(*body, expr, expanded_src); 370bf215546Sopenharmony_ci 371bf215546Sopenharmony_ci check_expanded_source(type, expanded_src); 372bf215546Sopenharmony_ci check_instructions(&instructions, type, expr); 373bf215546Sopenharmony_ci} 374bf215546Sopenharmony_ci 375bf215546Sopenharmony_ciclass compact_destination : public ::testing::Test { 376bf215546Sopenharmony_cipublic: 377bf215546Sopenharmony_ci virtual void SetUp(); 378bf215546Sopenharmony_ci virtual void TearDown(); 379bf215546Sopenharmony_ci 380bf215546Sopenharmony_ci exec_list instructions; 381bf215546Sopenharmony_ci ir_factory *body; 382bf215546Sopenharmony_ci ir_variable *expanded_src[4]; 383bf215546Sopenharmony_ci void *mem_ctx; 384bf215546Sopenharmony_ci}; 385bf215546Sopenharmony_ci 386bf215546Sopenharmony_civoid 387bf215546Sopenharmony_cicompact_destination::SetUp() 388bf215546Sopenharmony_ci{ 389bf215546Sopenharmony_ci mem_ctx = ralloc_context(NULL); 390bf215546Sopenharmony_ci 391bf215546Sopenharmony_ci memset(expanded_src, 0, sizeof(expanded_src)); 392bf215546Sopenharmony_ci instructions.make_empty(); 393bf215546Sopenharmony_ci body = new ir_factory(&instructions, mem_ctx); 394bf215546Sopenharmony_ci} 395bf215546Sopenharmony_ci 396bf215546Sopenharmony_civoid 397bf215546Sopenharmony_cicompact_destination::TearDown() 398bf215546Sopenharmony_ci{ 399bf215546Sopenharmony_ci delete body; 400bf215546Sopenharmony_ci body = NULL; 401bf215546Sopenharmony_ci 402bf215546Sopenharmony_ci ralloc_free(mem_ctx); 403bf215546Sopenharmony_ci mem_ctx = NULL; 404bf215546Sopenharmony_ci} 405bf215546Sopenharmony_ci 406bf215546Sopenharmony_ciTEST_F(compact_destination, uint64) 407bf215546Sopenharmony_ci{ 408bf215546Sopenharmony_ci const glsl_type *const type = glsl_type::uint64_t_type; 409bf215546Sopenharmony_ci 410bf215546Sopenharmony_ci for (unsigned i = 0; i < type->vector_elements; i++) { 411bf215546Sopenharmony_ci expanded_src[i] = new(mem_ctx) ir_variable(glsl_type::uvec2_type, 412bf215546Sopenharmony_ci "result", 413bf215546Sopenharmony_ci ir_var_temporary); 414bf215546Sopenharmony_ci } 415bf215546Sopenharmony_ci 416bf215546Sopenharmony_ci ir_dereference_variable *deref = 417bf215546Sopenharmony_ci lower_64bit::compact_destination(*body, 418bf215546Sopenharmony_ci type, 419bf215546Sopenharmony_ci expanded_src); 420bf215546Sopenharmony_ci 421bf215546Sopenharmony_ci ASSERT_EQ(ir_type_dereference_variable, deref->ir_type); 422bf215546Sopenharmony_ci EXPECT_EQ(type, deref->var->type) << 423bf215546Sopenharmony_ci " Got " << 424bf215546Sopenharmony_ci deref->var->type->name << 425bf215546Sopenharmony_ci ", expected " << 426bf215546Sopenharmony_ci type->name; 427bf215546Sopenharmony_ci 428bf215546Sopenharmony_ci ir_instruction *ir; 429bf215546Sopenharmony_ci 430bf215546Sopenharmony_ci ASSERT_FALSE(instructions.is_empty()); 431bf215546Sopenharmony_ci ir = (ir_instruction *) instructions.pop_head(); 432bf215546Sopenharmony_ci ir_variable *const var = ir->as_variable(); 433bf215546Sopenharmony_ci ASSERT_NE((void *)0, var); 434bf215546Sopenharmony_ci EXPECT_EQ(deref->var, var); 435bf215546Sopenharmony_ci 436bf215546Sopenharmony_ci for (unsigned i = 0; i < type->vector_elements; i++) { 437bf215546Sopenharmony_ci ASSERT_FALSE(instructions.is_empty()); 438bf215546Sopenharmony_ci ir = (ir_instruction *) instructions.pop_head(); 439bf215546Sopenharmony_ci ir_assignment *const assign = ir->as_assignment(); 440bf215546Sopenharmony_ci ASSERT_NE((void *)0, assign); 441bf215546Sopenharmony_ci EXPECT_EQ(deref->var, assign->lhs->variable_referenced()); 442bf215546Sopenharmony_ci } 443bf215546Sopenharmony_ci} 444