Home | History | Annotate | Download | only in tests
      1 #include <stdlib.h>
      2 #include <string.h>
      3 #include <sys/types.h>
      4 
      5 #include "radeon_compiler_util.h"
      6 #include "radeon_program.h"
      7 
      8 #include "r300_compiler_tests.h"
      9 #include "rc_test_helpers.h"
     10 #include "unit_test.h"
     11 
     12 static void test_rc_inst_can_use_presub(
     13 	struct test_result * result,
     14 	int expected,
     15 	const char * add_str,
     16 	const char * replace_str)
     17 {
     18 	struct rc_instruction add_inst, replace_inst;
     19 	int ret;
     20 
     21 	test_begin(result);
     22 	init_rc_normal_instruction(&add_inst, add_str);
     23 	init_rc_normal_instruction(&replace_inst, replace_str);
     24 
     25 	ret = rc_inst_can_use_presub(&replace_inst, RC_PRESUB_ADD, 0,
     26 			&replace_inst.U.I.SrcReg[0],
     27 			&add_inst.U.I.SrcReg[0], &add_inst.U.I.SrcReg[1]);
     28 
     29 	test_check(result, ret == expected);
     30 }
     31 
     32 static void test_runner_rc_inst_can_use_presub(struct test_result * result)
     33 {
     34 
     35 	/* This tests the case where the source being replace has the same
     36 	 * register file and register index as another source register in the
     37 	 * CMP instruction.  A previous version of this function was ignoring
     38 	 * all registers that shared the same file and index as the replacement
     39 	 * register when counting the number of source selects.
     40 	 *
     41 	 * https://bugs.freedesktop.org/show_bug.cgi?id=36527
     42 	 */
     43 	test_rc_inst_can_use_presub(result, 0,
     44 		"ADD temp[0].z, temp[6].__x_, const[1].__x_;",
     45 		"CMP temp[0].y, temp[0]._z__, const[0]._z__, temp[0]._y__;");
     46 
     47 
     48 	/* Testing a random case that should fail
     49 	 *
     50 	 * https://bugs.freedesktop.org/show_bug.cgi?id=36527
     51 	 */
     52 	test_rc_inst_can_use_presub(result, 0,
     53 		"ADD temp[3], temp[1], temp[2];",
     54 		"MAD temp[1], temp[0], const[0].xxxx, -temp[3];");
     55 
     56 	/* This tests the case where the arguments of the ADD
     57 	 * instruction share the same register file and index.  Normally, we
     58 	 * would need only one source select for these two arguments, but since
     59 	 * they will be part of a presubtract operation we need to use the two
     60 	 * source selects that the presubtract instruction expects
     61 	 * (src0 and src1).
     62 	 *
     63 	 * https://bugs.freedesktop.org/show_bug.cgi?id=36527
     64 	 */
     65 	test_rc_inst_can_use_presub(result, 0,
     66 		"ADD temp[3].x, temp[0].x___, temp[0].x___;",
     67 		"MAD temp[0].xyz, temp[2].xyz_, -temp[3].xxx_, input[5].xyz_;");
     68 }
     69 
     70 void radeon_compiler_util_run_tests()
     71 {
     72 	struct test tests[] = {
     73 		{"rc_inst_can_use_presub()", test_runner_rc_inst_can_use_presub},
     74 		{NULL, NULL}
     75 	};
     76 	run_tests(tests);
     77 }
     78