1 ///////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2013 Academy of Motion Picture Arts and Sciences
3 // ("A.M.P.A.S."). Portions contributed by others as indicated.
4 // All rights reserved.
5 //
6 // A worldwide, royalty-free, non-exclusive right to copy, modify, create
7 // derivatives, and use, in source and binary forms, is hereby granted,
8 // subject to acceptance of this license. Performance of any of the
9 // aforementioned acts indicates acceptance to be bound by the following
10 // terms and conditions:
11 //
12 // * Copies of source code, in whole or in part, must retain the
13 // above copyright notice, this list of conditions and the
14 // Disclaimer of Warranty.
15 //
16 // * Use in binary form must retain the above copyright notice,
17 // this list of conditions and the Disclaimer of Warranty in the
18 // documentation and/or other materials provided with the distribution.
19 //
20 // * Nothing in this license shall be deemed to grant any rights to
21 // trademarks, copyrights, patents, trade secrets or any other
22 // intellectual property of A.M.P.A.S. or any contributors, except
23 // as expressly stated herein.
24 //
25 // * Neither the name "A.M.P.A.S." nor the name of any other
26 // contributors to this software may be used to endorse or promote
27 // products derivative of or based on this software without express
28 // prior written permission of A.M.P.A.S. or the contributors, as
29 // appropriate.
30 //
31 // This license shall be construed pursuant to the laws of the State of
32 // California, and any disputes related thereto shall be subject to the
33 // jurisdiction of the courts therein.
34 //
35 // Disclaimer of Warranty: THIS SOFTWARE IS PROVIDED BY A.M.P.A.S. AND
36 // CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
37 // BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
38 // FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT ARE DISCLAIMED. IN NO
39 // EVENT SHALL A.M.P.A.S., OR ANY CONTRIBUTORS OR DISTRIBUTORS, BE LIABLE
40 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, RESITUTIONARY,
41 // OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
42 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
43 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
44 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
46 // THE POSSIBILITY OF SUCH DAMAGE.
47 //
48 // WITHOUT LIMITING THE GENERALITY OF THE FOREGOING, THE ACADEMY
49 // SPECIFICALLY DISCLAIMS ANY REPRESENTATIONS OR WARRANTIES WHATSOEVER
50 // RELATED TO PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS IN THE ACADEMY
51 // COLOR ENCODING SYSTEM, OR APPLICATIONS THEREOF, HELD BY PARTIES OTHER
52 // THAN A.M.P.A.S., WHETHER DISCLOSED OR UNDISCLOSED.
53 ///////////////////////////////////////////////////////////////////////////
54
55 //-----------------------------------------------------------------------------
56 //
57 // The Standard Library of C++ functions that can be called from CTL
58 //
59 // - math functions (cos(), exp(), sqrt(), etc.)
60 // - vectors and matrices
61 //
62 //-----------------------------------------------------------------------------
63
64 #include <CtlSimdStdLibMath.h>
65 #include <CtlSimdStdLibTemplates.h>
66 #include <CtlSimdStdLibrary.h>
67 #include <CtlSimdStdTypes.h>
68 #include <CtlSimdCFunc.h>
69 #include <CtlSimdHalfExpLog.h>
70 #include <ImathMatrix.h>
71 #include <cmath>
72
73 using namespace Imath;
74 using namespace std;
75
76 namespace Ctl {
77 namespace {
78
79 DEFINE_SIMD_FUNC_1_ARG (Acos, acos (a1), float, float);
80 DEFINE_SIMD_FUNC_1_ARG (Asin, asin (a1), float, float);
81 DEFINE_SIMD_FUNC_1_ARG (Atan, atan (a1), float, float);
82 DEFINE_SIMD_FUNC_2_ARG (Atan2, atan2 (a1, a2), float, float, float);
83 DEFINE_SIMD_FUNC_1_ARG (Cos, cos (a1), float, float);
84 DEFINE_SIMD_FUNC_1_ARG (Sin, sin (a1), float, float);
85 DEFINE_SIMD_FUNC_1_ARG (Tan, tan (a1), float, float);
86 DEFINE_SIMD_FUNC_1_ARG (Cosh, cosh (a1), float, float);
87 DEFINE_SIMD_FUNC_1_ARG (Sinh, sinh (a1), float, float);
88 DEFINE_SIMD_FUNC_1_ARG (Tanh, tanh (a1), float, float);
89 DEFINE_SIMD_FUNC_1_ARG (Exp, exp (a1), float, float);
90 DEFINE_SIMD_FUNC_1_ARG (ExpH, exp_h (a1), half, float);
91 DEFINE_SIMD_FUNC_1_ARG (Log, log (a1), float, float);
92 DEFINE_SIMD_FUNC_1_ARG (LogH, log_h (a1), float, half);
93 DEFINE_SIMD_FUNC_1_ARG (Log10, log10 (a1), float, float);
94 DEFINE_SIMD_FUNC_1_ARG (Log10H, log10_h (a1), float, half);
95 DEFINE_SIMD_FUNC_2_ARG (Pow, pow (a1, a2), float, float, float);
96 DEFINE_SIMD_FUNC_2_ARG (PowH, pow_h (a1, a2), half, half, float);
97 DEFINE_SIMD_FUNC_1_ARG (Pow10, pow (10.0f, a1), float, float);
98 DEFINE_SIMD_FUNC_1_ARG (Pow10H, pow10_h (a1), half, float);
99 DEFINE_SIMD_FUNC_1_ARG (Sqrt, sqrt (a1), float, float);
100 DEFINE_SIMD_FUNC_1_ARG (Fabs, fabs (a1), float, float);
101 DEFINE_SIMD_FUNC_1_ARG (Floor, floor (a1), float, float);
102 DEFINE_SIMD_FUNC_2_ARG (Fmod, fmod (a1, a2), float, float, float);
103 DEFINE_SIMD_FUNC_2_ARG (Hypot, hypot (a1, a2), float, float, float);
104 DEFINE_SIMD_FUNC_2_ARG (Mult_f33_f33, a1 * a2, M33f, M33f, M33f);
105 DEFINE_SIMD_FUNC_2_ARG (Mult_f44_f44, a1 * a2, M44f, M44f, M44f);
106 DEFINE_SIMD_FUNC_2_ARG (Mult_f_f33, a1 * a2, M33f, float, M33f);
107 DEFINE_SIMD_FUNC_2_ARG (Mult_f_f44, a1 * a2, M44f, float, M44f);
108 DEFINE_SIMD_FUNC_2_ARG (Add_f33_f33, a1 + a2, M33f, M33f, M33f);
109 DEFINE_SIMD_FUNC_2_ARG (Add_f44_f44, a1 + a2, M44f, M44f, M44f);
110 DEFINE_SIMD_FUNC_1_ARG (Invert_f33, a1.inverse(), M33f, M33f);
111 DEFINE_SIMD_FUNC_1_ARG (Invert_f44, a1.inverse(), M44f, M44f);
112 DEFINE_SIMD_FUNC_1_ARG (Transpose_f33, a1.transposed(), M33f, M33f);
113 DEFINE_SIMD_FUNC_1_ARG (Transpose_f44, a1.transposed(), M44f, M44f);
114 DEFINE_SIMD_FUNC_2_ARG (Mult_f3_f33, a1 * a2, V3f, V3f, M33f);
115 DEFINE_SIMD_FUNC_2_ARG (Mult_f3_f44, a1 * a2, V3f, V3f, M44f);
116 DEFINE_SIMD_FUNC_2_ARG (Mult_f_f3, a1 * a2, V3f, float, V3f);
117 DEFINE_SIMD_FUNC_2_ARG (Add_f3_f3, a1 + a2, V3f, V3f, V3f);
118 DEFINE_SIMD_FUNC_2_ARG (Sub_f3_f3, a1 - a2, V3f, V3f, V3f);
119 DEFINE_SIMD_FUNC_2_ARG (Cross_f3_f3, a1.cross(a2), V3f, V3f, V3f);
120 DEFINE_SIMD_FUNC_2_ARG (Dot_f3_f3, a1.dot(a2), float, V3f, V3f);
121 DEFINE_SIMD_FUNC_1_ARG (Length_f3, a1.length(), float, V3f);
122
123 } // namespace
124
125
126 void
declareSimdStdLibMath(SymbolTable & symtab,SimdStdTypes & types)127 declareSimdStdLibMath (SymbolTable &symtab, SimdStdTypes &types)
128 {
129 declareSimdCFunc (symtab, simdFunc1Arg <Acos>,
130 types.funcType_f_f(), "acos");
131
132 declareSimdCFunc (symtab, simdFunc1Arg <Asin>,
133 types.funcType_f_f(), "asin");
134
135 declareSimdCFunc (symtab, simdFunc1Arg <Atan>,
136 types.funcType_f_f(), "atan");
137
138 declareSimdCFunc (symtab, simdFunc2Arg <Atan2>,
139 types.funcType_f_f_f(), "atan2");
140
141 declareSimdCFunc (symtab, simdFunc1Arg <Cos>,
142 types.funcType_f_f(), "cos");
143
144 declareSimdCFunc (symtab, simdFunc1Arg <Sin>,
145 types.funcType_f_f(), "sin");
146
147 declareSimdCFunc (symtab, simdFunc1Arg <Tan>,
148 types.funcType_f_f(), "tan");
149
150 declareSimdCFunc (symtab, simdFunc1Arg <Cosh>,
151 types.funcType_f_f(), "cosh");
152
153 declareSimdCFunc (symtab, simdFunc1Arg <Sinh>,
154 types.funcType_f_f(), "sinh");
155
156 declareSimdCFunc (symtab, simdFunc1Arg <Tanh>,
157 types.funcType_f_f(), "tanh");
158
159 declareSimdCFunc (symtab, simdFunc1Arg <Exp>,
160 types.funcType_f_f(), "exp");
161
162 declareSimdCFunc (symtab, simdFunc1Arg <ExpH>,
163 types.funcType_h_f(), "exp_h");
164
165 declareSimdCFunc (symtab, simdFunc1Arg <Log>,
166 types.funcType_f_f(), "log");
167
168 declareSimdCFunc (symtab, simdFunc1Arg <LogH>,
169 types.funcType_f_h(), "log_h");
170
171 declareSimdCFunc (symtab, simdFunc1Arg <Log10>,
172 types.funcType_f_f(), "log10");
173
174 declareSimdCFunc (symtab, simdFunc1Arg <Log10H>,
175 types.funcType_f_h(), "log10_h");
176
177 declareSimdCFunc (symtab, simdFunc2Arg <Pow>,
178 types.funcType_f_f_f(), "pow");
179
180 declareSimdCFunc (symtab, simdFunc2Arg <PowH>,
181 types.funcType_h_h_f(), "pow_h");
182
183 declareSimdCFunc (symtab, simdFunc1Arg <Pow10>,
184 types.funcType_f_f(), "pow10");
185
186 declareSimdCFunc (symtab, simdFunc1Arg <Pow10H>,
187 types.funcType_h_f(), "pow10_h");
188
189 declareSimdCFunc (symtab, simdFunc1Arg <Sqrt>,
190 types.funcType_f_f(), "sqrt");
191
192 declareSimdCFunc (symtab, simdFunc1Arg <Fabs>,
193 types.funcType_f_f(), "fabs");
194
195 declareSimdCFunc (symtab, simdFunc1Arg <Floor>,
196 types.funcType_f_f(), "floor");
197
198 declareSimdCFunc (symtab, simdFunc2Arg <Fmod>,
199 types.funcType_f_f_f(), "fmod");
200
201 declareSimdCFunc (symtab, simdFunc2Arg <Hypot>,
202 types.funcType_f_f_f(), "hypot");
203
204 declareSimdCFunc (symtab, simdFunc2Arg <Mult_f33_f33>,
205 types.funcType_f33_f33_f33(), "mult_f33_f33");
206
207 declareSimdCFunc (symtab, simdFunc2Arg <Mult_f44_f44>,
208 types.funcType_f44_f44_f44(), "mult_f44_f44");
209
210 declareSimdCFunc (symtab, simdFunc2Arg <Mult_f_f33>,
211 types.funcType_f33_f_f33(), "mult_f_f33");
212
213 declareSimdCFunc (symtab, simdFunc2Arg <Mult_f_f44>,
214 types.funcType_f44_f_f44(), "mult_f_f44");
215
216 declareSimdCFunc (symtab, simdFunc2Arg <Add_f33_f33>,
217 types.funcType_f33_f33_f33(), "add_f33_f33");
218
219 declareSimdCFunc (symtab, simdFunc2Arg <Add_f44_f44>,
220 types.funcType_f44_f44_f44(), "add_f44_f44");
221
222 declareSimdCFunc (symtab, simdFunc1Arg <Invert_f33>,
223 types.funcType_f33_f33(), "invert_f33");
224
225 declareSimdCFunc (symtab, simdFunc1Arg <Invert_f44>,
226 types.funcType_f44_f44(), "invert_f44");
227
228 declareSimdCFunc (symtab, simdFunc1Arg <Transpose_f33>,
229 types.funcType_f33_f33(), "transpose_f33");
230
231 declareSimdCFunc (symtab, simdFunc1Arg <Transpose_f44>,
232 types.funcType_f44_f44(), "transpose_f44");
233
234 declareSimdCFunc (symtab, simdFunc2Arg <Mult_f3_f33>,
235 types.funcType_f3_f3_f33(), "mult_f3_f33");
236
237 declareSimdCFunc (symtab, simdFunc2Arg <Mult_f3_f44>,
238 types.funcType_f3_f3_f44(), "mult_f3_f44");
239
240 declareSimdCFunc (symtab, simdFunc2Arg <Mult_f_f3>,
241 types.funcType_f3_f_f3(), "mult_f_f3");
242
243 declareSimdCFunc (symtab, simdFunc2Arg <Add_f3_f3>,
244 types.funcType_f3_f3_f3(), "add_f3_f3");
245
246 declareSimdCFunc (symtab, simdFunc2Arg <Sub_f3_f3>,
247 types.funcType_f3_f3_f3(), "sub_f3_f3");
248
249 declareSimdCFunc (symtab, simdFunc2Arg <Cross_f3_f3>,
250 types.funcType_f3_f3_f3(), "cross_f3_f3");
251
252 declareSimdCFunc (symtab, simdFunc2Arg <Dot_f3_f3>,
253 types.funcType_f_f3_f3(), "dot_f3_f3");
254
255 declareSimdCFunc (symtab, simdFunc1Arg <Length_f3>,
256 types.funcType_f_f3(), "length_f3");
257 }
258
259 } // namespace Ctl
260