xref: /aosp_15_r20/external/mesa3d/src/gallium/auxiliary/gallivm/lp_bld_const.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /**************************************************************************
2  *
3  * Copyright 2009 VMware, Inc.
4  * All Rights Reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * 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, sub license, 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 portions
16  * of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21  * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25  *
26  **************************************************************************/
27 
28 /**
29  * @file
30  * Helper functions for constant building.
31  *
32  * @author Jose Fonseca <[email protected]>
33  */
34 
35 
36 #ifndef LP_BLD_CONST_H
37 #define LP_BLD_CONST_H
38 
39 
40 #include "util/compiler.h"
41 #include "gallivm/lp_bld.h"
42 #include "gallivm/lp_bld_init.h"
43 
44 
45 
46 struct lp_type;
47 
48 
49 unsigned
50 lp_mantissa(struct lp_type type);
51 
52 
53 unsigned
54 lp_const_shift(struct lp_type type);
55 
56 
57 unsigned
58 lp_const_offset(struct lp_type type);
59 
60 
61 double
62 lp_const_scale(struct lp_type type);
63 
64 double
65 lp_const_min(struct lp_type type);
66 
67 
68 double
69 lp_const_max(struct lp_type type);
70 
71 
72 double
73 lp_const_eps(struct lp_type type);
74 
75 
76 LLVMValueRef
77 lp_build_undef(struct gallivm_state *gallivm, struct lp_type type);
78 
79 
80 LLVMValueRef
81 lp_build_zero(struct gallivm_state *gallivm, struct lp_type type);
82 
83 
84 LLVMValueRef
85 lp_build_one(struct gallivm_state *gallivm, struct lp_type type);
86 
87 
88 LLVMValueRef
89 lp_build_const_elem(struct gallivm_state *gallivm, struct lp_type type,
90                     double val);
91 
92 LLVMValueRef
93 lp_build_const_vec(struct gallivm_state *gallivm, struct lp_type type,
94                    double val);
95 
96 
97 LLVMValueRef
98 lp_build_const_int_vec(struct gallivm_state *gallivm,
99                        struct lp_type type, long long val);
100 
101 LLVMValueRef
102 lp_build_const_channel_vec(struct gallivm_state *gallivm, struct lp_type type);
103 
104 LLVMValueRef
105 lp_build_const_aos(struct gallivm_state *gallivm, struct lp_type type,
106                    double r, double g, double b, double a,
107                    const unsigned char *swizzle);
108 
109 
110 LLVMValueRef
111 lp_build_const_mask_aos(struct gallivm_state *gallivm,
112                         struct lp_type type,
113                         unsigned mask,
114                         unsigned channels);
115 
116 
117 LLVMValueRef
118 lp_build_const_mask_aos_swizzled(struct gallivm_state *gallivm,
119                                  struct lp_type type,
120                                  unsigned mask,
121                                  unsigned channels,
122                                  const unsigned char *swizzle);
123 
124 
125 static inline LLVMValueRef
lp_build_const_int32(struct gallivm_state * gallivm,int i)126 lp_build_const_int32(struct gallivm_state *gallivm, int i)
127 {
128    return LLVMConstInt(LLVMInt32TypeInContext(gallivm->context), i, 0);
129 }
130 
131 static inline LLVMValueRef
lp_build_const_int64(struct gallivm_state * gallivm,int64_t i)132 lp_build_const_int64(struct gallivm_state *gallivm, int64_t i)
133 {
134    return LLVMConstInt(LLVMInt64TypeInContext(gallivm->context), i, 0);
135 }
136 
137 static inline LLVMValueRef
lp_build_const_float(struct gallivm_state * gallivm,float x)138 lp_build_const_float(struct gallivm_state *gallivm, float x)
139 {
140    return LLVMConstReal(LLVMFloatTypeInContext(gallivm->context), x);
141 }
142 
143 static inline LLVMValueRef
lp_build_const_double(struct gallivm_state * gallivm,float x)144 lp_build_const_double(struct gallivm_state *gallivm, float x)
145 {
146    return LLVMConstReal(LLVMDoubleTypeInContext(gallivm->context), x);
147 }
148 
149 
150 /** Return constant-valued pointer to int */
151 static inline LLVMValueRef
lp_build_const_int_pointer(struct gallivm_state * gallivm,const void * ptr)152 lp_build_const_int_pointer(struct gallivm_state *gallivm, const void *ptr)
153 {
154    LLVMTypeRef int_type;
155    LLVMValueRef v;
156 
157    /* int type large enough to hold a pointer */
158    int_type = LLVMIntTypeInContext(gallivm->context, 8 * sizeof(void *));
159    v = LLVMConstInt(int_type, (uintptr_t) ptr, 0);
160    v = LLVMBuildIntToPtr(gallivm->builder, v,
161                          LLVMPointerType(int_type, 0),
162                          "cast int to ptr");
163    return v;
164 }
165 
166 
167 LLVMValueRef
168 lp_build_const_string(struct gallivm_state *gallivm,
169                       const char *str);
170 
171 
172 LLVMValueRef
173 lp_build_const_func_pointer(struct gallivm_state *gallivm,
174                             const void *ptr,
175                             LLVMTypeRef ret_type,
176                             LLVMTypeRef *arg_types,
177                             unsigned num_args,
178                             const char *name);
179 
180 
181 LLVMValueRef
182 lp_build_const_func_pointer_from_type(struct gallivm_state *gallivm,
183                             const void *ptr,
184                             LLVMTypeRef function_type,
185                             const char *name);
186 
187 #endif /* !LP_BLD_CONST_H */
188