1/* 2 Copyright (C) Intel Corp. 2006. All Rights Reserved. 3 Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to 4 develop this 3D driver. 5 6 Permission is hereby granted, free of charge, to any person obtaining 7 a copy of this software and associated documentation files (the 8 "Software"), to deal in the Software without restriction, including 9 without limitation the rights to use, copy, modify, merge, publish, 10 distribute, sublicense, and/or sell copies of the Software, and to 11 permit persons to whom the Software is furnished to do so, subject to 12 the following conditions: 13 14 The above copyright notice and this permission notice (including the 15 next paragraph) shall be included in all copies or substantial 16 portions of the Software. 17 18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 19 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 21 IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE 22 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 23 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 24 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 26 **********************************************************************/ 27 /* 28 * Authors: 29 * Keith Whitwell <keith@tungstengraphics.com> 30 */ 31 32#ifdef HAVE_CONFIG_H 33#include "config.h" 34#endif 35 36#include "brw_eu.h" 37 38#include <string.h> 39#include <stdlib.h> 40 41/* Returns the corresponding conditional mod for swapping src0 and 42 * src1 in e.g. CMP. 43 */ 44uint32_t 45brw_swap_cmod(uint32_t cmod) 46{ 47 switch (cmod) { 48 case BRW_CONDITIONAL_Z: 49 case BRW_CONDITIONAL_NZ: 50 return cmod; 51 case BRW_CONDITIONAL_G: 52 return BRW_CONDITIONAL_LE; 53 case BRW_CONDITIONAL_GE: 54 return BRW_CONDITIONAL_L; 55 case BRW_CONDITIONAL_L: 56 return BRW_CONDITIONAL_GE; 57 case BRW_CONDITIONAL_LE: 58 return BRW_CONDITIONAL_G; 59 default: 60 return ~0; 61 } 62} 63 64/* How does predicate control work when execution_size != 8? Do I 65 * need to test/set for 0xffff when execution_size is 16? 66 */ 67void brw_set_predicate_control_flag_value( struct brw_compile *p, unsigned value ) 68{ 69 p->current->header.predicate_control = BRW_PREDICATE_NONE; 70 71 if (value != 0xff) { 72 if (value != p->flag_value) { 73 brw_MOV(p, brw_flag_reg(), brw_imm_uw(value)); 74 p->flag_value = value; 75 } 76 77 p->current->header.predicate_control = BRW_PREDICATE_NORMAL; 78 } 79} 80 81void brw_set_compression_control(struct brw_compile *p, 82 enum brw_compression compression_control) 83{ 84 p->compressed = (compression_control == BRW_COMPRESSION_COMPRESSED); 85 86 if (p->gen >= 060) { 87 /* Since we don't use the 32-wide support in gen6, we translate 88 * the pre-gen6 compression control here. 89 */ 90 switch (compression_control) { 91 case BRW_COMPRESSION_NONE: 92 /* This is the "use the first set of bits of dmask/vmask/arf 93 * according to execsize" option. 94 */ 95 p->current->header.compression_control = GEN6_COMPRESSION_1Q; 96 break; 97 case BRW_COMPRESSION_2NDHALF: 98 /* For 8-wide, this is "use the second set of 8 bits." */ 99 p->current->header.compression_control = GEN6_COMPRESSION_2Q; 100 break; 101 case BRW_COMPRESSION_COMPRESSED: 102 /* For 16-wide instruction compression, use the first set of 16 bits 103 * since we don't do 32-wide dispatch. 104 */ 105 p->current->header.compression_control = GEN6_COMPRESSION_1H; 106 break; 107 default: 108 assert(!"not reached"); 109 p->current->header.compression_control = GEN6_COMPRESSION_1H; 110 break; 111 } 112 } else { 113 p->current->header.compression_control = compression_control; 114 } 115} 116 117void brw_push_insn_state( struct brw_compile *p ) 118{ 119 assert(p->current != &p->stack[BRW_EU_MAX_INSN_STACK-1]); 120 memcpy(p->current+1, p->current, sizeof(struct brw_instruction)); 121 p->compressed_stack[p->current - p->stack] = p->compressed; 122 p->current++; 123} 124 125void brw_pop_insn_state( struct brw_compile *p ) 126{ 127 assert(p->current != p->stack); 128 p->current--; 129 p->compressed = p->compressed_stack[p->current - p->stack]; 130} 131 132void brw_compile_init(struct brw_compile *p, int gen, void *store) 133{ 134 assert(gen); 135 136 p->gen = gen; 137 p->store = store; 138 139 p->nr_insn = 0; 140 p->current = p->stack; 141 p->compressed = false; 142 memset(p->current, 0, sizeof(p->current[0])); 143 144 /* Some defaults? 145 */ 146 brw_set_mask_control(p, BRW_MASK_ENABLE); /* what does this do? */ 147 brw_set_saturate(p, 0); 148 brw_set_compression_control(p, BRW_COMPRESSION_NONE); 149 brw_set_predicate_control_flag_value(p, 0xff); 150 151 p->if_stack_depth = 0; 152 p->if_stack_array_size = 0; 153 p->if_stack = NULL; 154} 155