• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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@amd.com>
24  */
25 
26 #include <stdio.h>
27 #include "radeon_compiler.h"
28 #include "radeon_dataflow.h"
29 
30 #include "r300_compiler_tests.h"
31 #include "rc_test_helpers.h"
32 #include "unit_test.h"
33 
test_rc_optimize(struct test_result * result,struct radeon_compiler * c,const char * filename)34 static unsigned test_rc_optimize(
35 	struct test_result * result,
36 	struct radeon_compiler * c,
37 	const char * filename)
38 {
39 	struct rc_test_file test_file;
40 
41 	test_begin(result);
42 
43 	if (!load_program(c, &test_file, filename)) {
44 		fprintf(stderr, "Failed to load program\n");
45 		return 0;
46 	}
47 
48 	rc_optimize(c, NULL);
49 	return 1;
50 }
51 
test_runner_rc_optimize(struct test_result * result)52 static void test_runner_rc_optimize(struct test_result * result)
53 {
54 	unsigned pass = 1;
55 	struct radeon_compiler c;
56 	struct rc_instruction *inst;
57 	struct rc_instruction *inst_list[3];
58 	unsigned inst_count = 0;
59 	float const0[4] = {2.0f, 0.0f, 0.0f, 0.0f};
60 
61 	init_compiler(&c, RC_FRAGMENT_PROGRAM, 1, 0);
62 
63 	rc_constants_add_immediate_vec4(&c.Program.Constants, const0);
64 
65 	test_rc_optimize(result, &c, "omod_two_writers.test");
66 
67 	for(inst = c.Program.Instructions.Next;
68 				inst != &c.Program.Instructions;
69 				inst = inst->Next, inst_count++) {
70 		inst_list[inst_count] = inst;
71 	}
72 
73 	if (inst_list[0]->U.I.Omod != RC_OMOD_MUL_2 ||
74 			inst_list[1]->U.I.Omod != RC_OMOD_MUL_2 ||
75 			inst_list[2]->U.I.Opcode != RC_OPCODE_MOV) {
76 		pass = 0;
77 	}
78 
79 	test_check(result, pass);
80 }
81 
radeon_compiler_optimize_run_tests()82 unsigned radeon_compiler_optimize_run_tests()
83 {
84 	static struct test tests[] = {
85 		{"rc_optimize() => peephole_mul_omod()", test_runner_rc_optimize},
86 		{NULL, NULL}
87 	};
88 	return run_tests(tests);
89 }
90