• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2011-2012 Advanced Micro Devices, Inc.
3  * All Rights Reserved.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the
7  * "Software"), to deal in the Software without restriction, including
8  * without limitation the rights to use, copy, modify, merge, publish,
9  * distribute, sub license, and/or sell copies of the Software, and to
10  * permit persons to whom the Software is furnished to do so, subject to
11  * the following conditions:
12  *
13  * The above copyright notice and this permission notice (including the
14  * next paragraph) shall be included in all copies or substantial portions
15  * of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
20  * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
21  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24  *
25  **************************************************************************/
26 
27 /**
28  *
29  * @author Tom Stellard <thomas.stellard@amd.com>
30  *
31  */
32 
33 
34 #ifndef LP_BLD_TGSI_ACTION_H
35 #define LP_BLD_TGSI_ACTION_H
36 
37 #include <llvm-c/Core.h>
38 
39 struct lp_build_tgsi_context;
40 
41 struct lp_build_emit_data {
42    /** Arguments that are passed to lp_build_tgsi_action::emit.  The
43     * order of the arguments should be as follows:
44     * SOA: s0.x, s0.y, s0.z, s0.w, s1.x, s1.y, s1.z, s1.w, s2.x, s2.y, s2.x, s2.w
45     * AOS: s0.xyzw, s1.xyzw, s2.xyzw
46     * TEXTURE Instructions: coord.xyzw
47     *
48     * Arguments should be packed into the args array.  For example an SOA
49     * instructions that reads s0.x and s1.x args should look like this:
50     * args[0] = s0.x;
51     * args[1] = s1.x;
52     */
53    LLVMValueRef args[12];
54 
55    /**
56     * Number of arguments in the args array.
57     */
58    unsigned arg_count;
59 
60    /**
61     * The type output type of the opcode.  This should be set in the
62     * lp_build_tgsi_action::fetch_args function.
63     */
64    LLVMTypeRef dst_type;
65 
66    /** This is used by the lp_build_tgsi_action::fetch_args function to
67     * determine which channel to read from the opcode arguments.  It also
68     * specifies which index of the output array should be written to by
69     * the lp_build_tgsi_action::emit function.  However, this value is
70     * usually ignored by any opcodes that are not TGSI_OUTPUT_COMPONENTWISE.
71     */
72    unsigned chan;
73 
74    /**
75     * This is used to specify the src channel to read from for doubles.
76     */
77    unsigned src_chan;
78 
79    /** The lp_build_tgsi_action::emit 'executes' the opcode and writes the
80     * results to this array.
81     */
82    LLVMValueRef output[4];
83 
84    /**
85     * Secondary output for instruction that have a second destination register.
86     */
87    LLVMValueRef output1[4];
88 
89    /**
90     * The current instruction that is being 'executed'.
91     */
92    const struct tgsi_full_instruction * inst;
93    const struct tgsi_opcode_info * info;
94 };
95 
96 struct lp_build_tgsi_action
97 {
98 
99    /**
100     * This function is responsible for doing 2-3 things:
101     * 1. Fetching the instruction arguments into the emit_data->args array.
102     * 2. Setting the number of arguments in emit_data->arg_count.
103     * 3. Setting the destination type in emit_data->dst_type (usually only
104     *    necessary for opcodes that are TGSI_OUTPUT_COMPONENTWISE).
105     */
106    void (*fetch_args)(struct lp_build_tgsi_context *,
107                       struct lp_build_emit_data *);
108 
109 
110    /**
111     * This function is responsible for emitting LLVM IR for a TGSI opcode.
112     * It should store the values it generates in the emit_data->output array
113     * and for TGSI_OUTPUT_COMPONENTWISE and TGSI_OUTPUT_REPLICATE instructions
114     * (and possibly others depending on the specific implementation), it should
115     * make sure to store the values in the array slot indexed by emit_data->chan.
116     */
117    void (*emit)(const struct lp_build_tgsi_action *,
118                         struct lp_build_tgsi_context *,
119                         struct lp_build_emit_data *);
120 
121    /**
122     * This variable can be used to store an intrinsic name, in case the TGSI
123     * opcode will be replaced by a target specific intrinsic.  (There is a
124     * convenience function in lp_bld_tgsi.c called lp_build_tgsi_intrinsic()
125     * that can be assigned to lp_build_tgsi_action::emit and used for
126     * generating intrinsics).
127     */
128    const char * intr_name;
129 };
130 
131 /**
132  * This function initializes the bld_base->op_actions array with some
133  * generic operand actions.
134  */
135 void
136 lp_set_default_actions(
137    struct lp_build_tgsi_context * bld_base);
138 
139 /*
140  * This function initialize the bld_base->op_actions array with some
141  * operand actions that are intended only for use when generating
142  * instructions to be executed on a CPU.
143  */
144 void
145 lp_set_default_actions_cpu(
146    struct lp_build_tgsi_context * bld_base);
147 
148 #endif /* LP_BLD_TGSI_ACTION_H */
149