xref: /aosp_15_r20/external/mesa3d/src/gallium/drivers/r300/compiler/radeon_compiler_util.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * Copyright 2010 Tom Stellard <[email protected]>
3  * SPDX-License-Identifier: MIT
4  */
5 
6 #include "radeon_program_constants.h"
7 
8 #ifndef RADEON_PROGRAM_UTIL_H
9 #define RADEON_PROGRAM_UTIL_H
10 
11 #include <stdbool.h>
12 
13 #include "radeon_opcodes.h"
14 
15 struct radeon_compiler;
16 struct rc_instruction;
17 struct rc_pair_instruction;
18 struct rc_pair_sub_instruction;
19 struct rc_src_register;
20 
21 unsigned int rc_swizzle_to_writemask(unsigned int swz);
22 
23 rc_swizzle get_swz(unsigned int swz, rc_swizzle idx);
24 
25 unsigned int rc_init_swizzle(unsigned int initial_value, unsigned int channels);
26 
27 unsigned int combine_swizzles4(unsigned int src,
28 			       rc_swizzle swz_x, rc_swizzle swz_y,
29 			       rc_swizzle swz_z, rc_swizzle swz_w);
30 
31 unsigned int combine_swizzles(unsigned int src, unsigned int swz);
32 
33 rc_swizzle rc_mask_to_swizzle(unsigned int mask);
34 
35 unsigned swizzle_mask(unsigned swizzle, unsigned mask);
36 
37 unsigned int rc_adjust_channels(
38 	unsigned int old_swizzle,
39 	unsigned int conversion_swizzle);
40 
41 void rc_pair_rewrite_writemask(
42 	struct rc_pair_sub_instruction * sub,
43 	unsigned int conversion_swizzle);
44 
45 void rc_normal_rewrite_writemask(
46 	struct rc_instruction * inst,
47 	unsigned int conversion_swizzle);
48 
49 unsigned int rc_rewrite_swizzle(
50 	unsigned int swizzle,
51 	unsigned int new_mask);
52 
53 struct rc_src_register lmul_swizzle(unsigned int swizzle, struct rc_src_register srcreg);
54 
55 void reset_srcreg(struct rc_src_register* reg);
56 
57 unsigned int rc_src_reads_dst_mask(
58 		rc_register_file src_file,
59 		unsigned int src_idx,
60 		unsigned int src_swz,
61 		rc_register_file dst_file,
62 		unsigned int dst_idx,
63 		unsigned int dst_mask);
64 
65 unsigned int rc_source_type_swz(unsigned int swizzle);
66 
67 unsigned int rc_source_type_mask(unsigned int mask);
68 
69 unsigned int rc_inst_can_use_presub(
70 	struct radeon_compiler * c,
71 	struct rc_instruction * inst,
72 	rc_presubtract_op presub_op,
73 	unsigned int presub_writemask,
74 	const struct rc_src_register * replace_reg,
75 	const struct rc_src_register * presub_src0,
76 	const struct rc_src_register * presub_src1);
77 
78 int rc_get_max_index(
79 	struct radeon_compiler * c,
80 	rc_register_file file);
81 
82 void rc_pair_remove_src(struct rc_instruction * inst,
83 	unsigned int src_type,
84 	unsigned int source);
85 
86 rc_opcode rc_get_flow_control_inst(struct rc_instruction * inst);
87 
88 struct rc_instruction * rc_match_endloop(struct rc_instruction * endloop);
89 struct rc_instruction * rc_match_bgnloop(struct rc_instruction * bgnloop);
90 
91 unsigned int rc_make_conversion_swizzle(
92 	unsigned int old_mask,
93 	unsigned int new_mask);
94 
95 unsigned int rc_src_reg_is_immediate(
96 	struct radeon_compiler * c,
97 	unsigned int file,
98 	unsigned int index);
99 
100 float rc_get_constant_value(
101 	struct radeon_compiler * c,
102 	unsigned int index,
103 	unsigned int swizzle,
104 	unsigned int negate,
105 	unsigned int chan);
106 
107 unsigned int rc_get_scalar_src_swz(unsigned int swizzle);
108 
109 bool rc_inst_has_three_diff_temp_srcs(struct rc_instruction *inst);
110 
111 float rc_inline_to_float(int index);
112 #endif /* RADEON_PROGRAM_UTIL_H */
113