1 /* 2 * Copyright 2010 Tom Stellard <tstellar@gmail.com> 3 * 4 * All Rights Reserved. 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 #include "radeon_program_constants.h" 29 30 #ifndef RADEON_PROGRAM_UTIL_H 31 #define RADEON_PROGRAM_UTIL_H 32 33 #include "radeon_opcodes.h" 34 35 struct radeon_compiler; 36 struct rc_instruction; 37 struct rc_pair_instruction; 38 struct rc_pair_sub_instruction; 39 struct rc_src_register; 40 41 unsigned int rc_swizzle_to_writemask(unsigned int swz); 42 43 rc_swizzle get_swz(unsigned int swz, rc_swizzle idx); 44 45 unsigned int rc_init_swizzle(unsigned int initial_value, unsigned int channels); 46 47 unsigned int combine_swizzles4(unsigned int src, 48 rc_swizzle swz_x, rc_swizzle swz_y, 49 rc_swizzle swz_z, rc_swizzle swz_w); 50 51 unsigned int combine_swizzles(unsigned int src, unsigned int swz); 52 53 rc_swizzle rc_mask_to_swizzle(unsigned int mask); 54 55 unsigned swizzle_mask(unsigned swizzle, unsigned mask); 56 57 unsigned int rc_adjust_channels( 58 unsigned int old_swizzle, 59 unsigned int conversion_swizzle); 60 61 void rc_pair_rewrite_writemask( 62 struct rc_pair_sub_instruction * sub, 63 unsigned int conversion_swizzle); 64 65 void rc_normal_rewrite_writemask( 66 struct rc_instruction * inst, 67 unsigned int conversion_swizzle); 68 69 unsigned int rc_rewrite_swizzle( 70 unsigned int swizzle, 71 unsigned int new_mask); 72 73 struct rc_src_register lmul_swizzle(unsigned int swizzle, struct rc_src_register srcreg); 74 75 void reset_srcreg(struct rc_src_register* reg); 76 77 unsigned int rc_src_reads_dst_mask( 78 rc_register_file src_file, 79 unsigned int src_idx, 80 unsigned int src_swz, 81 rc_register_file dst_file, 82 unsigned int dst_idx, 83 unsigned int dst_mask); 84 85 unsigned int rc_source_type_swz(unsigned int swizzle); 86 87 unsigned int rc_source_type_mask(unsigned int mask); 88 89 unsigned int rc_inst_can_use_presub( 90 struct rc_instruction * inst, 91 rc_presubtract_op presub_op, 92 unsigned int presub_writemask, 93 const struct rc_src_register * replace_reg, 94 const struct rc_src_register * presub_src0, 95 const struct rc_src_register * presub_src1); 96 97 int rc_get_max_index( 98 struct radeon_compiler * c, 99 rc_register_file file); 100 101 unsigned int rc_pair_remove_src( 102 struct rc_instruction * inst, 103 unsigned int src_type, 104 unsigned int source, 105 unsigned int new_readmask); 106 107 rc_opcode rc_get_flow_control_inst(struct rc_instruction * inst); 108 109 struct rc_instruction * rc_match_endloop(struct rc_instruction * endloop); 110 struct rc_instruction * rc_match_bgnloop(struct rc_instruction * bgnloop); 111 112 unsigned int rc_make_conversion_swizzle( 113 unsigned int old_mask, 114 unsigned int new_mask); 115 116 unsigned int rc_src_reg_is_immediate( 117 struct radeon_compiler * c, 118 unsigned int file, 119 unsigned int index); 120 121 float rc_get_constant_value( 122 struct radeon_compiler * c, 123 unsigned int index, 124 unsigned int swizzle, 125 unsigned int negate, 126 unsigned int chan); 127 128 unsigned int rc_get_scalar_src_swz(unsigned int swizzle); 129 130 #endif /* RADEON_PROGRAM_UTIL_H */ 131