Subversion Repositories Kolibri OS

Rev

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

  1. /*
  2.  * Copyright © 2014 Broadcom
  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.  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8.  * and/or sell copies of the Software, and to permit persons to whom the
  9.  * 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 NONINFRINGEMENT.  IN NO EVENT SHALL
  18.  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19.  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20.  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  21.  * IN THE SOFTWARE.
  22.  */
  23.  
  24. /**
  25.  * @file vc4_opt_small_immediates.c
  26.  *
  27.  * Turns references to small constant uniform values into small immediates
  28.  * fields.
  29.  */
  30.  
  31. #include "vc4_qir.h"
  32. #include "vc4_qpu.h"
  33.  
  34. static bool debug;
  35.  
  36. bool
  37. qir_opt_small_immediates(struct vc4_compile *c)
  38. {
  39.         bool progress = false;
  40.         struct simple_node *node;
  41.  
  42.         foreach(node, &c->instructions) {
  43.                 struct qinst *inst = (struct qinst *)node;
  44.  
  45.                 /* The small immediate value sits in the raddr B field, so we
  46.                  * can't have 2 small immediates in one instruction (unless
  47.                  * they're the same value, but that should be optimized away
  48.                  * elsewhere).
  49.                  */
  50.                 bool uses_small_imm = false;
  51.                 for (int i = 0; i < qir_get_op_nsrc(inst->op); i++) {
  52.                         if (inst->src[i].file == QFILE_SMALL_IMM)
  53.                                 uses_small_imm = true;
  54.                 }
  55.                 if (uses_small_imm)
  56.                         continue;
  57.  
  58.                 for (int i = 0; i < qir_get_op_nsrc(inst->op); i++) {
  59.                         struct qreg src = qir_follow_movs(c, inst->src[i]);
  60.  
  61.                         if (src.file != QFILE_UNIF ||
  62.                             c->uniform_contents[src.index] !=
  63.                             QUNIFORM_CONSTANT) {
  64.                                 continue;
  65.                         }
  66.  
  67.                         if (i == 1 &&
  68.                             (inst->op == QOP_TEX_S ||
  69.                              inst->op == QOP_TEX_T ||
  70.                              inst->op == QOP_TEX_R ||
  71.                              inst->op == QOP_TEX_B)) {
  72.                                 /* No turning the implicit uniform read into
  73.                                  * an immediate.
  74.                                  */
  75.                                 continue;
  76.                         }
  77.  
  78.                         if (qir_src_needs_a_file(inst))
  79.                                 continue;
  80.  
  81.                         uint32_t imm = c->uniform_data[src.index];
  82.                         uint32_t small_imm = qpu_encode_small_immediate(imm);
  83.                         if (small_imm == ~0)
  84.                                 continue;
  85.  
  86.                         if (debug) {
  87.                                 fprintf(stderr, "opt_small_immediate() from: ");
  88.                                 qir_dump_inst(c, inst);
  89.                                 fprintf(stderr, "\n");
  90.                         }
  91.                         inst->src[i].file = QFILE_SMALL_IMM;
  92.                         inst->src[i].index = imm;
  93.                         if (debug) {
  94.                                 fprintf(stderr, "to: ");
  95.                                 qir_dump_inst(c, inst);
  96.                                 fprintf(stderr, "\n");
  97.                         }
  98.                         progress = true;
  99.                         break;
  100.                 }
  101.         }
  102.  
  103.         return progress;
  104. }
  105.