1 /* 2 * Copyright 2013 Advanced Micro Devices, Inc. 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 * on the rights to use, copy, modify, merge, publish, distribute, sub 8 * license, and/or sell copies of the Software, and to permit persons to whom 9 * the 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 NON-INFRINGEMENT. IN NO EVENT SHALL 18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, 19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 21 * USE OR OTHER DEALINGS IN THE SOFTWARE. 22 * 23 * Author: Tom Stellard <thomas.stellard (at) amd.com> 24 */ 25 26 #include <stdio.h> 27 28 #include "radeon_program_pair.h" 29 30 #include "r300_compiler_tests.h" 31 #include "rc_test_helpers.h" 32 #include "unit_test.h" 33 34 static void dummy_allocate_hw_inputs( 35 struct r300_fragment_program_compiler * c, 36 void (*allocate)(void * data, unsigned input, unsigned hwreg), 37 void * mydata) 38 { 39 unsigned i; 40 for (i = 0; i < 10; i++) { 41 allocate(mydata, i, i); 42 } 43 } 44 45 static void test_runner_rc_regalloc( 46 struct test_result *result, 47 struct radeon_compiler *c, 48 const char *filename) 49 { 50 struct rc_test_file test_file; 51 unsigned optimizations = 1; 52 unsigned do_full_regalloc = 1; 53 struct rc_instruction *inst; 54 unsigned pass = 1; 55 56 test_begin(result); 57 58 if (!load_program(c, &test_file, filename)) { 59 fprintf(stderr, "Failed to load program\n"); 60 } 61 62 rc_pair_translate(c, NULL); 63 rc_pair_schedule(c, &optimizations); 64 rc_pair_remove_dead_sources(c, NULL); 65 rc_pair_regalloc(c, &do_full_regalloc); 66 67 for(inst = c->Program.Instructions.Next; 68 inst != &c->Program.Instructions; 69 inst = inst->Next) { 70 if (inst->Type == RC_INSTRUCTION_NORMAL && 71 inst->U.I.Opcode != RC_OPCODE_BEGIN_TEX) { 72 if (GET_SWZ(inst->U.I.SrcReg[0].Swizzle, 0) 73 != RC_SWIZZLE_X) { 74 pass = 0; 75 } 76 } 77 } 78 79 test_check(result, pass); 80 } 81 82 static void tex_1d_swizzle(struct test_result *result) 83 { 84 struct r300_fragment_program_compiler c; 85 86 memset(&c, 0, sizeof(c)); 87 init_compiler(&c.Base, RC_FRAGMENT_PROGRAM, 0, 0); 88 c.AllocateHwInputs = dummy_allocate_hw_inputs; 89 90 test_runner_rc_regalloc(result, &c.Base, "regalloc_tex_1d_swizzle.test"); 91 } 92 93 unsigned radeon_compiler_regalloc_run_tests() 94 { 95 static struct test tests[] = { 96 {"rc_pair_regalloc() => TEX 1D Swizzle - r300", tex_1d_swizzle }, 97 {NULL, NULL} 98 }; 99 return run_tests(tests); 100 } 101