1 /* 2 * Copyright 2011 Tom Stellard <tstellar (at) gmail.com> 3 * 4 * All Rights Reserved. 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining 7 * a copy of this software and associated documentation files (the 8 * "Software"), to deal in the Software without restriction, including 9 * without limitation the rights to use, copy, modify, merge, publish, 10 * distribute, sublicense, and/or sell copies of the Software, and to 11 * permit persons to whom the Software is furnished to do so, subject to 12 * the following conditions: 13 * 14 * The above copyright notice and this permission notice (including the 15 * next paragraph) shall be included in all copies or substantial 16 * portions of the Software. 17 * 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 21 * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE 22 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 23 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 24 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 * 26 */ 27 28 #include <stdlib.h> 29 #include <string.h> 30 #include <sys/types.h> 31 32 #include "radeon_compiler_util.h" 33 #include "radeon_program.h" 34 35 #include "r300_compiler_tests.h" 36 #include "rc_test_helpers.h" 37 #include "unit_test.h" 38 39 static void test_rc_inst_can_use_presub( 40 struct test_result * result, 41 int expected, 42 const char * add_str, 43 const char * replace_str) 44 { 45 struct rc_instruction add_inst, replace_inst; 46 int ret; 47 48 test_begin(result); 49 init_rc_normal_instruction(&add_inst, add_str); 50 init_rc_normal_instruction(&replace_inst, replace_str); 51 52 ret = rc_inst_can_use_presub(&replace_inst, RC_PRESUB_ADD, 0, 53 &replace_inst.U.I.SrcReg[0], 54 &add_inst.U.I.SrcReg[0], &add_inst.U.I.SrcReg[1]); 55 56 test_check(result, ret == expected); 57 } 58 59 static void test_runner_rc_inst_can_use_presub(struct test_result * result) 60 { 61 62 /* This tests the case where the source being replace has the same 63 * register file and register index as another source register in the 64 * CMP instruction. A previous version of this function was ignoring 65 * all registers that shared the same file and index as the replacement 66 * register when counting the number of source selects. 67 * 68 * https://bugs.freedesktop.org/show_bug.cgi?id=36527 69 */ 70 test_rc_inst_can_use_presub(result, 0, 71 "ADD temp[0].z, temp[6].__x_, const[1].__x_;", 72 "CMP temp[0].y, temp[0]._z__, const[0]._z__, temp[0]._y__;"); 73 74 75 /* Testing a random case that should fail 76 * 77 * https://bugs.freedesktop.org/show_bug.cgi?id=36527 78 */ 79 test_rc_inst_can_use_presub(result, 0, 80 "ADD temp[3], temp[1], temp[2];", 81 "MAD temp[1], temp[0], const[0].xxxx, -temp[3];"); 82 83 /* This tests the case where the arguments of the ADD 84 * instruction share the same register file and index. Normally, we 85 * would need only one source select for these two arguments, but since 86 * they will be part of a presubtract operation we need to use the two 87 * source selects that the presubtract instruction expects 88 * (src0 and src1). 89 * 90 * https://bugs.freedesktop.org/show_bug.cgi?id=36527 91 */ 92 test_rc_inst_can_use_presub(result, 0, 93 "ADD temp[3].x, temp[0].x___, temp[0].x___;", 94 "MAD temp[0].xyz, temp[2].xyz_, -temp[3].xxx_, input[5].xyz_;"); 95 } 96 97 unsigned radeon_compiler_util_run_tests() 98 { 99 static struct test tests[] = { 100 {"rc_inst_can_use_presub()", test_runner_rc_inst_can_use_presub}, 101 {NULL, NULL} 102 }; 103 return run_tests(tests); 104 } 105