Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | RSS feed

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