swr/rasterizer: improvements in simdlib
[mesa.git] / src / gallium / drivers / swr / rasterizer / jitter / builder_misc.h
1 /****************************************************************************
2 * Copyright (C) 2014-2015 Intel Corporation. All Rights Reserved.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 *
23 * @file builder_misc.h
24 *
25 * @brief miscellaneous builder functions
26 *
27 * Notes:
28 *
29 ******************************************************************************/
30 #pragma once
31
32 Constant* C(bool i);
33 Constant* C(char i);
34 Constant* C(uint8_t i);
35 Constant* C(int i);
36 Constant* C(int64_t i);
37 Constant* C(uint64_t i);
38 Constant* C(uint16_t i);
39 Constant* C(uint32_t i);
40 Constant* C(float i);
41
42 template <typename Ty>
43 Constant* C(const std::initializer_list<Ty>& constList)
44 {
45 std::vector<Constant*> vConsts;
46 for (auto i : constList)
47 {
48 vConsts.push_back(C((Ty)i));
49 }
50 return ConstantVector::get(vConsts);
51 }
52
53 template <typename Ty>
54 Constant* CA(LLVMContext& ctx, ArrayRef<Ty> constList)
55 {
56 return ConstantDataArray::get(ctx, constList);
57 }
58
59 template <typename Ty>
60 Constant* CInc(uint32_t base, uint32_t count)
61 {
62 std::vector<Constant*> vConsts;
63
64 for (uint32_t i = 0; i < count; i++)
65 {
66 vConsts.push_back(C((Ty)base));
67 base++;
68 }
69 return ConstantVector::get(vConsts);
70 }
71
72 Constant* PRED(bool pred);
73
74 Value* VIMMED1(uint64_t i);
75 Value* VIMMED1_16(uint64_t i);
76
77 Value* VIMMED1(int i);
78 Value* VIMMED1_16(int i);
79
80 Value* VIMMED1(uint32_t i);
81 Value* VIMMED1_16(uint32_t i);
82
83 Value* VIMMED1(float i);
84 Value* VIMMED1_16(float i);
85
86 Value* VIMMED1(bool i);
87 Value* VIMMED1_16(bool i);
88
89 Value* VUNDEF(Type* t);
90
91 Value* VUNDEF_F();
92 Value* VUNDEF_F_16();
93
94 Value* VUNDEF_I();
95 Value* VUNDEF_I_16();
96
97 Value* VUNDEF(Type* ty, uint32_t size);
98
99 Value* VUNDEF_IPTR();
100
101 Value* VBROADCAST(Value* src, const llvm::Twine& name = "");
102 Value* VBROADCAST_16(Value* src);
103
104 Value* VRCP(Value* va, const llvm::Twine& name = "");
105 Value* VPLANEPS(Value* vA, Value* vB, Value* vC, Value*& vX, Value*& vY);
106
107 uint32_t IMMED(Value* i);
108 int32_t S_IMMED(Value* i);
109
110 CallInst*
111 CALL(Value* Callee, const std::initializer_list<Value*>& args, const llvm::Twine& name = "");
112 CallInst* CALL(Value* Callee)
113 {
114 return CALLA(Callee);
115 }
116 CallInst* CALL(Value* Callee, Value* arg);
117 CallInst* CALL2(Value* Callee, Value* arg1, Value* arg2);
118 CallInst* CALL3(Value* Callee, Value* arg1, Value* arg2, Value* arg3);
119
120 Value* MASK(Value* vmask);
121 Value* MASK_16(Value* vmask);
122
123 Value* VMASK(Value* mask);
124 Value* VMASK_16(Value* mask);
125
126 Value* VMOVMSK(Value* mask);
127
128 //////////////////////////////////////////////////////////////////////////
129 /// @brief Float / Fixed-point conversions
130 //////////////////////////////////////////////////////////////////////////
131 // Signed
132 Value* VCVT_F32_FIXED_SI(Value* vFloat,
133 uint32_t numIntBits,
134 uint32_t numFracBits,
135 const llvm::Twine& name = "");
136 Value* VCVT_FIXED_SI_F32(Value* vFixed,
137 uint32_t numIntBits,
138 uint32_t numFracBits,
139 const llvm::Twine& name = "");
140 // Unsigned
141 Value* VCVT_F32_FIXED_UI(Value* vFloat,
142 uint32_t numIntBits,
143 uint32_t numFracBits,
144 const llvm::Twine& name = "");
145 Value* VCVT_FIXED_UI_F32(Value* vFixed,
146 uint32_t numIntBits,
147 uint32_t numFracBits,
148 const llvm::Twine& name = "");
149
150 //////////////////////////////////////////////////////////////////////////
151 /// @brief functions that build IR to call x86 intrinsics directly, or
152 /// emulate them with other instructions if not available on the host
153 //////////////////////////////////////////////////////////////////////////
154
155 Value* EXTRACT_16(Value* x, uint32_t imm);
156 Value* JOIN_16(Value* a, Value* b);
157
158 Value* PSHUFB(Value* a, Value* b);
159 Value* PMOVSXBD(Value* a);
160 Value* PMOVSXWD(Value* a);
161 Value* CVTPH2PS(Value* a, const llvm::Twine& name = "");
162 Value* CVTPS2PH(Value* a, Value* rounding);
163 Value* PMAXSD(Value* a, Value* b);
164 Value* PMINSD(Value* a, Value* b);
165 Value* PMAXUD(Value* a, Value* b);
166 Value* PMINUD(Value* a, Value* b);
167 Value* VABSPS(Value* a);
168 Value* FMADDPS(Value* a, Value* b, Value* c);
169
170 Value* ICLAMP(Value* src, Value* low, Value* high, const llvm::Twine& name = "");
171 Value* FCLAMP(Value* src, Value* low, Value* high);
172 Value* FCLAMP(Value* src, float low, float high);
173
174 CallInst* PRINT(const std::string& printStr);
175 CallInst* PRINT(const std::string& printStr, const std::initializer_list<Value*>& printArgs);
176
177 Value* VPOPCNT(Value* a);
178
179 Value* INT3()
180 {
181 return DEBUGTRAP();
182 }
183
184
185 Value* VEXTRACTI128(Value* a, Constant* imm8);
186 Value* VINSERTI128(Value* a, Value* b, Constant* imm8);
187
188 // rdtsc buckets macros
189 void RDTSC_START(Value* pBucketMgr, Value* pId);
190 void RDTSC_STOP(Value* pBucketMgr, Value* pId);
191
192 Value* CreateEntryAlloca(Function* pFunc, Type* pType);
193 Value* CreateEntryAlloca(Function* pFunc, Type* pType, Value* pArraySize);
194
195 uint32_t GetTypeSize(Type* pType);