Subversion Repositories Kolibri OS

Rev

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_vpm_writes.c
  26.  *
  27.  * This modifies instructions that generate the value consumed by a VPM write
  28.  * to write directly into the VPM.
  29.  */
  30.  
  31. #include "vc4_qir.h"
  32.  
  33. bool
  34. qir_opt_vpm_writes(struct vc4_compile *c)
  35. {
  36.         if (c->stage == QSTAGE_FRAG)
  37.                 return false;
  38.  
  39.         bool progress = false;
  40.         struct simple_node *node;
  41.         struct qinst *vpm_writes[64] = { 0 };
  42.         uint32_t use_count[c->num_temps];
  43.         uint32_t vpm_write_count = 0;
  44.         memset(&use_count, 0, sizeof(use_count));
  45.  
  46.         foreach(node, &c->instructions) {
  47.                 struct qinst *inst = (struct qinst *)node;
  48.  
  49.                 switch (inst->dst.file) {
  50.                 case QFILE_VPM:
  51.                         vpm_writes[vpm_write_count++] = inst;
  52.                         break;
  53.                 default:
  54.                         break;
  55.                 }
  56.  
  57.                 for (int i = 0; i < qir_get_op_nsrc(inst->op); i++) {
  58.                         if (inst->src[i].file == QFILE_TEMP)
  59.                                 use_count[inst->src[i].index]++;
  60.                 }
  61.         }
  62.  
  63.         for (int i = 0; i < vpm_write_count; i++) {
  64.                 if (vpm_writes[i]->op != QOP_MOV ||
  65.                     vpm_writes[i]->src[0].file != QFILE_TEMP) {
  66.                         continue;
  67.                 }
  68.  
  69.                 uint32_t temp = vpm_writes[i]->src[0].index;
  70.                 if (use_count[temp] != 1)
  71.                         continue;
  72.  
  73.                 struct qinst *inst = c->defs[temp];
  74.                 if (qir_is_multi_instruction(inst))
  75.                         continue;
  76.  
  77.                 if (qir_depends_on_flags(inst) || inst->sf)
  78.                         continue;
  79.  
  80.                 if (qir_has_side_effects(c, inst) ||
  81.                     qir_has_side_effect_reads(c, inst)) {
  82.                         continue;
  83.                 }
  84.  
  85.                 /* A QOP_TEX_RESULT destination is r4, so we can't move
  86.                  * accesses to it past another QOP_TEX_RESULT which would
  87.                  * update it.
  88.                  */
  89.                 int src;
  90.                 for (src = 0; src < qir_get_op_nsrc(inst->op); src++) {
  91.                         if (inst->src[src].file == QFILE_TEMP) {
  92.                                 if (c->defs[inst->src[src].index]->op ==
  93.                                     QOP_TEX_RESULT) {
  94.                                         break;
  95.                                 }
  96.                         }
  97.                 }
  98.                 if (src != qir_get_op_nsrc(inst->op))
  99.                         continue;
  100.  
  101.                 /* Move the generating instruction to the end of the program
  102.                  * to maintain the order of the VPM writes.
  103.                  */
  104.                 assert(!vpm_writes[i]->sf);
  105.                 move_to_tail(&vpm_writes[i]->link, &inst->link);
  106.                 qir_remove_instruction(c, vpm_writes[i]);
  107.  
  108.                 c->defs[inst->dst.index] = NULL;
  109.                 inst->dst.file = QFILE_VPM;
  110.                 inst->dst.index = 0;
  111.  
  112.                 progress = true;
  113.         }
  114.  
  115.         return progress;
  116. }
  117.