llvmpipe: Split control flow function declarations and notes.
[mesa.git] / src / gallium / drivers / llvmpipe / lp_bld_type.h
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 * Convenient representation of SIMD types.
31 *
32 * @author Jose Fonseca <jfonseca@vmware.com>
33 */
34
35
36 #ifndef LP_BLD_TYPE_H
37 #define LP_BLD_TYPE_H
38
39
40 #include <llvm-c/Core.h>
41
42 #include <pipe/p_compiler.h>
43
44
45 /**
46 * Several functions can only cope with vectors of length up to this value.
47 * You may need to increase that value if you want to represent bigger vectors.
48 */
49 #define LP_MAX_VECTOR_LENGTH 16
50
51 #define LP_MAX_TYPE_WIDTH 64
52
53
54 /**
55 * The LLVM type system can't conveniently express all the things we care about
56 * on the types used for intermediate computations, such as signed vs unsigned,
57 * normalized values, or fixed point.
58 */
59 union lp_type {
60 struct {
61 /**
62 * Floating-point. Cannot be used with fixed. Integer numbers are
63 * represented by this zero.
64 */
65 unsigned floating:1;
66
67 /**
68 * Fixed-point. Cannot be used with floating. Integer numbers are
69 * represented by this zero.
70 */
71 unsigned fixed:1;
72
73 /**
74 * Whether it can represent negative values or not.
75 *
76 * If this is not set for floating point, it means that all values are
77 * assumed to be positive.
78 */
79 unsigned sign:1;
80
81 /**
82 * Whether values are normalized to fit [0, 1] interval, or [-1, 1]
83 * interval for signed types.
84 *
85 * For integer types it means the representable integer range should be
86 * interpreted as the interval above.
87 *
88 * For floating and fixed point formats it means the values should be
89 * clamped to the interval above.
90 */
91 unsigned norm:1;
92
93 /**
94 * Element width.
95 *
96 * For fixed point values, the fixed point is assumed to be at half the
97 * width.
98 */
99 unsigned width:14;
100
101 /**
102 * Vector length.
103 *
104 * width*length should be a power of two greater or equal to eight.
105 *
106 * @sa LP_MAX_VECTOR_LENGTH
107 */
108 unsigned length:14;
109 };
110 uint32_t value;
111 };
112
113
114 /**
115 * We need most of the information here in order to correctly and efficiently
116 * translate an arithmetic operation into LLVM IR. Putting it here avoids the
117 * trouble of passing it as parameters.
118 */
119 struct lp_build_context
120 {
121 LLVMBuilderRef builder;
122
123 /**
124 * This not only describes the input/output LLVM types, but also whether
125 * to normalize/clamp the results.
126 */
127 union lp_type type;
128
129 /** Same as lp_build_undef(type) */
130 LLVMValueRef undef;
131
132 /** Same as lp_build_zero(type) */
133 LLVMValueRef zero;
134
135 /** Same as lp_build_one(type) */
136 LLVMValueRef one;
137 };
138
139
140 LLVMTypeRef
141 lp_build_elem_type(union lp_type type);
142
143
144 LLVMTypeRef
145 lp_build_vec_type(union lp_type type);
146
147
148 boolean
149 lp_check_elem_type(union lp_type type, LLVMTypeRef elem_type);
150
151
152 boolean
153 lp_check_vec_type(union lp_type type, LLVMTypeRef vec_type);
154
155
156 boolean
157 lp_check_value(union lp_type type, LLVMValueRef val);
158
159
160 LLVMTypeRef
161 lp_build_int_elem_type(union lp_type type);
162
163
164 LLVMTypeRef
165 lp_build_int_vec_type(union lp_type type);
166
167
168 void
169 lp_build_context_init(struct lp_build_context *bld,
170 LLVMBuilderRef builder,
171 union lp_type type);
172
173
174 #endif /* !LP_BLD_TYPE_H */