Mercurial > octave-nkf
annotate libinterp/corefcn/jit-typeinfo.cc @ 18565:3f2a95a4b98d draft lyh-review
jit compiler: use existing int functions
author | Stefan Mahr <dac922@gmx.de> |
---|---|
date | Sun, 24 Nov 2013 22:46:32 +0100 |
parents | 5a5a67799338 |
children |
rev | line source |
---|---|
18553 | 1 #pragma GCC diagnostic push |
2 #pragma GCC diagnostic error "-Werror" | |
15016 | 3 /* |
4 | |
17744
d63878346099
maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents:
17164
diff
changeset
|
5 Copyright (C) 2012-2013 Max Brister |
15016 | 6 |
7 This file is part of Octave. | |
8 | |
9 Octave is free software; you can redistribute it and/or modify it | |
10 under the terms of the GNU General Public License as published by the | |
11 Free Software Foundation; either version 3 of the License, or (at your | |
12 option) any later version. | |
13 | |
14 Octave is distributed in the hope that it will be useful, but WITHOUT | |
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
17 for more details. | |
18 | |
19 You should have received a copy of the GNU General Public License | |
20 along with Octave; see the file COPYING. If not, see | |
21 <http://www.gnu.org/licenses/>. | |
22 | |
23 */ | |
24 | |
16768 | 25 // Author: Max Brister <max@2bass.com> |
26 | |
15016 | 27 // defines required by llvm |
28 #define __STDC_LIMIT_MACROS | |
29 #define __STDC_CONSTANT_MACROS | |
30 | |
31 #ifdef HAVE_CONFIG_H | |
32 #include <config.h> | |
33 #endif | |
34 | |
35 #ifdef HAVE_LLVM | |
36 | |
37 #include "jit-typeinfo.h" | |
38 | |
39 #include <llvm/Analysis/Verifier.h> | |
17164 | 40 #include <llvm/ExecutionEngine/ExecutionEngine.h> |
41 | |
42 #ifdef HAVE_LLVM_IR_FUNCTION_H | |
43 #include <llvm/IR/GlobalVariable.h> | |
44 #include <llvm/IR/LLVMContext.h> | |
45 #include <llvm/IR/Function.h> | |
46 #include <llvm/IR/Instructions.h> | |
47 #include <llvm/IR/Intrinsics.h> | |
48 #else | |
15016 | 49 #include <llvm/GlobalVariable.h> |
50 #include <llvm/LLVMContext.h> | |
51 #include <llvm/Function.h> | |
52 #include <llvm/Instructions.h> | |
53 #include <llvm/Intrinsics.h> | |
17164 | 54 #endif |
55 | |
56 #ifdef HAVE_LLVM_SUPPORT_IRBUILDER_H | |
15016 | 57 #include <llvm/Support/IRBuilder.h> |
17164 | 58 #elif defined(HAVE_LLVM_IR_IRBUILDER_H) |
59 #include <llvm/IR/IRBuilder.h> | |
17031
38bcfd413db0
Handle LLVM API incoherence. Octave now works with LLVM 3.0, 3.1, and 3.2
LYH <lyh.kernel@gmail.com>
parents:
16892
diff
changeset
|
60 #else |
38bcfd413db0
Handle LLVM API incoherence. Octave now works with LLVM 3.0, 3.1, and 3.2
LYH <lyh.kernel@gmail.com>
parents:
16892
diff
changeset
|
61 #include <llvm/IRBuilder.h> |
38bcfd413db0
Handle LLVM API incoherence. Octave now works with LLVM 3.0, 3.1, and 3.2
LYH <lyh.kernel@gmail.com>
parents:
16892
diff
changeset
|
62 #endif |
17164 | 63 |
15016 | 64 #include <llvm/Support/raw_os_ostream.h> |
65 | |
66 #include "jit-ir.h" | |
67 #include "ov.h" | |
68 #include "ov-builtin.h" | |
69 #include "ov-complex.h" | |
70 #include "ov-scalar.h" | |
18554 | 71 #include "ov-float.h" |
18557 | 72 #include "ov-int8.h" |
18559 | 73 #include "ov-int16.h" |
18560 | 74 #include "ov-int32.h" |
18558
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
75 #include "ov-int64.h" |
18561 | 76 #include "ov-uint8.h" |
18555 | 77 #include "ov-uint16.h" |
18563 | 78 #include "ov-uint32.h" |
18562
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
79 #include "ov-uint64.h" |
15016 | 80 #include "pager.h" |
18565
3f2a95a4b98d
jit compiler: use existing int functions
Stefan Mahr <dac922@gmx.de>
parents:
18564
diff
changeset
|
81 #include "oct-inttypes.h" |
15016 | 82 |
83 static llvm::LLVMContext& context = llvm::getGlobalContext (); | |
84 | |
85 jit_typeinfo *jit_typeinfo::instance = 0; | |
86 | |
87 std::ostream& jit_print (std::ostream& os, jit_type *atype) | |
88 { | |
89 if (! atype) | |
90 return os << "null"; | |
91 return os << atype->name (); | |
92 } | |
93 | |
94 // function that jit code calls | |
95 extern "C" void | |
96 octave_jit_print_any (const char *name, octave_base_value *obv) | |
97 { | |
98 obv->print_with_name (octave_stdout, name, true); | |
99 } | |
100 | |
101 extern "C" void | |
15019
ae3670d4df29
Update the execution engine's global mapping for external functions
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
102 octave_jit_print_scalar (const char *name, double value) |
15016 | 103 { |
104 // FIXME: We should avoid allocating a new octave_scalar each time | |
105 octave_value ov (value); | |
106 ov.print_with_name (octave_stdout, name); | |
107 } | |
108 | |
109 extern "C" octave_base_value* | |
110 octave_jit_binary_any_any (octave_value::binary_op op, octave_base_value *lhs, | |
111 octave_base_value *rhs) | |
112 { | |
113 octave_value olhs (lhs, true); | |
114 octave_value orhs (rhs, true); | |
115 octave_value result = do_binary_op (op, olhs, orhs); | |
116 octave_base_value *rep = result.internal_rep (); | |
117 rep->grab (); | |
118 return rep; | |
119 } | |
120 | |
121 extern "C" octave_idx_type | |
122 octave_jit_compute_nelem (double base, double limit, double inc) | |
123 { | |
124 Range rng = Range (base, limit, inc); | |
125 return rng.nelem (); | |
126 } | |
127 | |
128 extern "C" void | |
129 octave_jit_release_any (octave_base_value *obv) | |
130 { | |
131 obv->release (); | |
132 } | |
133 | |
134 extern "C" void | |
135 octave_jit_release_matrix (jit_matrix *m) | |
136 { | |
137 delete m->array; | |
138 } | |
139 | |
140 extern "C" octave_base_value * | |
141 octave_jit_grab_any (octave_base_value *obv) | |
142 { | |
143 obv->grab (); | |
144 return obv; | |
145 } | |
146 | |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
147 extern "C" jit_matrix |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
148 octave_jit_grab_matrix (jit_matrix *m) |
15016 | 149 { |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
150 return *m->array; |
15016 | 151 } |
152 | |
153 extern "C" octave_base_value * | |
154 octave_jit_cast_any_matrix (jit_matrix *m) | |
155 { | |
156 octave_value ret (*m->array); | |
157 octave_base_value *rep = ret.internal_rep (); | |
158 rep->grab (); | |
159 delete m->array; | |
160 | |
161 return rep; | |
162 } | |
163 | |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
164 extern "C" jit_matrix |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
165 octave_jit_cast_matrix_any (octave_base_value *obv) |
15016 | 166 { |
167 NDArray m = obv->array_value (); | |
168 obv->release (); | |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
169 return m; |
15016 | 170 } |
171 | |
15027
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
172 extern "C" octave_base_value * |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
173 octave_jit_cast_any_range (jit_range *rng) |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
174 { |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
175 Range temp (*rng); |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
176 octave_value ret (temp); |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
177 octave_base_value *rep = ret.internal_rep (); |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
178 rep->grab (); |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
179 |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
180 return rep; |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
181 } |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
182 extern "C" jit_range |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
183 octave_jit_cast_range_any (octave_base_value *obv) |
15027
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
184 { |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
185 |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
186 jit_range r (obv->range_value ()); |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
187 obv->release (); |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
188 return r; |
15027
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
189 } |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
190 |
15016 | 191 extern "C" double |
192 octave_jit_cast_scalar_any (octave_base_value *obv) | |
193 { | |
194 double ret = obv->double_value (); | |
195 obv->release (); | |
196 return ret; | |
197 } | |
198 | |
199 extern "C" octave_base_value * | |
200 octave_jit_cast_any_scalar (double value) | |
201 { | |
202 return new octave_scalar (value); | |
203 } | |
204 | |
18554 | 205 extern "C" float |
206 octave_jit_cast_single_any (octave_base_value *obv) | |
207 { | |
208 float ret = obv->float_value (); | |
209 obv->release (); | |
210 return ret; | |
211 } | |
212 | |
213 extern "C" octave_base_value * | |
214 octave_jit_cast_any_single (float value) | |
215 { | |
216 return new octave_float_scalar (value); | |
217 } | |
218 | |
18557 | 219 extern "C" int8_t |
220 octave_jit_cast_int8_any (octave_base_value *obv) | |
221 { | |
222 int8_t ret = obv->int8_scalar_value (); | |
223 obv->release (); | |
224 return ret; | |
225 } | |
226 | |
227 extern "C" octave_base_value * | |
228 octave_jit_cast_any_int8 (int8_t value) | |
229 { | |
230 return new octave_int8_scalar (value); | |
231 } | |
232 | |
18559 | 233 extern "C" int16_t |
234 octave_jit_cast_int16_any (octave_base_value *obv) | |
235 { | |
236 int16_t ret = obv->int16_scalar_value (); | |
237 obv->release (); | |
238 return ret; | |
239 } | |
240 | |
241 extern "C" octave_base_value * | |
242 octave_jit_cast_any_int16 (int16_t value) | |
243 { | |
244 return new octave_int16_scalar (value); | |
245 } | |
246 | |
18560 | 247 extern "C" int32_t |
248 octave_jit_cast_int32_any (octave_base_value *obv) | |
249 { | |
250 int32_t ret = obv->int32_scalar_value (); | |
251 obv->release (); | |
252 return ret; | |
253 } | |
254 | |
255 extern "C" octave_base_value * | |
256 octave_jit_cast_any_int32 (int32_t value) | |
257 { | |
258 return new octave_int32_scalar (value); | |
259 } | |
260 | |
18558
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
261 extern "C" int64_t |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
262 octave_jit_cast_int64_any (octave_base_value *obv) |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
263 { |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
264 int64_t ret = obv->int64_scalar_value (); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
265 obv->release (); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
266 return ret; |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
267 } |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
268 |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
269 extern "C" octave_base_value * |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
270 octave_jit_cast_any_int64 (int64_t value) |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
271 { |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
272 return new octave_int64_scalar (value); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
273 } |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
274 |
18561 | 275 extern "C" uint8_t |
276 octave_jit_cast_uint8_any (octave_base_value *obv) | |
277 { | |
278 uint8_t ret = obv->uint8_scalar_value (); | |
279 obv->release (); | |
280 return ret; | |
281 } | |
282 | |
283 extern "C" octave_base_value * | |
284 octave_jit_cast_any_uint8 (uint8_t value) | |
285 { | |
286 return new octave_uint8_scalar (value); | |
287 } | |
288 | |
18555 | 289 extern "C" uint16_t |
290 octave_jit_cast_uint16_any (octave_base_value *obv) | |
291 { | |
292 uint16_t ret = obv->uint16_scalar_value (); | |
293 obv->release (); | |
294 return ret; | |
295 } | |
296 | |
297 extern "C" octave_base_value * | |
298 octave_jit_cast_any_uint16 (uint16_t value) | |
299 { | |
300 return new octave_uint16_scalar (value); | |
301 } | |
302 | |
18563 | 303 extern "C" uint32_t |
304 octave_jit_cast_uint32_any (octave_base_value *obv) | |
305 { | |
306 uint32_t ret = obv->uint32_scalar_value (); | |
307 obv->release (); | |
308 return ret; | |
309 } | |
310 | |
311 extern "C" octave_base_value * | |
312 octave_jit_cast_any_uint32 (uint32_t value) | |
313 { | |
314 return new octave_uint32_scalar (value); | |
315 } | |
316 | |
18562
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
317 extern "C" uint64_t |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
318 octave_jit_cast_uint64_any (octave_base_value *obv) |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
319 { |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
320 uint64_t ret = obv->uint64_scalar_value (); |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
321 obv->release (); |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
322 return ret; |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
323 } |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
324 |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
325 extern "C" octave_base_value * |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
326 octave_jit_cast_any_uint64 (uint64_t value) |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
327 { |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
328 return new octave_uint64_scalar (value); |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
329 } |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
330 |
15016 | 331 extern "C" Complex |
332 octave_jit_cast_complex_any (octave_base_value *obv) | |
333 { | |
334 Complex ret = obv->complex_value (); | |
335 obv->release (); | |
336 return ret; | |
337 } | |
338 | |
339 extern "C" octave_base_value * | |
340 octave_jit_cast_any_complex (Complex c) | |
341 { | |
342 if (c.imag () == 0) | |
343 return new octave_scalar (c.real ()); | |
344 else | |
345 return new octave_complex (c); | |
346 } | |
347 | |
348 extern "C" void | |
349 octave_jit_gripe_nan_to_logical_conversion (void) | |
350 { | |
351 try | |
352 { | |
353 gripe_nan_to_logical_conversion (); | |
354 } | |
355 catch (const octave_execution_exception&) | |
356 { | |
357 gripe_library_execution_error (); | |
358 } | |
359 } | |
360 | |
361 extern "C" void | |
362 octave_jit_ginvalid_index (void) | |
363 { | |
364 try | |
365 { | |
366 gripe_invalid_index (); | |
367 } | |
368 catch (const octave_execution_exception&) | |
369 { | |
370 gripe_library_execution_error (); | |
371 } | |
372 } | |
373 | |
374 extern "C" void | |
375 octave_jit_gindex_range (int nd, int dim, octave_idx_type iext, | |
376 octave_idx_type ext) | |
377 { | |
378 try | |
379 { | |
380 gripe_index_out_of_range (nd, dim, iext, ext); | |
381 } | |
382 catch (const octave_execution_exception&) | |
383 { | |
384 gripe_library_execution_error (); | |
385 } | |
386 } | |
387 | |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
388 extern "C" jit_matrix |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
389 octave_jit_paren_subsasgn_impl (jit_matrix *mat, octave_idx_type index, |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
390 double value) |
15016 | 391 { |
392 NDArray *array = mat->array; | |
393 if (array->nelem () < index) | |
394 array->resize1 (index); | |
395 | |
396 double *data = array->fortran_vec (); | |
397 data[index - 1] = value; | |
398 | |
399 mat->update (); | |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
400 return *mat; |
15016 | 401 } |
402 | |
15068
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
403 static void |
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
404 make_indices (double *indices, octave_idx_type idx_count, |
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
405 Array<idx_vector>& result) |
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
406 { |
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
407 result.resize (dim_vector (1, idx_count)); |
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
408 for (octave_idx_type i = 0; i < idx_count; ++i) |
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
409 result(i) = idx_vector (indices[i]); |
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
410 } |
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
411 |
15067 | 412 extern "C" double |
413 octave_jit_paren_scalar (jit_matrix *mat, double *indicies, | |
414 octave_idx_type idx_count) | |
415 { | |
416 // FIXME: Replace this with a more optimal version | |
417 try | |
418 { | |
15068
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
419 Array<idx_vector> idx; |
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
420 make_indices (indicies, idx_count, idx); |
15067 | 421 |
422 Array<double> ret = mat->array->index (idx); | |
423 return ret.xelem (0); | |
424 } | |
425 catch (const octave_execution_exception&) | |
426 { | |
427 gripe_library_execution_error (); | |
428 return 0; | |
429 } | |
430 } | |
431 | |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
432 extern "C" jit_matrix |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
433 octave_jit_paren_scalar_subsasgn (jit_matrix *mat, double *indices, |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
434 octave_idx_type idx_count, double value) |
15068
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
435 { |
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
436 // FIXME: Replace this with a more optimal version |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
437 jit_matrix ret; |
15068
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
438 try |
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
439 { |
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
440 Array<idx_vector> idx; |
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
441 make_indices (indices, idx_count, idx); |
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
442 |
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
443 Matrix temp (1, 1); |
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
444 temp.xelem(0) = value; |
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
445 mat->array->assign (idx, temp); |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
446 ret.update (mat->array); |
15068
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
447 } |
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
448 catch (const octave_execution_exception&) |
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
449 { |
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
450 gripe_library_execution_error (); |
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
451 } |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
452 |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
453 return ret; |
15068
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
454 } |
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
455 |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
456 extern "C" jit_matrix |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
457 octave_jit_paren_subsasgn_matrix_range (jit_matrix *mat, jit_range *index, |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
458 double value) |
15016 | 459 { |
460 NDArray *array = mat->array; | |
461 bool done = false; | |
462 | |
463 // optimize for the simple case (no resizing and no errors) | |
464 if (*array->jit_ref_count () == 1 | |
465 && index->all_elements_are_ints ()) | |
466 { | |
467 // this code is similar to idx_vector::fill, but we avoid allocating an | |
468 // idx_vector and its associated rep | |
469 octave_idx_type start = static_cast<octave_idx_type> (index->base) - 1; | |
470 octave_idx_type step = static_cast<octave_idx_type> (index->inc); | |
471 octave_idx_type nelem = index->nelem; | |
472 octave_idx_type final = start + nelem * step; | |
473 if (step < 0) | |
474 { | |
475 step = -step; | |
476 std::swap (final, start); | |
477 } | |
478 | |
479 if (start >= 0 && final < mat->slice_len) | |
480 { | |
481 done = true; | |
482 | |
483 double *data = array->jit_slice_data (); | |
484 if (step == 1) | |
485 std::fill (data + start, data + start + nelem, value); | |
486 else | |
487 { | |
488 for (octave_idx_type i = start; i < final; i += step) | |
489 data[i] = value; | |
490 } | |
491 } | |
492 } | |
493 | |
494 if (! done) | |
495 { | |
496 idx_vector idx (*index); | |
497 NDArray avalue (dim_vector (1, 1)); | |
498 avalue.xelem (0) = value; | |
499 array->assign (idx, avalue); | |
500 } | |
501 | |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
502 jit_matrix ret; |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
503 ret.update (array); |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
504 return ret; |
15016 | 505 } |
506 | |
15102
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
507 extern "C" double |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
508 octave_jit_end_matrix (jit_matrix *mat, octave_idx_type idx, |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
509 octave_idx_type count) |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
510 { |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
511 octave_idx_type ndim = mat->dimensions[-1]; |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
512 if (ndim == count) |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
513 return mat->dimensions[idx]; |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
514 else if (ndim > count) |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
515 { |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
516 if (idx == count - 1) |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
517 { |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
518 double ret = mat->dimensions[idx]; |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
519 for (octave_idx_type i = idx + 1; i < ndim; ++i) |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
520 ret *= mat->dimensions[idx]; |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
521 return ret; |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
522 } |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
523 |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
524 return mat->dimensions[idx]; |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
525 } |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
526 else // ndim < count |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
527 return idx < ndim ? mat->dimensions[idx] : 1; |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
528 } |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
529 |
15337
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
530 extern "C" octave_base_value * |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
531 octave_jit_create_undef (void) |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
532 { |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
533 octave_value undef; |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
534 octave_base_value *ret = undef.internal_rep (); |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
535 ret->grab (); |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
536 |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
537 return ret; |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
538 } |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
539 |
15016 | 540 extern "C" Complex |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
541 octave_jit_complex_mul (Complex lhs, Complex rhs) |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
542 { |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
543 if (lhs.imag () == 0 && rhs.imag() == 0) |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
544 return Complex (lhs.real () * rhs.real (), 0); |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
545 |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
546 return lhs * rhs; |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
547 } |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
548 |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
549 extern "C" Complex |
15016 | 550 octave_jit_complex_div (Complex lhs, Complex rhs) |
551 { | |
552 // see src/OPERATORS/op-cs-cs.cc | |
553 if (rhs == 0.0) | |
554 gripe_divide_by_zero (); | |
555 | |
556 return lhs / rhs; | |
557 } | |
558 | |
559 // FIXME: CP form src/xpow.cc | |
560 static inline int | |
561 xisint (double x) | |
562 { | |
563 return (D_NINT (x) == x | |
15215
9020dddc925a
use std::numeric_limits for integer max and min values
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
564 && ((x >= 0 && x < std::numeric_limits<int>::max ()) |
15219
aeba1adfd76b
Correct small typo in jit-typeinfo.cc
Melvin Robinson <melvin.robinson@mavs.uta.edu>
parents:
15215
diff
changeset
|
565 || (x <= 0 && x > std::numeric_limits<int>::min ()))); |
15016 | 566 } |
567 | |
568 extern "C" Complex | |
569 octave_jit_pow_scalar_scalar (double lhs, double rhs) | |
570 { | |
571 // FIXME: almost CP from src/xpow.cc | |
572 if (lhs < 0.0 && ! xisint (rhs)) | |
573 return std::pow (Complex (lhs), rhs); | |
574 return std::pow (lhs, rhs); | |
575 } | |
576 | |
577 extern "C" Complex | |
578 octave_jit_pow_complex_complex (Complex lhs, Complex rhs) | |
579 { | |
580 if (lhs.imag () == 0 && rhs.imag () == 0) | |
581 return octave_jit_pow_scalar_scalar (lhs.real (), rhs.real ()); | |
582 return std::pow (lhs, rhs); | |
583 } | |
584 | |
18554 | 585 // FIXME: should handle FloatComplex |
586 extern "C" Complex | |
587 octave_jit_pow_single_single (float lhs, float rhs) | |
588 { | |
589 // FIXME: almost CP from libinterp/corefcn/xpow.cc | |
590 float retval; | |
591 | |
592 if (lhs < 0.0 && ! xisint (rhs)) | |
593 { | |
594 FloatComplex lhstmp (lhs); | |
595 | |
596 return std::pow (lhstmp, rhs); | |
597 } | |
598 else | |
599 retval = std::pow (lhs, rhs); | |
600 | |
601 return retval; | |
602 } | |
603 | |
15016 | 604 extern "C" Complex |
605 octave_jit_pow_complex_scalar (Complex lhs, double rhs) | |
606 { | |
607 if (lhs.imag () == 0) | |
608 return octave_jit_pow_scalar_scalar (lhs.real (), rhs); | |
609 return std::pow (lhs, rhs); | |
610 } | |
611 | |
612 extern "C" Complex | |
613 octave_jit_pow_scalar_complex (double lhs, Complex rhs) | |
614 { | |
615 if (rhs.imag () == 0) | |
616 return octave_jit_pow_scalar_scalar (lhs, rhs.real ()); | |
617 return std::pow (lhs, rhs); | |
618 } | |
619 | |
18555 | 620 /************************************************************ |
621 * | |
18557 | 622 * int8 related external helper function |
623 * | |
624 ************************************************************/ | |
625 | |
626 extern "C" int8_t | |
627 octave_jit_add_int8_int8 (int8_t lhs, int8_t rhs) | |
628 { | |
629 uint8_t ulhs = lhs; | |
630 uint8_t urhs = rhs; | |
631 uint8_t res = ulhs + urhs; | |
632 | |
633 /* Calculate overflowed result. (Don't change the sign bit of ux) */ | |
634 ulhs = (ulhs >> 7) + SCHAR_MAX; | |
635 | |
636 /* Force compiler to use cmovns instruction */ | |
637 if ((int8_t) ((ulhs ^ urhs) | ~(urhs ^ res)) >= 0) | |
638 { | |
639 res = ulhs; | |
640 } | |
641 | |
642 return res; | |
643 } | |
644 | |
645 extern "C" int8_t | |
646 octave_jit_sub_int8_int8 (int8_t lhs, int8_t rhs) | |
647 { | |
648 uint8_t ulhs = lhs; | |
649 uint8_t urhs = rhs; | |
650 uint8_t res = ulhs - urhs; | |
651 | |
652 ulhs = (ulhs >> 7) + SCHAR_MAX; | |
653 | |
654 /* Force compiler to use cmovns instruction */ | |
655 if ((int8_t)((ulhs ^ urhs) & (ulhs ^ res)) < 0) | |
656 { | |
657 res = ulhs; | |
658 } | |
659 | |
660 return res; | |
661 } | |
662 | |
663 extern "C" int8_t | |
664 octave_jit_mul_int8_int8 (int8_t lhs, int8_t rhs) | |
665 { | |
666 int16_t res = (int16_t) lhs * (int16_t) rhs; | |
667 uint8_t res2 = ((uint8_t) (lhs ^ rhs) >> 7) + SCHAR_MAX; | |
668 | |
669 int8_t hi = (res >> 8); | |
670 int8_t lo = res; | |
671 | |
672 if (hi != (lo >> 7)) res = res2; | |
673 | |
674 return res; | |
675 } | |
676 | |
677 extern "C" int8_t | |
678 octave_jit_incr_int8 (int8_t val) | |
679 { | |
680 return octave_jit_add_int8_int8 (val, 1); | |
681 } | |
682 | |
683 extern "C" int8_t | |
684 octave_jit_decr_int8 (int8_t val) | |
685 { | |
686 return octave_jit_sub_int8_int8 (val, 1); | |
687 } | |
688 | |
689 /************************************************************ | |
690 * | |
18559 | 691 * int16 related external helper function |
692 * | |
693 ************************************************************/ | |
694 | |
695 extern "C" int16_t | |
696 octave_jit_add_int16_int16 (int16_t lhs, int16_t rhs) | |
697 { | |
698 uint16_t ulhs = lhs; | |
699 uint16_t urhs = rhs; | |
700 uint16_t res = ulhs + urhs; | |
701 | |
702 /* Calculate overflowed result. (Don't change the sign bit of ux) */ | |
703 ulhs = (ulhs >> 15) + SHRT_MAX; | |
704 | |
705 /* Force compiler to use cmovns instruction */ | |
706 if ((int16_t) ((ulhs ^ urhs) | ~(urhs ^ res)) >= 0) | |
707 { | |
708 res = ulhs; | |
709 } | |
710 | |
711 return res; | |
712 } | |
713 | |
714 extern "C" int16_t | |
715 octave_jit_sub_int16_int16 (int16_t lhs, int16_t rhs) | |
716 { | |
717 uint16_t ulhs = lhs; | |
718 uint16_t urhs = rhs; | |
719 uint16_t res = ulhs - urhs; | |
720 | |
721 ulhs = (ulhs >> 15) + SHRT_MAX; | |
722 | |
723 /* Force compiler to use cmovns instruction */ | |
724 if ((int16_t)((ulhs ^ urhs) & (ulhs ^ res)) < 0) | |
725 { | |
726 res = ulhs; | |
727 } | |
728 | |
729 return res; | |
730 } | |
731 | |
732 extern "C" int16_t | |
733 octave_jit_mul_int16_int16 (int16_t lhs, int16_t rhs) | |
734 { | |
735 int32_t res = (int32_t) lhs * (int32_t) rhs; | |
736 uint16_t res2 = ((uint16_t) (lhs ^ rhs) >> 15) + SHRT_MAX; | |
737 | |
738 int16_t hi = (res >> 16); | |
739 int16_t lo = res; | |
740 | |
741 if (hi != (lo >> 15)) res = res2; | |
742 | |
743 return res; | |
744 } | |
745 | |
746 extern "C" int16_t | |
747 octave_jit_incr_int16 (int16_t val) | |
748 { | |
749 return octave_jit_add_int16_int16 (val, 1); | |
750 } | |
751 | |
752 extern "C" int16_t | |
753 octave_jit_decr_int16 (int16_t val) | |
754 { | |
755 return octave_jit_sub_int16_int16 (val, 1); | |
756 } | |
757 | |
758 /************************************************************ | |
759 * | |
18560 | 760 * int32 related external helper function |
761 * | |
762 ************************************************************/ | |
763 | |
764 extern "C" int32_t | |
765 octave_jit_add_int32_int32 (int32_t lhs, int32_t rhs) | |
766 { | |
767 uint32_t ulhs = lhs; | |
768 uint32_t urhs = rhs; | |
769 uint32_t res = ulhs + urhs; | |
770 | |
771 /* Calculate overflowed result. (Don't change the sign bit of ux) */ | |
772 ulhs = (ulhs >> 31) + INT_MAX; | |
773 | |
774 /* Force compiler to use cmovns instruction */ | |
775 if ((int32_t) ((ulhs ^ urhs) | ~(urhs ^ res)) >= 0) | |
776 { | |
777 res = ulhs; | |
778 } | |
779 | |
780 return res; | |
781 } | |
782 | |
783 extern "C" int32_t | |
784 octave_jit_sub_int32_int32 (int32_t lhs, int32_t rhs) | |
785 { | |
786 uint32_t ulhs = lhs; | |
787 uint32_t urhs = rhs; | |
788 uint32_t res = ulhs - urhs; | |
789 | |
790 ulhs = (ulhs >> 31) + INT_MAX; | |
791 | |
792 /* Force compiler to use cmovns instruction */ | |
793 if ((int32_t)((ulhs ^ urhs) & (ulhs ^ res)) < 0) | |
794 { | |
795 res = ulhs; | |
796 } | |
797 | |
798 return res; | |
799 } | |
800 | |
801 extern "C" int32_t | |
802 octave_jit_mul_int32_int32 (int32_t lhs, int32_t rhs) | |
803 { | |
804 int64_t res = (int64_t) lhs * (int64_t) rhs; | |
805 uint32_t res2 = ((uint32_t) (lhs ^ rhs) >> 31) + INT_MAX; | |
806 | |
807 int32_t hi = (res >> 32); | |
808 int32_t lo = res; | |
809 | |
810 if (hi != (lo >> 31)) res = res2; | |
811 | |
812 return res; | |
813 } | |
814 | |
815 extern "C" int32_t | |
816 octave_jit_incr_int32 (int32_t val) | |
817 { | |
818 return octave_jit_add_int32_int32 (val, 1); | |
819 } | |
820 | |
821 extern "C" int32_t | |
822 octave_jit_decr_int32 (int32_t val) | |
823 { | |
824 return octave_jit_sub_int32_int32 (val, 1); | |
825 } | |
826 | |
827 /************************************************************ | |
828 * | |
18558
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
829 * int64 related external helper function |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
830 * |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
831 ************************************************************/ |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
832 |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
833 extern "C" int64_t |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
834 octave_jit_add_int64_int64 (int64_t lhs, int64_t rhs) |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
835 { |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
836 uint64_t ulhs = lhs; |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
837 uint64_t urhs = rhs; |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
838 uint64_t res = ulhs + urhs; |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
839 |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
840 /* Calculate overflowed result. (Don't change the sign bit of ux) */ |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
841 ulhs = (ulhs >> 63) + LONG_MAX; |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
842 |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
843 /* Force compiler to use cmovns instruction */ |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
844 if ((int64_t) ((ulhs ^ urhs) | ~(urhs ^ res)) >= 0) |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
845 { |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
846 res = ulhs; |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
847 } |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
848 |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
849 return res; |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
850 } |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
851 |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
852 extern "C" int64_t |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
853 octave_jit_sub_int64_int64 (int64_t lhs, int64_t rhs) |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
854 { |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
855 uint64_t ulhs = lhs; |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
856 uint64_t urhs = rhs; |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
857 uint64_t res = ulhs - urhs; |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
858 |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
859 ulhs = (ulhs >> 63) + LONG_MAX; |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
860 |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
861 /* Force compiler to use cmovns instruction */ |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
862 if ((int64_t)((ulhs ^ urhs) & (ulhs ^ res)) < 0) |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
863 { |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
864 res = ulhs; |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
865 } |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
866 |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
867 return res; |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
868 } |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
869 |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
870 extern "C" int64_t |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
871 octave_jit_mul_int64_int64 (int64_t lhs, int64_t rhs) |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
872 { |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
873 #ifdef OCTAVE_INT_USE_LONG_DOUBLE |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
874 long double p = static_cast<long double> (lhs) * static_cast<long double> (rhs); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
875 if (p > static_cast<long double> (std::numeric_limits<int64_t>::max ())) |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
876 { |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
877 return std::numeric_limits<int64_t>::max (); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
878 } |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
879 else if (p < static_cast<long double> (std::numeric_limits<int64_t>::min ())) |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
880 { |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
881 return std::numeric_limits<int64_t>::min (); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
882 } |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
883 else |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
884 return static_cast<int64_t> (p); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
885 #else |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
886 __int128_t res = (__int128_t) lhs * (__int128_t) rhs; |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
887 uint64_t res2 = ((uint64_t) (lhs ^ rhs) >> 63) + LONG_MAX; |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
888 |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
889 int64_t hi = (res >> 64); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
890 int64_t lo = res; |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
891 |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
892 if (hi != (lo >> 63)) res = res2; |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
893 |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
894 return res; |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
895 #endif |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
896 } |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
897 |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
898 extern "C" int64_t |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
899 octave_jit_incr_int64 (int64_t val) |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
900 { |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
901 return octave_jit_add_int64_int64 (val, 1); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
902 } |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
903 |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
904 extern "C" int64_t |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
905 octave_jit_decr_int64 (int64_t val) |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
906 { |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
907 return octave_jit_sub_int64_int64 (val, 1); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
908 } |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
909 |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
910 /************************************************************ |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
911 * |
18561 | 912 * uint8 related external helper function |
913 * | |
914 ************************************************************/ | |
915 | |
916 extern "C" uint8_t | |
917 octave_jit_add_uint8_uint8 (uint8_t lhs, uint8_t rhs) | |
918 { | |
919 uint8_t res = lhs + rhs; | |
920 res |= -(res < lhs); | |
921 | |
922 return res; | |
923 } | |
924 | |
925 extern "C" uint8_t | |
926 octave_jit_sub_uint8_uint8 (uint8_t lhs, uint8_t rhs) | |
927 { | |
928 uint8_t res = lhs - rhs; | |
929 res &= -(res <= lhs); | |
930 | |
931 return res; | |
932 } | |
933 | |
934 extern "C" uint8_t | |
935 octave_jit_mul_uint8_uint8 (uint8_t lhs, uint8_t rhs) | |
936 { | |
937 uint16_t res = (uint16_t) lhs * (uint16_t) rhs; | |
938 | |
939 uint8_t hi = res >> 8; | |
940 uint8_t lo = res; | |
941 | |
942 return lo | -!!hi; | |
943 } | |
944 | |
945 extern "C" uint8_t | |
946 octave_jit_incr_uint8 (uint8_t val) | |
947 { | |
948 return octave_jit_add_uint8_uint8 (val, 1); | |
949 } | |
950 | |
951 extern "C" uint8_t | |
952 octave_jit_decr_uint8 (uint8_t val) | |
953 { | |
954 return octave_jit_sub_uint8_uint8 (val, 1); | |
955 } | |
956 | |
957 /************************************************************ | |
958 * | |
18555 | 959 * uint16 related external helper function |
960 * | |
961 ************************************************************/ | |
962 | |
963 extern "C" uint16_t | |
964 octave_jit_add_uint16_uint16 (uint16_t lhs, uint16_t rhs) | |
965 { | |
966 uint16_t res = lhs + rhs; | |
967 res |= -(res < lhs); | |
968 | |
969 return res; | |
970 } | |
971 | |
972 extern "C" uint16_t | |
973 octave_jit_sub_uint16_uint16 (uint16_t lhs, uint16_t rhs) | |
974 { | |
975 uint16_t res = lhs - rhs; | |
976 res &= -(res <= lhs); | |
977 | |
978 return res; | |
979 } | |
980 | |
981 extern "C" uint16_t | |
982 octave_jit_mul_uint16_uint16 (uint16_t lhs, uint16_t rhs) | |
983 { | |
984 uint32_t res = (uint32_t) lhs * (uint32_t) rhs; | |
985 | |
986 uint16_t hi = res >> 16; | |
987 uint16_t lo = res; | |
988 | |
989 return lo | -!!hi; | |
990 } | |
991 | |
992 extern "C" uint16_t | |
993 octave_jit_incr_uint16 (uint16_t val) | |
994 { | |
995 return octave_jit_add_uint16_uint16 (val, 1); | |
996 } | |
997 | |
998 extern "C" uint16_t | |
999 octave_jit_decr_uint16 (uint16_t val) | |
1000 { | |
1001 return octave_jit_sub_uint16_uint16 (val, 1); | |
1002 } | |
1003 | |
18562
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
1004 /************************************************************ |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
1005 * |
18563 | 1006 * uint32 related external helper function |
1007 * | |
1008 ************************************************************/ | |
1009 | |
1010 extern "C" uint32_t | |
1011 octave_jit_add_uint32_uint32 (uint32_t lhs, uint32_t rhs) | |
1012 { | |
1013 uint32_t res = lhs + rhs; | |
1014 res |= -(res < lhs); | |
1015 | |
1016 return res; | |
1017 } | |
1018 | |
1019 extern "C" uint32_t | |
1020 octave_jit_sub_uint32_uint32 (uint32_t lhs, uint32_t rhs) | |
1021 { | |
1022 uint32_t res = lhs - rhs; | |
1023 res &= -(res <= lhs); | |
1024 | |
1025 return res; | |
1026 } | |
1027 | |
1028 extern "C" uint32_t | |
1029 octave_jit_mul_uint32_uint32 (uint32_t lhs, uint32_t rhs) | |
1030 { | |
1031 uint64_t res = (uint64_t) lhs * (uint64_t) rhs; | |
1032 | |
1033 uint32_t hi = res >> 32; | |
1034 uint32_t lo = res; | |
1035 | |
1036 return lo | -!!hi; | |
1037 } | |
1038 | |
1039 extern "C" uint32_t | |
1040 octave_jit_incr_uint32 (uint32_t val) | |
1041 { | |
1042 return octave_jit_add_uint32_uint32 (val, 1); | |
1043 } | |
1044 | |
1045 extern "C" uint32_t | |
1046 octave_jit_decr_uint32 (uint32_t val) | |
1047 { | |
1048 return octave_jit_sub_uint32_uint32 (val, 1); | |
1049 } | |
1050 | |
1051 /************************************************************ | |
1052 * | |
18562
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
1053 * uint64 related external helper function |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
1054 * |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
1055 ************************************************************/ |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
1056 |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
1057 extern "C" uint64_t |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
1058 octave_jit_add_uint64_uint64 (uint64_t lhs, uint64_t rhs) |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
1059 { |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
1060 uint64_t res = lhs + rhs; |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
1061 res |= -(res < lhs); |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
1062 |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
1063 return res; |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
1064 } |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
1065 |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
1066 extern "C" uint64_t |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
1067 octave_jit_sub_uint64_uint64 (uint64_t lhs, uint64_t rhs) |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
1068 { |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
1069 uint64_t res = lhs - rhs; |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
1070 res &= -(res <= lhs); |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
1071 |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
1072 return res; |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
1073 } |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
1074 |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
1075 extern "C" uint64_t |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
1076 octave_jit_mul_uint64_uint64 (uint64_t lhs, uint64_t rhs) |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
1077 { |
18565
3f2a95a4b98d
jit compiler: use existing int functions
Stefan Mahr <dac922@gmx.de>
parents:
18564
diff
changeset
|
1078 #if 1 |
3f2a95a4b98d
jit compiler: use existing int functions
Stefan Mahr <dac922@gmx.de>
parents:
18564
diff
changeset
|
1079 return octave_int_arith_base<uint64_t,false>::mul(lhs,rhs); |
3f2a95a4b98d
jit compiler: use existing int functions
Stefan Mahr <dac922@gmx.de>
parents:
18564
diff
changeset
|
1080 #else |
18562
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
1081 #ifdef OCTAVE_INT_USE_LONG_DOUBLE |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
1082 long double p = static_cast<long double> (lhs) * static_cast<long double> (rhs); |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
1083 if (p > static_cast<long double> (std::numeric_limits<uint64_t>::max ())) |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
1084 { |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
1085 return std::numeric_limits<uint64_t>::max (); |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
1086 } |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
1087 else |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
1088 return static_cast<uint64_t> (p); |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
1089 #else |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
1090 __uint128_t res = (__uint128_t) lhs * (__uint128_t) rhs; |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
1091 |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
1092 uint64_t hi = res >> 64; |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
1093 uint64_t lo = res; |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
1094 |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
1095 return lo | -!!hi; |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
1096 #endif |
18565
3f2a95a4b98d
jit compiler: use existing int functions
Stefan Mahr <dac922@gmx.de>
parents:
18564
diff
changeset
|
1097 #endif |
18562
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
1098 } |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
1099 |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
1100 extern "C" uint64_t |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
1101 octave_jit_incr_uint64 (uint64_t val) |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
1102 { |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
1103 return octave_jit_add_uint64_uint64 (val, 1); |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
1104 } |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
1105 |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
1106 extern "C" uint64_t |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
1107 octave_jit_decr_uint64 (uint64_t val) |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
1108 { |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
1109 return octave_jit_sub_uint64_uint64 (val, 1); |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
1110 } |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
1111 |
15016 | 1112 extern "C" void |
1113 octave_jit_print_matrix (jit_matrix *m) | |
1114 { | |
1115 std::cout << *m << std::endl; | |
1116 } | |
1117 | |
1118 static void | |
1119 gripe_bad_result (void) | |
1120 { | |
1121 error ("incorrect type information given to the JIT compiler"); | |
1122 } | |
1123 | |
1124 // FIXME: Add support for multiple outputs | |
1125 extern "C" octave_base_value * | |
1126 octave_jit_call (octave_builtin::fcn fn, size_t nargin, | |
1127 octave_base_value **argin, jit_type *result_type) | |
1128 { | |
1129 octave_value_list ovl (nargin); | |
1130 for (size_t i = 0; i < nargin; ++i) | |
1131 ovl.xelem (i) = octave_value (argin[i]); | |
1132 | |
1133 ovl = fn (ovl, 1); | |
1134 | |
15169
6242904370bd
Support balance, cond, det, norm, rand, magic, eye, and mod in JIT
Max Brister <max@2bass.com>
parents:
15148
diff
changeset
|
1135 // FIXME: Check result_type somehow |
15016 | 1136 if (result_type) |
1137 { | |
15169
6242904370bd
Support balance, cond, det, norm, rand, magic, eye, and mod in JIT
Max Brister <max@2bass.com>
parents:
15148
diff
changeset
|
1138 if (ovl.length () < 1) |
15016 | 1139 { |
1140 gripe_bad_result (); | |
1141 return 0; | |
1142 } | |
1143 | |
15169
6242904370bd
Support balance, cond, det, norm, rand, magic, eye, and mod in JIT
Max Brister <max@2bass.com>
parents:
15148
diff
changeset
|
1144 octave_value result = ovl.xelem(0); |
15016 | 1145 octave_base_value *ret = result.internal_rep (); |
1146 ret->grab (); | |
1147 return ret; | |
1148 } | |
1149 | |
1150 if (! (ovl.length () == 0 | |
1151 || (ovl.length () == 1 && ovl.xelem (0).is_undefined ()))) | |
1152 gripe_bad_result (); | |
1153 | |
1154 return 0; | |
1155 } | |
1156 | |
1157 // -------------------- jit_range -------------------- | |
1158 bool | |
1159 jit_range::all_elements_are_ints () const | |
1160 { | |
1161 Range r (*this); | |
1162 return r.all_elements_are_ints (); | |
1163 } | |
1164 | |
1165 std::ostream& | |
1166 operator<< (std::ostream& os, const jit_range& rng) | |
1167 { | |
1168 return os << "Range[" << rng.base << ", " << rng.limit << ", " << rng.inc | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1169 << ", " << rng.nelem << "]"; |
15016 | 1170 } |
1171 | |
1172 // -------------------- jit_matrix -------------------- | |
1173 | |
1174 std::ostream& | |
1175 operator<< (std::ostream& os, const jit_matrix& mat) | |
1176 { | |
1177 return os << "Matrix[" << mat.ref_count << ", " << mat.slice_data << ", " | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1178 << mat.slice_len << ", " << mat.dimensions << ", " |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1179 << mat.array << "]"; |
15016 | 1180 } |
1181 | |
1182 // -------------------- jit_type -------------------- | |
1183 jit_type::jit_type (const std::string& aname, jit_type *aparent, | |
15124
0464e3ceb85b
Skip functions when resolving end context in JIT
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
1184 llvm::Type *allvm_type, bool askip_paren, int aid) : |
15016 | 1185 mname (aname), mparent (aparent), llvm_type (allvm_type), mid (aid), |
15124
0464e3ceb85b
Skip functions when resolving end context in JIT
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
1186 mdepth (aparent ? aparent->mdepth + 1 : 0), mskip_paren (askip_paren) |
15016 | 1187 { |
1188 std::memset (msret, 0, sizeof (msret)); | |
1189 std::memset (mpointer_arg, 0, sizeof (mpointer_arg)); | |
1190 std::memset (mpack, 0, sizeof (mpack)); | |
1191 std::memset (munpack, 0, sizeof (munpack)); | |
1192 | |
1193 for (size_t i = 0; i < jit_convention::length; ++i) | |
1194 mpacked_type[i] = llvm_type; | |
1195 } | |
1196 | |
1197 llvm::Type * | |
1198 jit_type::to_llvm_arg (void) const | |
1199 { | |
1200 return llvm_type ? llvm_type->getPointerTo () : 0; | |
1201 } | |
1202 | |
1203 // -------------------- jit_function -------------------- | |
1204 jit_function::jit_function () : module (0), llvm_function (0), mresult (0), | |
1205 call_conv (jit_convention::length), | |
1206 mcan_error (false) | |
1207 {} | |
1208 | |
1209 jit_function::jit_function (llvm::Module *amodule, | |
1210 jit_convention::type acall_conv, | |
1211 const llvm::Twine& aname, jit_type *aresult, | |
1212 const std::vector<jit_type *>& aargs) | |
1213 : module (amodule), mresult (aresult), args (aargs), call_conv (acall_conv), | |
1214 mcan_error (false) | |
1215 { | |
1216 llvm::SmallVector<llvm::Type *, 15> llvm_args; | |
1217 | |
1218 llvm::Type *rtype = llvm::Type::getVoidTy (context); | |
1219 if (mresult) | |
1220 { | |
1221 rtype = mresult->packed_type (call_conv); | |
1222 if (sret ()) | |
1223 { | |
1224 llvm_args.push_back (rtype->getPointerTo ()); | |
1225 rtype = llvm::Type::getVoidTy (context); | |
1226 } | |
1227 } | |
1228 | |
1229 for (std::vector<jit_type *>::const_iterator iter = args.begin (); | |
1230 iter != args.end (); ++iter) | |
1231 { | |
1232 jit_type *ty = *iter; | |
1233 assert (ty); | |
1234 llvm::Type *argty = ty->packed_type (call_conv); | |
1235 if (ty->pointer_arg (call_conv)) | |
1236 argty = argty->getPointerTo (); | |
1237 | |
1238 llvm_args.push_back (argty); | |
1239 } | |
1240 | |
1241 // we mark all functinos as external linkage because this prevents llvm | |
1242 // from getting rid of always inline functions | |
1243 llvm::FunctionType *ft = llvm::FunctionType::get (rtype, llvm_args, false); | |
1244 llvm_function = llvm::Function::Create (ft, llvm::Function::ExternalLinkage, | |
1245 aname, module); | |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1246 |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1247 if (sret ()) |
17031
38bcfd413db0
Handle LLVM API incoherence. Octave now works with LLVM 3.0, 3.1, and 3.2
LYH <lyh.kernel@gmail.com>
parents:
16892
diff
changeset
|
1248 { |
38bcfd413db0
Handle LLVM API incoherence. Octave now works with LLVM 3.0, 3.1, and 3.2
LYH <lyh.kernel@gmail.com>
parents:
16892
diff
changeset
|
1249 #ifdef FUNCTION_ADDATTRIBUTE_ARG_IS_ATTRIBUTES |
38bcfd413db0
Handle LLVM API incoherence. Octave now works with LLVM 3.0, 3.1, and 3.2
LYH <lyh.kernel@gmail.com>
parents:
16892
diff
changeset
|
1250 llvm::AttrBuilder attr_builder; |
38bcfd413db0
Handle LLVM API incoherence. Octave now works with LLVM 3.0, 3.1, and 3.2
LYH <lyh.kernel@gmail.com>
parents:
16892
diff
changeset
|
1251 attr_builder.addAttribute (llvm::Attributes::StructRet); |
38bcfd413db0
Handle LLVM API incoherence. Octave now works with LLVM 3.0, 3.1, and 3.2
LYH <lyh.kernel@gmail.com>
parents:
16892
diff
changeset
|
1252 llvm::Attributes attrs = llvm::Attributes::get(context, attr_builder); |
38bcfd413db0
Handle LLVM API incoherence. Octave now works with LLVM 3.0, 3.1, and 3.2
LYH <lyh.kernel@gmail.com>
parents:
16892
diff
changeset
|
1253 llvm_function->addAttribute (1, attrs); |
38bcfd413db0
Handle LLVM API incoherence. Octave now works with LLVM 3.0, 3.1, and 3.2
LYH <lyh.kernel@gmail.com>
parents:
16892
diff
changeset
|
1254 #else |
38bcfd413db0
Handle LLVM API incoherence. Octave now works with LLVM 3.0, 3.1, and 3.2
LYH <lyh.kernel@gmail.com>
parents:
16892
diff
changeset
|
1255 llvm_function->addAttribute (1, llvm::Attribute::StructRet); |
38bcfd413db0
Handle LLVM API incoherence. Octave now works with LLVM 3.0, 3.1, and 3.2
LYH <lyh.kernel@gmail.com>
parents:
16892
diff
changeset
|
1256 #endif |
38bcfd413db0
Handle LLVM API incoherence. Octave now works with LLVM 3.0, 3.1, and 3.2
LYH <lyh.kernel@gmail.com>
parents:
16892
diff
changeset
|
1257 } |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1258 |
15016 | 1259 if (call_conv == jit_convention::internal) |
17031
38bcfd413db0
Handle LLVM API incoherence. Octave now works with LLVM 3.0, 3.1, and 3.2
LYH <lyh.kernel@gmail.com>
parents:
16892
diff
changeset
|
1260 #ifdef FUNCTION_ADDFNATTR_ARG_IS_ATTRIBUTES |
38bcfd413db0
Handle LLVM API incoherence. Octave now works with LLVM 3.0, 3.1, and 3.2
LYH <lyh.kernel@gmail.com>
parents:
16892
diff
changeset
|
1261 llvm_function->addFnAttr (llvm::Attributes::AlwaysInline); |
38bcfd413db0
Handle LLVM API incoherence. Octave now works with LLVM 3.0, 3.1, and 3.2
LYH <lyh.kernel@gmail.com>
parents:
16892
diff
changeset
|
1262 #else |
15016 | 1263 llvm_function->addFnAttr (llvm::Attribute::AlwaysInline); |
17031
38bcfd413db0
Handle LLVM API incoherence. Octave now works with LLVM 3.0, 3.1, and 3.2
LYH <lyh.kernel@gmail.com>
parents:
16892
diff
changeset
|
1264 #endif |
15016 | 1265 } |
1266 | |
1267 jit_function::jit_function (const jit_function& fn, jit_type *aresult, | |
1268 const std::vector<jit_type *>& aargs) | |
1269 : module (fn.module), llvm_function (fn.llvm_function), mresult (aresult), | |
1270 args (aargs), call_conv (fn.call_conv), mcan_error (fn.mcan_error) | |
1271 { | |
1272 } | |
1273 | |
1274 jit_function::jit_function (const jit_function& fn) | |
1275 : module (fn.module), llvm_function (fn.llvm_function), mresult (fn.mresult), | |
1276 args (fn.args), call_conv (fn.call_conv), mcan_error (fn.mcan_error) | |
1277 {} | |
1278 | |
15385
8ccb187b24e9
Erase partially created functions on JIT compilation failure (bug #37308)
Max Brister <max@2bass.com>
parents:
15370
diff
changeset
|
1279 void |
8ccb187b24e9
Erase partially created functions on JIT compilation failure (bug #37308)
Max Brister <max@2bass.com>
parents:
15370
diff
changeset
|
1280 jit_function::erase (void) |
8ccb187b24e9
Erase partially created functions on JIT compilation failure (bug #37308)
Max Brister <max@2bass.com>
parents:
15370
diff
changeset
|
1281 { |
8ccb187b24e9
Erase partially created functions on JIT compilation failure (bug #37308)
Max Brister <max@2bass.com>
parents:
15370
diff
changeset
|
1282 if (! llvm_function) |
8ccb187b24e9
Erase partially created functions on JIT compilation failure (bug #37308)
Max Brister <max@2bass.com>
parents:
15370
diff
changeset
|
1283 return; |
8ccb187b24e9
Erase partially created functions on JIT compilation failure (bug #37308)
Max Brister <max@2bass.com>
parents:
15370
diff
changeset
|
1284 |
8ccb187b24e9
Erase partially created functions on JIT compilation failure (bug #37308)
Max Brister <max@2bass.com>
parents:
15370
diff
changeset
|
1285 llvm_function->eraseFromParent (); |
8ccb187b24e9
Erase partially created functions on JIT compilation failure (bug #37308)
Max Brister <max@2bass.com>
parents:
15370
diff
changeset
|
1286 llvm_function = 0; |
8ccb187b24e9
Erase partially created functions on JIT compilation failure (bug #37308)
Max Brister <max@2bass.com>
parents:
15370
diff
changeset
|
1287 } |
8ccb187b24e9
Erase partially created functions on JIT compilation failure (bug #37308)
Max Brister <max@2bass.com>
parents:
15370
diff
changeset
|
1288 |
15016 | 1289 std::string |
1290 jit_function::name (void) const | |
1291 { | |
1292 return llvm_function->getName (); | |
1293 } | |
1294 | |
1295 llvm::BasicBlock * | |
1296 jit_function::new_block (const std::string& aname, | |
1297 llvm::BasicBlock *insert_before) | |
1298 { | |
1299 return llvm::BasicBlock::Create (context, aname, llvm_function, | |
1300 insert_before); | |
1301 } | |
1302 | |
1303 llvm::Value * | |
1304 jit_function::call (llvm::IRBuilderD& builder, | |
1305 const std::vector<jit_value *>& in_args) const | |
1306 { | |
18556
4d285a169b29
add comment for function support
LYH <lyh.kernel@gmail.com>
parents:
18555
diff
changeset
|
1307 // FIXME: Unhandled case: |
4d285a169b29
add comment for function support
LYH <lyh.kernel@gmail.com>
parents:
18555
diff
changeset
|
1308 // function ret = lt(x, y) |
4d285a169b29
add comment for function support
LYH <lyh.kernel@gmail.com>
parents:
18555
diff
changeset
|
1309 // ret = x < y; |
4d285a169b29
add comment for function support
LYH <lyh.kernel@gmail.com>
parents:
18555
diff
changeset
|
1310 // endfunction |
15056
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15027
diff
changeset
|
1311 if (! valid ()) |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15027
diff
changeset
|
1312 throw jit_fail_exception ("Call not implemented"); |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15027
diff
changeset
|
1313 |
15016 | 1314 assert (in_args.size () == args.size ()); |
1315 std::vector<llvm::Value *> llvm_args (args.size ()); | |
1316 for (size_t i = 0; i < in_args.size (); ++i) | |
1317 llvm_args[i] = in_args[i]->to_llvm (); | |
1318 | |
1319 return call (builder, llvm_args); | |
1320 } | |
1321 | |
1322 llvm::Value * | |
1323 jit_function::call (llvm::IRBuilderD& builder, | |
1324 const std::vector<llvm::Value *>& in_args) const | |
1325 { | |
15056
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15027
diff
changeset
|
1326 if (! valid ()) |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15027
diff
changeset
|
1327 throw jit_fail_exception ("Call not implemented"); |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15027
diff
changeset
|
1328 |
15016 | 1329 assert (in_args.size () == args.size ()); |
1330 llvm::SmallVector<llvm::Value *, 10> llvm_args; | |
1331 llvm_args.reserve (in_args.size () + sret ()); | |
1332 | |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1333 llvm::BasicBlock *insert_block = builder.GetInsertBlock (); |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1334 llvm::Function *parent = insert_block->getParent (); |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1335 assert (parent); |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1336 |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1337 // we insert allocas inside the prelude block to prevent stack overflows |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1338 llvm::BasicBlock& prelude = parent->getEntryBlock (); |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1339 llvm::IRBuilder<> pre_builder (&prelude, prelude.begin ()); |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1340 |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1341 llvm::AllocaInst *sret_mem = 0; |
15016 | 1342 if (sret ()) |
1343 { | |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1344 sret_mem = pre_builder.CreateAlloca (mresult->packed_type (call_conv)); |
15016 | 1345 llvm_args.push_back (sret_mem); |
1346 } | |
1347 | |
1348 for (size_t i = 0; i < in_args.size (); ++i) | |
1349 { | |
1350 llvm::Value *arg = in_args[i]; | |
1351 jit_type::convert_fn convert = args[i]->pack (call_conv); | |
1352 if (convert) | |
1353 arg = convert (builder, arg); | |
1354 | |
1355 if (args[i]->pointer_arg (call_conv)) | |
1356 { | |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1357 llvm::Type *ty = args[i]->packed_type (call_conv); |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1358 llvm::Value *alloca = pre_builder.CreateAlloca (ty); |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1359 builder.CreateStore (arg, alloca); |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1360 arg = alloca; |
15016 | 1361 } |
1362 | |
1363 llvm_args.push_back (arg); | |
1364 } | |
1365 | |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1366 llvm::CallInst *callinst = builder.CreateCall (llvm_function, llvm_args); |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1367 llvm::Value *ret = callinst; |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1368 |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1369 if (sret ()) |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1370 { |
17031
38bcfd413db0
Handle LLVM API incoherence. Octave now works with LLVM 3.0, 3.1, and 3.2
LYH <lyh.kernel@gmail.com>
parents:
16892
diff
changeset
|
1371 #ifdef CALLINST_ADDATTRIBUTE_ARG_IS_ATTRIBUTES |
38bcfd413db0
Handle LLVM API incoherence. Octave now works with LLVM 3.0, 3.1, and 3.2
LYH <lyh.kernel@gmail.com>
parents:
16892
diff
changeset
|
1372 llvm::AttrBuilder attr_builder; |
38bcfd413db0
Handle LLVM API incoherence. Octave now works with LLVM 3.0, 3.1, and 3.2
LYH <lyh.kernel@gmail.com>
parents:
16892
diff
changeset
|
1373 attr_builder.addAttribute(llvm::Attributes::StructRet); |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1374 llvm::Attributes attrs = llvm::Attributes::get(context, attr_builder); |
17031
38bcfd413db0
Handle LLVM API incoherence. Octave now works with LLVM 3.0, 3.1, and 3.2
LYH <lyh.kernel@gmail.com>
parents:
16892
diff
changeset
|
1375 callinst->addAttribute (1, attrs); |
38bcfd413db0
Handle LLVM API incoherence. Octave now works with LLVM 3.0, 3.1, and 3.2
LYH <lyh.kernel@gmail.com>
parents:
16892
diff
changeset
|
1376 #else |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1377 callinst->addAttribute (1, llvm::Attribute::StructRet); |
17031
38bcfd413db0
Handle LLVM API incoherence. Octave now works with LLVM 3.0, 3.1, and 3.2
LYH <lyh.kernel@gmail.com>
parents:
16892
diff
changeset
|
1378 #endif |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1379 ret = builder.CreateLoad (sret_mem); |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1380 } |
15016 | 1381 |
1382 if (mresult) | |
1383 { | |
1384 jit_type::convert_fn unpack = mresult->unpack (call_conv); | |
1385 if (unpack) | |
1386 ret = unpack (builder, ret); | |
1387 } | |
1388 | |
1389 return ret; | |
1390 } | |
1391 | |
1392 llvm::Value * | |
1393 jit_function::argument (llvm::IRBuilderD& builder, size_t idx) const | |
1394 { | |
1395 assert (idx < args.size ()); | |
1396 | |
1397 // FIXME: We should be treating arguments like a list, not a vector. Shouldn't | |
1398 // matter much for now, as the number of arguments shouldn't be much bigger | |
1399 // than 4 | |
1400 llvm::Function::arg_iterator iter = llvm_function->arg_begin (); | |
1401 if (sret ()) | |
1402 ++iter; | |
1403 | |
1404 for (size_t i = 0; i < idx; ++i, ++iter); | |
1405 | |
1406 if (args[idx]->pointer_arg (call_conv)) | |
1407 return builder.CreateLoad (iter); | |
1408 | |
1409 return iter; | |
1410 } | |
1411 | |
1412 void | |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1413 jit_function::do_return (llvm::IRBuilderD& builder, llvm::Value *rval, |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1414 bool verify) |
15016 | 1415 { |
1416 assert (! rval == ! mresult); | |
1417 | |
1418 if (rval) | |
1419 { | |
1420 jit_type::convert_fn convert = mresult->pack (call_conv); | |
1421 if (convert) | |
1422 rval = convert (builder, rval); | |
1423 | |
1424 if (sret ()) | |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1425 { |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1426 builder.CreateStore (rval, llvm_function->arg_begin ()); |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1427 builder.CreateRetVoid (); |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1428 } |
15016 | 1429 else |
1430 builder.CreateRet (rval); | |
1431 } | |
1432 else | |
1433 builder.CreateRetVoid (); | |
1434 | |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1435 if (verify) |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1436 llvm::verifyFunction (*llvm_function); |
15016 | 1437 } |
1438 | |
15019
ae3670d4df29
Update the execution engine's global mapping for external functions
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
1439 void |
ae3670d4df29
Update the execution engine's global mapping for external functions
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
1440 jit_function::do_add_mapping (llvm::ExecutionEngine *engine, void *fn) |
ae3670d4df29
Update the execution engine's global mapping for external functions
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
1441 { |
ae3670d4df29
Update the execution engine's global mapping for external functions
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
1442 assert (valid ()); |
ae3670d4df29
Update the execution engine's global mapping for external functions
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
1443 engine->addGlobalMapping (llvm_function, fn); |
ae3670d4df29
Update the execution engine's global mapping for external functions
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
1444 } |
ae3670d4df29
Update the execution engine's global mapping for external functions
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
1445 |
15016 | 1446 std::ostream& |
1447 operator<< (std::ostream& os, const jit_function& fn) | |
1448 { | |
1449 llvm::Function *lfn = fn.to_llvm (); | |
1450 os << "jit_function: cc=" << fn.call_conv; | |
1451 llvm::raw_os_ostream llvm_out (os); | |
1452 lfn->print (llvm_out); | |
1453 llvm_out.flush (); | |
1454 return os; | |
1455 } | |
1456 | |
1457 // -------------------- jit_operation -------------------- | |
15078
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1458 jit_operation::~jit_operation (void) |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1459 { |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1460 for (generated_map::iterator iter = generated.begin (); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1461 iter != generated.end (); ++iter) |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1462 { |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1463 delete iter->first; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1464 delete iter->second; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1465 } |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1466 } |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1467 |
15016 | 1468 void |
1469 jit_operation::add_overload (const jit_function& func, | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1470 const std::vector<jit_type*>& args) |
15016 | 1471 { |
1472 if (args.size () >= overloads.size ()) | |
1473 overloads.resize (args.size () + 1); | |
1474 | |
1475 Array<jit_function>& over = overloads[args.size ()]; | |
1476 dim_vector dv (over.dims ()); | |
1477 Array<octave_idx_type> idx = to_idx (args); | |
1478 bool must_resize = false; | |
1479 | |
1480 if (dv.length () != idx.numel ()) | |
1481 { | |
1482 dv.resize (idx.numel ()); | |
1483 must_resize = true; | |
1484 } | |
1485 | |
1486 for (octave_idx_type i = 0; i < dv.length (); ++i) | |
1487 if (dv(i) <= idx(i)) | |
1488 { | |
1489 must_resize = true; | |
1490 dv(i) = idx(i) + 1; | |
1491 } | |
1492 | |
1493 if (must_resize) | |
1494 over.resize (dv); | |
1495 | |
1496 over(idx) = func; | |
1497 } | |
1498 | |
1499 const jit_function& | |
1500 jit_operation::overload (const std::vector<jit_type*>& types) const | |
1501 { | |
1502 static jit_function null_overload; | |
1503 for (size_t i =0; i < types.size (); ++i) | |
1504 if (! types[i]) | |
1505 return null_overload; | |
1506 | |
15078
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1507 if (types.size () >= overloads.size ()) |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1508 return do_generate (types); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1509 |
15016 | 1510 const Array<jit_function>& over = overloads[types.size ()]; |
1511 dim_vector dv (over.dims ()); | |
1512 Array<octave_idx_type> idx = to_idx (types); | |
1513 for (octave_idx_type i = 0; i < dv.length (); ++i) | |
1514 if (idx(i) >= dv(i)) | |
15078
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1515 return do_generate (types); |
15016 | 1516 |
15078
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1517 const jit_function& ret = over(idx); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1518 if (! ret.valid ()) |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1519 return do_generate (types); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1520 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1521 return ret; |
15016 | 1522 } |
1523 | |
1524 Array<octave_idx_type> | |
1525 jit_operation::to_idx (const std::vector<jit_type*>& types) const | |
1526 { | |
1527 octave_idx_type numel = types.size (); | |
18277
cc1c19863ae3
jit-typeinfo.cc: Fix C++ function ambiguity (bug #41145).
Lasse Schuirmann <lasse@schuirmann.net>
parents:
18274
diff
changeset
|
1528 numel = std::max (numel, static_cast<octave_idx_type>(2)); |
15016 | 1529 |
1530 Array<octave_idx_type> idx (dim_vector (1, numel)); | |
1531 for (octave_idx_type i = 0; i < static_cast<octave_idx_type> (types.size ()); | |
1532 ++i) | |
1533 idx(i) = types[i]->type_id (); | |
1534 | |
15337
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
1535 if (types.size () == 0) |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
1536 idx(0) = idx(1) = 0; |
15016 | 1537 if (types.size () == 1) |
1538 { | |
1539 idx(1) = idx(0); | |
1540 idx(0) = 0; | |
1541 } | |
1542 | |
1543 return idx; | |
1544 } | |
1545 | |
15078
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1546 const jit_function& |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1547 jit_operation::do_generate (const signature_vec& types) const |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1548 { |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1549 static jit_function null_overload; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1550 generated_map::const_iterator find = generated.find (&types); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1551 if (find != generated.end ()) |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1552 { |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1553 if (find->second) |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1554 return *find->second; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1555 else |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1556 return null_overload; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1557 } |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1558 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1559 jit_function *ret = generate (types); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1560 generated[new signature_vec (types)] = ret; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1561 return ret ? *ret : null_overload; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1562 } |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1563 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1564 jit_function * |
15135
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
1565 jit_operation::generate (const signature_vec&) const |
15078
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1566 { |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1567 return 0; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1568 } |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1569 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1570 bool |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1571 jit_operation::signature_cmp |
18222
4d90e104bf35
Allow jit-typeinfo.h to compile with clang on OS X (bug #41114)
Michael C. Grant <mcg@cvxr.com>
parents:
17787
diff
changeset
|
1572 ::operator() (const signature_vec *lhs, const signature_vec *rhs) const |
15078
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1573 { |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1574 const signature_vec& l = *lhs; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1575 const signature_vec& r = *rhs; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1576 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1577 if (l.size () < r.size ()) |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1578 return true; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1579 else if (l.size () > r.size ()) |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1580 return false; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1581 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1582 for (size_t i = 0; i < l.size (); ++i) |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1583 { |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1584 if (l[i]->type_id () < r[i]->type_id ()) |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1585 return true; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1586 else if (l[i]->type_id () > r[i]->type_id ()) |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1587 return false; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1588 } |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1589 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1590 return false; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1591 } |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1592 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1593 // -------------------- jit_index_operation -------------------- |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1594 jit_function * |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1595 jit_index_operation::generate (const signature_vec& types) const |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1596 { |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1597 if (types.size () > 2 && types[0] == jit_typeinfo::get_matrix ()) |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1598 { |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1599 // indexing a matrix with scalars |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1600 jit_type *scalar = jit_typeinfo::get_scalar (); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1601 for (size_t i = 1; i < types.size (); ++i) |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1602 if (types[i] != scalar) |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1603 return 0; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1604 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1605 return generate_matrix (types); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1606 } |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1607 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1608 return 0; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1609 } |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1610 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1611 llvm::Value * |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1612 jit_index_operation::create_arg_array (llvm::IRBuilderD& builder, |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1613 const jit_function &fn, size_t start_idx, |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1614 size_t end_idx) const |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1615 { |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1616 size_t n = end_idx - start_idx; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1617 llvm::Type *scalar_t = jit_typeinfo::get_scalar_llvm (); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1618 llvm::ArrayType *array_t = llvm::ArrayType::get (scalar_t, n); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1619 llvm::Value *array = llvm::UndefValue::get (array_t); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1620 for (size_t i = start_idx; i < end_idx; ++i) |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1621 { |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1622 llvm::Value *idx = fn.argument (builder, i); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1623 array = builder.CreateInsertValue (array, idx, i - start_idx); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1624 } |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1625 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1626 llvm::Value *array_mem = builder.CreateAlloca (array_t); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1627 builder.CreateStore (array, array_mem); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1628 return builder.CreateBitCast (array_mem, scalar_t->getPointerTo ()); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1629 } |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1630 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1631 // -------------------- jit_paren_subsref -------------------- |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1632 jit_function * |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1633 jit_paren_subsref::generate_matrix (const signature_vec& types) const |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1634 { |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1635 std::stringstream ss; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1636 ss << "jit_paren_subsref_matrix_scalar" << (types.size () - 1); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1637 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1638 jit_type *scalar = jit_typeinfo::get_scalar (); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1639 jit_function *fn = new jit_function (module, jit_convention::internal, |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1640 ss.str (), scalar, types); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1641 fn->mark_can_error (); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1642 llvm::BasicBlock *body = fn->new_block (); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1643 llvm::IRBuilder<> builder (body); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1644 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1645 llvm::Value *array = create_arg_array (builder, *fn, 1, types.size ()); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1646 jit_type *index = jit_typeinfo::get_index (); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1647 llvm::Value *nelem = llvm::ConstantInt::get (index->to_llvm (), |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1648 types.size () - 1); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1649 llvm::Value *mat = fn->argument (builder, 0); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1650 llvm::Value *ret = paren_scalar.call (builder, mat, array, nelem); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1651 fn->do_return (builder, ret); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1652 return fn; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1653 } |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1654 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1655 void |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1656 jit_paren_subsref::do_initialize (void) |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1657 { |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1658 std::vector<jit_type *> types (3); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1659 types[0] = jit_typeinfo::get_matrix (); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1660 types[1] = jit_typeinfo::get_scalar_ptr (); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1661 types[2] = jit_typeinfo::get_index (); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1662 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1663 jit_type *scalar = jit_typeinfo::get_scalar (); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1664 paren_scalar = jit_function (module, jit_convention::external, |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1665 "octave_jit_paren_scalar", scalar, types); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1666 paren_scalar.add_mapping (engine, &octave_jit_paren_scalar); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1667 paren_scalar.mark_can_error (); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1668 } |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1669 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1670 // -------------------- jit_paren_subsasgn -------------------- |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1671 jit_function * |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1672 jit_paren_subsasgn::generate_matrix (const signature_vec& types) const |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1673 { |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1674 std::stringstream ss; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1675 ss << "jit_paren_subsasgn_matrix_scalar" << (types.size () - 2); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1676 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1677 jit_type *matrix = jit_typeinfo::get_matrix (); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1678 jit_function *fn = new jit_function (module, jit_convention::internal, |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1679 ss.str (), matrix, types); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1680 fn->mark_can_error (); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1681 llvm::BasicBlock *body = fn->new_block (); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1682 llvm::IRBuilder<> builder (body); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1683 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1684 llvm::Value *array = create_arg_array (builder, *fn, 1, types.size () - 1); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1685 jit_type *index = jit_typeinfo::get_index (); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1686 llvm::Value *nelem = llvm::ConstantInt::get (index->to_llvm (), |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1687 types.size () - 2); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1688 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1689 llvm::Value *mat = fn->argument (builder, 0); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1690 llvm::Value *value = fn->argument (builder, types.size () - 1); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1691 llvm::Value *ret = paren_scalar.call (builder, mat, array, nelem, value); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1692 fn->do_return (builder, ret); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1693 return fn; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1694 } |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1695 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1696 void |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1697 jit_paren_subsasgn::do_initialize (void) |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1698 { |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1699 if (paren_scalar.valid ()) |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1700 return; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1701 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1702 jit_type *matrix = jit_typeinfo::get_matrix (); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1703 std::vector<jit_type *> types (4); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1704 types[0] = matrix; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1705 types[1] = jit_typeinfo::get_scalar_ptr (); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1706 types[2] = jit_typeinfo::get_index (); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1707 types[3] = jit_typeinfo::get_scalar (); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1708 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1709 paren_scalar = jit_function (module, jit_convention::external, |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1710 "octave_jit_paren_scalar", matrix, types); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1711 paren_scalar.add_mapping (engine, &octave_jit_paren_scalar_subsasgn); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1712 paren_scalar.mark_can_error (); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1713 } |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1714 |
15016 | 1715 // -------------------- jit_typeinfo -------------------- |
1716 void | |
1717 jit_typeinfo::initialize (llvm::Module *m, llvm::ExecutionEngine *e) | |
1718 { | |
1719 new jit_typeinfo (m, e); | |
1720 } | |
1721 | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1722 // wrap function names to simplify jit_typeinfo::create_external |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1723 #define JIT_FN(fn) engine, &fn, #fn |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1724 |
15016 | 1725 jit_typeinfo::jit_typeinfo (llvm::Module *m, llvm::ExecutionEngine *e) |
1726 : module (m), engine (e), next_id (0), | |
1727 builder (*new llvm::IRBuilderD (context)) | |
1728 { | |
1729 instance = this; | |
1730 | |
1731 // FIXME: We should be registering types like in octave_value_typeinfo | |
1732 llvm::Type *any_t = llvm::StructType::create (context, "octave_base_value"); | |
1733 any_t = any_t->getPointerTo (); | |
1734 | |
1735 llvm::Type *scalar_t = llvm::Type::getDoubleTy (context); | |
18554 | 1736 llvm::Type *single_t = llvm::Type::getFloatTy (context); |
18557 | 1737 llvm::Type *int8__t = llvm::Type::getIntNTy (context, 8); |
18559 | 1738 llvm::Type *int16__t = llvm::Type::getIntNTy (context, 16); |
18560 | 1739 llvm::Type *int32__t = llvm::Type::getIntNTy (context, 32); |
18558
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
1740 llvm::Type *int64__t = llvm::Type::getIntNTy (context, 64); |
18561 | 1741 llvm::Type *uint8__t = llvm::Type::getIntNTy (context, 8); |
18555 | 1742 llvm::Type *uint16__t = llvm::Type::getIntNTy (context, 16); |
18563 | 1743 llvm::Type *uint32__t = llvm::Type::getIntNTy (context, 32); |
18562
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
1744 llvm::Type *uint64__t = llvm::Type::getIntNTy (context, 64); |
15016 | 1745 llvm::Type *bool_t = llvm::Type::getInt1Ty (context); |
1746 llvm::Type *string_t = llvm::Type::getInt8Ty (context); | |
1747 string_t = string_t->getPointerTo (); | |
1748 llvm::Type *index_t = llvm::Type::getIntNTy (context, | |
1749 sizeof(octave_idx_type) * 8); | |
1750 | |
1751 llvm::StructType *range_t = llvm::StructType::create (context, "range"); | |
1752 std::vector<llvm::Type *> range_contents (4, scalar_t); | |
1753 range_contents[3] = index_t; | |
1754 range_t->setBody (range_contents); | |
1755 | |
1756 llvm::Type *refcount_t = llvm::Type::getIntNTy (context, sizeof(int) * 8); | |
1757 | |
1758 llvm::StructType *matrix_t = llvm::StructType::create (context, "matrix"); | |
1759 llvm::Type *matrix_contents[5]; | |
1760 matrix_contents[0] = refcount_t->getPointerTo (); | |
1761 matrix_contents[1] = scalar_t->getPointerTo (); | |
1762 matrix_contents[2] = index_t; | |
1763 matrix_contents[3] = index_t->getPointerTo (); | |
1764 matrix_contents[4] = string_t; | |
1765 matrix_t->setBody (llvm::makeArrayRef (matrix_contents, 5)); | |
1766 | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1767 llvm::Type *complex_t = llvm::ArrayType::get (scalar_t, 2); |
15016 | 1768 |
1769 // complex_ret is what is passed to C functions in order to get calling | |
1770 // convention right | |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1771 llvm::Type *cmplx_inner_cont[] = {scalar_t, scalar_t}; |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1772 llvm::StructType *cmplx_inner = llvm::StructType::create (cmplx_inner_cont); |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1773 |
15016 | 1774 complex_ret = llvm::StructType::create (context, "complex_ret"); |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1775 { |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1776 llvm::Type *contents[] = {cmplx_inner}; |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1777 complex_ret->setBody (contents); |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1778 } |
15016 | 1779 |
1780 // create types | |
1781 any = new_type ("any", 0, any_t); | |
1782 matrix = new_type ("matrix", any, matrix_t); | |
1783 complex = new_type ("complex", any, complex_t); | |
1784 scalar = new_type ("scalar", complex, scalar_t); | |
18554 | 1785 single = new_type ("single", any, single_t); |
15078
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1786 scalar_ptr = new_type ("scalar_ptr", 0, scalar_t->getPointerTo ()); |
15135
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
1787 any_ptr = new_type ("any_ptr", 0, any_t->getPointerTo ()); |
15016 | 1788 range = new_type ("range", any, range_t); |
1789 string = new_type ("string", any, string_t); | |
1790 boolean = new_type ("bool", any, bool_t); | |
1791 index = new_type ("index", any, index_t); | |
1792 | |
1793 create_int (8); | |
1794 create_int (16); | |
1795 create_int (32); | |
1796 create_int (64); | |
1797 | |
18561 | 1798 create_uint (8); |
18555 | 1799 create_uint (16); |
18563 | 1800 create_uint (32); |
18562
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
1801 create_uint (64); |
18555 | 1802 |
15016 | 1803 casts.resize (next_id + 1); |
1804 identities.resize (next_id + 1); | |
1805 | |
1806 // specify calling conventions | |
1807 // FIXME: We should detect architecture and do something sane based on that | |
1808 // here we assume x86 or x86_64 | |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1809 matrix->mark_sret (jit_convention::external); |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1810 matrix->mark_pointer_arg (jit_convention::external); |
15016 | 1811 |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1812 range->mark_sret (jit_convention::external); |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1813 range->mark_pointer_arg (jit_convention::external); |
15016 | 1814 |
1815 complex->set_pack (jit_convention::external, &jit_typeinfo::pack_complex); | |
1816 complex->set_unpack (jit_convention::external, &jit_typeinfo::unpack_complex); | |
1817 complex->set_packed_type (jit_convention::external, complex_ret); | |
1818 | |
1819 if (sizeof (void *) == 4) | |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1820 complex->mark_sret (jit_convention::external); |
15016 | 1821 |
15078
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1822 paren_subsref_fn.initialize (module, engine); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1823 paren_subsasgn_fn.initialize (module, engine); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1824 |
15016 | 1825 // bind global variables |
1826 lerror_state = new llvm::GlobalVariable (*module, bool_t, false, | |
1827 llvm::GlobalValue::ExternalLinkage, | |
1828 0, "error_state"); | |
1829 engine->addGlobalMapping (lerror_state, | |
1830 reinterpret_cast<void *> (&error_state)); | |
1831 | |
15603 | 1832 // sig_atomic_type is going to be some sort of integer |
1833 sig_atomic_type = llvm::Type::getIntNTy (context, sizeof(sig_atomic_t) * 8); | |
1834 loctave_interrupt_state | |
1835 = new llvm::GlobalVariable (*module, sig_atomic_type, false, | |
1836 llvm::GlobalValue::ExternalLinkage, 0, | |
1837 "octave_interrupt_state"); | |
1838 engine->addGlobalMapping (loctave_interrupt_state, | |
1839 reinterpret_cast<void *> (&octave_interrupt_state)); | |
1840 | |
15135
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
1841 // generic call function |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
1842 { |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
1843 jit_type *int_t = intN (sizeof (octave_builtin::fcn) * 8); |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1844 any_call = create_external (JIT_FN (octave_jit_call), any, int_t, int_t, |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1845 any_ptr, int_t); |
15135
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
1846 } |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
1847 |
15016 | 1848 // any with anything is an any op |
1849 jit_function fn; | |
1850 jit_type *binary_op_type = intN (sizeof (octave_value::binary_op) * 8); | |
1851 llvm::Type *llvm_bo_type = binary_op_type->to_llvm (); | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1852 jit_function any_binary = create_external (JIT_FN (octave_jit_binary_any_any), |
15016 | 1853 any, binary_op_type, any, any); |
1854 any_binary.mark_can_error (); | |
1855 binary_ops.resize (octave_value::num_binary_ops); | |
1856 for (size_t i = 0; i < octave_value::num_binary_ops; ++i) | |
1857 { | |
1858 octave_value::binary_op op = static_cast<octave_value::binary_op> (i); | |
1859 std::string op_name = octave_value::binary_op_as_string (op); | |
1860 binary_ops[i].stash_name ("binary" + op_name); | |
1861 } | |
1862 | |
15146
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1863 unary_ops.resize (octave_value::num_unary_ops); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1864 for (size_t i = 0; i < octave_value::num_unary_ops; ++i) |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1865 { |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1866 octave_value::unary_op op = static_cast<octave_value::unary_op> (i); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1867 std::string op_name = octave_value::unary_op_as_string (op); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1868 unary_ops[i].stash_name ("unary" + op_name); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1869 } |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1870 |
15016 | 1871 for (int op = 0; op < octave_value::num_binary_ops; ++op) |
1872 { | |
1873 llvm::Twine fn_name ("octave_jit_binary_any_any_"); | |
1874 fn_name = fn_name + llvm::Twine (op); | |
1875 | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1876 fn = create_internal (fn_name, any, any, any); |
15016 | 1877 fn.mark_can_error (); |
1878 llvm::BasicBlock *block = fn.new_block (); | |
1879 builder.SetInsertPoint (block); | |
1880 llvm::APInt op_int(sizeof (octave_value::binary_op) * 8, op, | |
1881 std::numeric_limits<octave_value::binary_op>::is_signed); | |
1882 llvm::Value *op_as_llvm = llvm::ConstantInt::get (llvm_bo_type, op_int); | |
1883 llvm::Value *ret = any_binary.call (builder, op_as_llvm, | |
1884 fn.argument (builder, 0), | |
1885 fn.argument (builder, 1)); | |
1886 fn.do_return (builder, ret); | |
1887 binary_ops[op].add_overload (fn); | |
1888 } | |
1889 | |
1890 // grab matrix | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1891 fn = create_external (JIT_FN (octave_jit_grab_matrix), matrix, matrix); |
15016 | 1892 grab_fn.add_overload (fn); |
1893 | |
15334
8125773322d4
Error on undefined an unused variables in JIT
Max Brister <max@2bass.com>
parents:
15311
diff
changeset
|
1894 grab_fn.add_overload (create_identity (scalar)); |
18554 | 1895 grab_fn.add_overload (create_identity (single)); |
18557 | 1896 grab_fn.add_overload (create_identity (intN (8))); |
18559 | 1897 grab_fn.add_overload (create_identity (intN (16))); |
18560 | 1898 grab_fn.add_overload (create_identity (intN (32))); |
18558
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
1899 grab_fn.add_overload (create_identity (intN (64))); |
18561 | 1900 grab_fn.add_overload (create_identity (uintN (8))); |
18555 | 1901 grab_fn.add_overload (create_identity (uintN (16))); |
18563 | 1902 grab_fn.add_overload (create_identity (uintN (32))); |
18562
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
1903 grab_fn.add_overload (create_identity (uintN (64))); |
15334
8125773322d4
Error on undefined an unused variables in JIT
Max Brister <max@2bass.com>
parents:
15311
diff
changeset
|
1904 grab_fn.add_overload (create_identity (scalar_ptr)); |
8125773322d4
Error on undefined an unused variables in JIT
Max Brister <max@2bass.com>
parents:
15311
diff
changeset
|
1905 grab_fn.add_overload (create_identity (any_ptr)); |
8125773322d4
Error on undefined an unused variables in JIT
Max Brister <max@2bass.com>
parents:
15311
diff
changeset
|
1906 grab_fn.add_overload (create_identity (boolean)); |
8125773322d4
Error on undefined an unused variables in JIT
Max Brister <max@2bass.com>
parents:
15311
diff
changeset
|
1907 grab_fn.add_overload (create_identity (complex)); |
8125773322d4
Error on undefined an unused variables in JIT
Max Brister <max@2bass.com>
parents:
15311
diff
changeset
|
1908 grab_fn.add_overload (create_identity (index)); |
8125773322d4
Error on undefined an unused variables in JIT
Max Brister <max@2bass.com>
parents:
15311
diff
changeset
|
1909 |
15016 | 1910 // release any |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1911 fn = create_external (JIT_FN (octave_jit_release_any), 0, any); |
15016 | 1912 release_fn.add_overload (fn); |
1913 release_fn.stash_name ("release"); | |
1914 | |
1915 // release matrix | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1916 fn = create_external (JIT_FN (octave_jit_release_matrix), 0, matrix); |
15016 | 1917 release_fn.add_overload (fn); |
1918 | |
15337
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
1919 // destroy |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
1920 destroy_fn = release_fn; |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
1921 destroy_fn.stash_name ("destroy"); |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
1922 destroy_fn.add_overload (create_identity(scalar)); |
18554 | 1923 destroy_fn.add_overload (create_identity(single)); |
18557 | 1924 destroy_fn.add_overload (create_identity(intN (8))); |
18559 | 1925 destroy_fn.add_overload (create_identity(intN (16))); |
18560 | 1926 destroy_fn.add_overload (create_identity(intN (32))); |
18558
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
1927 destroy_fn.add_overload (create_identity(intN (64))); |
18561 | 1928 destroy_fn.add_overload (create_identity(uintN (8))); |
18555 | 1929 destroy_fn.add_overload (create_identity(uintN (16))); |
18563 | 1930 destroy_fn.add_overload (create_identity(uintN (32))); |
18562
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
1931 destroy_fn.add_overload (create_identity(uintN (64))); |
15337
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
1932 destroy_fn.add_overload (create_identity(boolean)); |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
1933 destroy_fn.add_overload (create_identity(index)); |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
1934 destroy_fn.add_overload (create_identity(complex)); |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
1935 |
18323
0122fad27435
jit compiler: Fix uminus op support with scalar type
LYH <lyh.kernel@gmail.com>
parents:
18279
diff
changeset
|
1936 // -------------------- scalar related operations -------------------- |
0122fad27435
jit compiler: Fix uminus op support with scalar type
LYH <lyh.kernel@gmail.com>
parents:
18279
diff
changeset
|
1937 |
15016 | 1938 // now for binary scalar operations |
1939 add_binary_op (scalar, octave_value::op_add, llvm::Instruction::FAdd); | |
1940 add_binary_op (scalar, octave_value::op_sub, llvm::Instruction::FSub); | |
1941 add_binary_op (scalar, octave_value::op_mul, llvm::Instruction::FMul); | |
1942 add_binary_op (scalar, octave_value::op_el_mul, llvm::Instruction::FMul); | |
1943 | |
1944 add_binary_fcmp (scalar, octave_value::op_lt, llvm::CmpInst::FCMP_ULT); | |
1945 add_binary_fcmp (scalar, octave_value::op_le, llvm::CmpInst::FCMP_ULE); | |
1946 add_binary_fcmp (scalar, octave_value::op_eq, llvm::CmpInst::FCMP_UEQ); | |
1947 add_binary_fcmp (scalar, octave_value::op_ge, llvm::CmpInst::FCMP_UGE); | |
1948 add_binary_fcmp (scalar, octave_value::op_gt, llvm::CmpInst::FCMP_UGT); | |
1949 add_binary_fcmp (scalar, octave_value::op_ne, llvm::CmpInst::FCMP_UNE); | |
1950 | |
18564
5a5a67799338
jit compiler: Use seperate function for division operation
Stefan Mahr <dac922@gmx.de>
parents:
18563
diff
changeset
|
1951 fn = divide_float (scalar); |
15016 | 1952 binary_ops[octave_value::op_div].add_overload (fn); |
1953 binary_ops[octave_value::op_el_div].add_overload (fn); | |
1954 | |
1955 // ldiv is the same as div with the operators reversed | |
1956 fn = mirror_binary (fn); | |
1957 binary_ops[octave_value::op_ldiv].add_overload (fn); | |
1958 binary_ops[octave_value::op_el_ldiv].add_overload (fn); | |
1959 | |
1960 // In general, the result of scalar ^ scalar is a complex number. We might be | |
1961 // able to improve on this if we keep track of the range of values varaibles | |
1962 // can take on. | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1963 fn = create_external (JIT_FN (octave_jit_pow_scalar_scalar), complex, scalar, |
15016 | 1964 scalar); |
1965 binary_ops[octave_value::op_pow].add_overload (fn); | |
1966 binary_ops[octave_value::op_el_pow].add_overload (fn); | |
1967 | |
15146
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1968 // now for unary scalar operations |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1969 // FIXME: Impelment not |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1970 fn = create_internal ("octave_jit_++", scalar, scalar); |
18564
5a5a67799338
jit compiler: Use seperate function for division operation
Stefan Mahr <dac922@gmx.de>
parents:
18563
diff
changeset
|
1971 llvm::BasicBlock *body = fn.new_block (); |
15146
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1972 builder.SetInsertPoint (body); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1973 { |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1974 llvm::Value *one = llvm::ConstantFP::get (scalar_t, 1); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1975 llvm::Value *val = fn.argument (builder, 0); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1976 val = builder.CreateFAdd (val, one); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1977 fn.do_return (builder, val); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1978 } |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1979 unary_ops[octave_value::op_incr].add_overload (fn); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1980 |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1981 fn = create_internal ("octave_jit_--", scalar, scalar); |
15146
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1982 body = fn.new_block (); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1983 builder.SetInsertPoint (body); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1984 { |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1985 llvm::Value *one = llvm::ConstantFP::get (scalar_t, 1); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1986 llvm::Value *val = fn.argument (builder, 0); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1987 val = builder.CreateFSub (val, one); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1988 fn.do_return (builder, val); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1989 } |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1990 unary_ops[octave_value::op_decr].add_overload (fn); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1991 |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1992 fn = create_internal ("octave_jit_uminus", scalar, scalar); |
15146
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1993 body = fn.new_block (); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1994 builder.SetInsertPoint (body); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1995 { |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1996 llvm::Value *mone = llvm::ConstantFP::get (scalar_t, -1); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1997 llvm::Value *val = fn.argument (builder, 0); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1998 val = builder.CreateFMul (val, mone); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1999 fn.do_return (builder, val); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
2000 } |
18323
0122fad27435
jit compiler: Fix uminus op support with scalar type
LYH <lyh.kernel@gmail.com>
parents:
18279
diff
changeset
|
2001 unary_ops[octave_value::op_uminus].add_overload (fn); |
15146
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
2002 |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
2003 fn = create_identity (scalar); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
2004 unary_ops[octave_value::op_uplus].add_overload (fn); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
2005 unary_ops[octave_value::op_transpose].add_overload (fn); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
2006 unary_ops[octave_value::op_hermitian].add_overload (fn); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
2007 |
18554 | 2008 /************************************************************ |
2009 * | |
2010 * complex related operations | |
2011 * | |
2012 ************************************************************/ | |
2013 | |
15016 | 2014 // now for binary complex operations |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2015 fn = create_internal ("octave_jit_+_complex_complex", complex, complex, |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2016 complex); |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2017 body = fn.new_block (); |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2018 builder.SetInsertPoint (body); |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2019 { |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2020 llvm::Value *lhs = fn.argument (builder, 0); |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2021 llvm::Value *rhs = fn.argument (builder, 1); |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2022 llvm::Value *real = builder.CreateFAdd (complex_real (lhs), |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2023 complex_real (rhs)); |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2024 llvm::Value *imag = builder.CreateFAdd (complex_imag (lhs), |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2025 complex_imag (rhs)); |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2026 fn.do_return (builder, complex_new (real, imag)); |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2027 } |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2028 binary_ops[octave_value::op_add].add_overload (fn); |
15016 | 2029 |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2030 fn = create_internal ("octave_jit_-_complex_complex", complex, complex, |
15016 | 2031 complex); |
2032 body = fn.new_block (); | |
2033 builder.SetInsertPoint (body); | |
2034 { | |
2035 llvm::Value *lhs = fn.argument (builder, 0); | |
2036 llvm::Value *rhs = fn.argument (builder, 1); | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2037 llvm::Value *real = builder.CreateFSub (complex_real (lhs), |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2038 complex_real (rhs)); |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2039 llvm::Value *imag = builder.CreateFSub (complex_imag (lhs), |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2040 complex_imag (rhs)); |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2041 fn.do_return (builder, complex_new (real, imag)); |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2042 } |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2043 binary_ops[octave_value::op_sub].add_overload (fn); |
15016 | 2044 |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2045 fn = create_external (JIT_FN (octave_jit_complex_mul), |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2046 complex, complex, complex); |
15016 | 2047 binary_ops[octave_value::op_mul].add_overload (fn); |
2048 binary_ops[octave_value::op_el_mul].add_overload (fn); | |
2049 | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2050 jit_function complex_div = create_external (JIT_FN (octave_jit_complex_div), |
15016 | 2051 complex, complex, complex); |
2052 complex_div.mark_can_error (); | |
2053 binary_ops[octave_value::op_div].add_overload (fn); | |
2054 binary_ops[octave_value::op_ldiv].add_overload (fn); | |
2055 | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2056 fn = create_external (JIT_FN (octave_jit_pow_complex_complex), complex, |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2057 complex, complex); |
15016 | 2058 binary_ops[octave_value::op_pow].add_overload (fn); |
2059 binary_ops[octave_value::op_el_pow].add_overload (fn); | |
2060 | |
18554 | 2061 /************************************************************ |
2062 * | |
2063 * single related operations | |
2064 * | |
2065 ************************************************************/ | |
2066 | |
2067 // now for binary single operations | |
2068 add_binary_op (single, octave_value::op_add, llvm::Instruction::FAdd); | |
2069 add_binary_op (single, octave_value::op_sub, llvm::Instruction::FSub); | |
2070 add_binary_op (single, octave_value::op_mul, llvm::Instruction::FMul); | |
2071 add_binary_op (single, octave_value::op_el_mul, llvm::Instruction::FMul); | |
2072 | |
2073 add_binary_fcmp (single, octave_value::op_lt, llvm::CmpInst::FCMP_ULT); | |
2074 add_binary_fcmp (single, octave_value::op_le, llvm::CmpInst::FCMP_ULE); | |
2075 add_binary_fcmp (single, octave_value::op_eq, llvm::CmpInst::FCMP_UEQ); | |
2076 add_binary_fcmp (single, octave_value::op_ge, llvm::CmpInst::FCMP_UGE); | |
2077 add_binary_fcmp (single, octave_value::op_gt, llvm::CmpInst::FCMP_UGT); | |
2078 add_binary_fcmp (single, octave_value::op_ne, llvm::CmpInst::FCMP_UNE); | |
2079 | |
18564
5a5a67799338
jit compiler: Use seperate function for division operation
Stefan Mahr <dac922@gmx.de>
parents:
18563
diff
changeset
|
2080 fn = divide_float (single); |
18554 | 2081 binary_ops[octave_value::op_div].add_overload (fn); |
2082 binary_ops[octave_value::op_el_div].add_overload (fn); | |
2083 | |
2084 // ldiv is the same as div with the operators reversed | |
2085 fn = mirror_binary (fn); | |
2086 binary_ops[octave_value::op_ldiv].add_overload (fn); | |
2087 binary_ops[octave_value::op_el_ldiv].add_overload (fn); | |
2088 | |
2089 // In general, the result of scalar ^ scalar is a complex number. We might be | |
2090 // able to improve on this if we keep track of the range of values varaibles | |
2091 // can take on. | |
2092 fn = create_external (JIT_FN (octave_jit_pow_single_single), complex, single, | |
2093 single); | |
2094 binary_ops[octave_value::op_pow].add_overload (fn); | |
2095 binary_ops[octave_value::op_el_pow].add_overload (fn); | |
2096 | |
2097 // now for unary single operations | |
2098 // FIXME: Impelment not | |
2099 fn = create_internal ("octave_jit_++", single, single); | |
2100 body = fn.new_block (); | |
2101 builder.SetInsertPoint (body); | |
2102 { | |
2103 llvm::Value *one = llvm::ConstantFP::get (single_t, 1); | |
2104 llvm::Value *val = fn.argument (builder, 0); | |
2105 val = builder.CreateFAdd (val, one); | |
2106 fn.do_return (builder, val); | |
2107 } | |
2108 unary_ops[octave_value::op_incr].add_overload (fn); | |
2109 | |
2110 fn = create_internal ("octave_jit_--", single, single); | |
2111 body = fn.new_block (); | |
2112 builder.SetInsertPoint (body); | |
2113 { | |
2114 llvm::Value *one = llvm::ConstantFP::get (single_t, 1); | |
2115 llvm::Value *val = fn.argument (builder, 0); | |
2116 val = builder.CreateFSub (val, one); | |
2117 fn.do_return (builder, val); | |
2118 } | |
2119 unary_ops[octave_value::op_decr].add_overload (fn); | |
2120 | |
2121 fn = create_internal ("octave_jit_uminus", single, single); | |
2122 body = fn.new_block (); | |
2123 builder.SetInsertPoint (body); | |
2124 { | |
2125 llvm::Value *mone = llvm::ConstantFP::get (single_t, -1); | |
2126 llvm::Value *val = fn.argument (builder, 0); | |
2127 val = builder.CreateFMul (val, mone); | |
2128 fn.do_return (builder, val); | |
2129 } | |
2130 unary_ops[octave_value::op_uminus].add_overload (fn); | |
2131 | |
2132 fn = create_identity (single); | |
2133 unary_ops[octave_value::op_uplus].add_overload (fn); | |
2134 unary_ops[octave_value::op_transpose].add_overload (fn); | |
2135 unary_ops[octave_value::op_hermitian].add_overload (fn); | |
2136 | |
18555 | 2137 /************************************************************ |
2138 * | |
18557 | 2139 * int8 related operations |
2140 * | |
2141 ************************************************************/ | |
2142 | |
2143 // now for binary int8 operations | |
2144 fn = create_external (JIT_FN (octave_jit_add_int8_int8), intN (8), intN (8), | |
2145 intN (8)); | |
2146 binary_ops[octave_value::op_add].add_overload (fn); | |
2147 fn = create_external (JIT_FN (octave_jit_sub_int8_int8), intN (8), intN (8), | |
2148 intN (8)); | |
2149 binary_ops[octave_value::op_sub].add_overload (fn); | |
2150 fn = create_external (JIT_FN (octave_jit_mul_int8_int8), intN (8), intN (8), | |
2151 intN (8)); | |
2152 binary_ops[octave_value::op_mul].add_overload (fn); | |
2153 binary_ops[octave_value::op_el_mul].add_overload (fn); | |
2154 | |
2155 add_binary_icmp (intN (8), octave_value::op_lt, llvm::CmpInst::ICMP_SLT); | |
2156 add_binary_icmp (intN (8), octave_value::op_le, llvm::CmpInst::ICMP_SLE); | |
2157 add_binary_icmp (intN (8), octave_value::op_eq, llvm::CmpInst::ICMP_EQ); | |
2158 add_binary_icmp (intN (8), octave_value::op_ge, llvm::CmpInst::ICMP_SGE); | |
2159 add_binary_icmp (intN (8), octave_value::op_gt, llvm::CmpInst::ICMP_SGT); | |
2160 add_binary_icmp (intN (8), octave_value::op_ne, llvm::CmpInst::ICMP_NE); | |
2161 | |
2162 // FIXME: saturation divide definition? interpreter convert int to double, calculate and round. | |
2163 // divide is annoying because it might error | |
2164 // FIXME: Implement div | |
2165 | |
2166 // FIXME: Implement pow | |
2167 | |
2168 // now for unary int8 operations | |
2169 // FIXME: Impelment not | |
2170 fn = create_external (JIT_FN (octave_jit_incr_int8), intN (8), intN (8)); | |
2171 unary_ops[octave_value::op_incr].add_overload (fn); | |
2172 | |
2173 fn = create_external (JIT_FN (octave_jit_decr_int8), intN (8), intN (8)); | |
2174 unary_ops[octave_value::op_decr].add_overload (fn); | |
2175 | |
2176 fn = create_internal ("octave_jit_uminus", intN (8), intN (8)); | |
2177 body = fn.new_block (); | |
2178 builder.SetInsertPoint (body); | |
2179 { | |
2180 llvm::Value *mone = llvm::ConstantInt::get (int8__t, -1); | |
2181 llvm::Value *val = fn.argument (builder, 0); | |
2182 val = builder.CreateMul (val, mone); | |
2183 fn.do_return (builder, val); | |
2184 } | |
2185 unary_ops[octave_value::op_uminus].add_overload (fn); | |
2186 | |
2187 fn = create_identity (intN (8)); | |
2188 unary_ops[octave_value::op_uplus].add_overload (fn); | |
2189 unary_ops[octave_value::op_transpose].add_overload (fn); | |
2190 unary_ops[octave_value::op_hermitian].add_overload (fn); | |
2191 | |
2192 /************************************************************ | |
2193 * | |
18559 | 2194 * int16 related operations |
2195 * | |
2196 ************************************************************/ | |
2197 | |
2198 // now for binary int16 operations | |
2199 fn = create_external (JIT_FN (octave_jit_add_int16_int16), intN (16), intN (16), | |
2200 intN (16)); | |
2201 binary_ops[octave_value::op_add].add_overload (fn); | |
2202 fn = create_external (JIT_FN (octave_jit_sub_int16_int16), intN (16), intN (16), | |
2203 intN (16)); | |
2204 binary_ops[octave_value::op_sub].add_overload (fn); | |
2205 fn = create_external (JIT_FN (octave_jit_mul_int16_int16), intN (16), intN (16), | |
2206 intN (16)); | |
2207 binary_ops[octave_value::op_mul].add_overload (fn); | |
2208 binary_ops[octave_value::op_el_mul].add_overload (fn); | |
2209 | |
2210 add_binary_icmp (intN (16), octave_value::op_lt, llvm::CmpInst::ICMP_SLT); | |
2211 add_binary_icmp (intN (16), octave_value::op_le, llvm::CmpInst::ICMP_SLE); | |
2212 add_binary_icmp (intN (16), octave_value::op_eq, llvm::CmpInst::ICMP_EQ); | |
2213 add_binary_icmp (intN (16), octave_value::op_ge, llvm::CmpInst::ICMP_SGE); | |
2214 add_binary_icmp (intN (16), octave_value::op_gt, llvm::CmpInst::ICMP_SGT); | |
2215 add_binary_icmp (intN (16), octave_value::op_ne, llvm::CmpInst::ICMP_NE); | |
2216 | |
2217 // FIXME: saturation divide definition? interpreter convert int to double, calculate and round. | |
2218 // divide is annoying because it might error | |
2219 // FIXME: Implement div | |
2220 | |
2221 // FIXME: Implement pow | |
2222 | |
2223 // now for unary int16 operations | |
2224 // FIXME: Impelment not | |
2225 fn = create_external (JIT_FN (octave_jit_incr_int16), intN (16), intN (16)); | |
2226 unary_ops[octave_value::op_incr].add_overload (fn); | |
2227 | |
2228 fn = create_external (JIT_FN (octave_jit_decr_int16), intN (16), intN (16)); | |
2229 unary_ops[octave_value::op_decr].add_overload (fn); | |
2230 | |
2231 fn = create_internal ("octave_jit_uminus", intN (16), intN (16)); | |
2232 body = fn.new_block (); | |
2233 builder.SetInsertPoint (body); | |
2234 { | |
2235 llvm::Value *mone = llvm::ConstantInt::get (int16__t, -1); | |
2236 llvm::Value *val = fn.argument (builder, 0); | |
2237 val = builder.CreateMul (val, mone); | |
2238 fn.do_return (builder, val); | |
2239 } | |
2240 unary_ops[octave_value::op_uminus].add_overload (fn); | |
2241 | |
2242 fn = create_identity (intN (16)); | |
2243 unary_ops[octave_value::op_uplus].add_overload (fn); | |
2244 unary_ops[octave_value::op_transpose].add_overload (fn); | |
2245 unary_ops[octave_value::op_hermitian].add_overload (fn); | |
2246 | |
2247 /************************************************************ | |
2248 * | |
18560 | 2249 * int32 related operations |
2250 * | |
2251 ************************************************************/ | |
2252 | |
2253 // FIXME: interpreter overflow occurs at minus + minus, minus - plus | |
2254 // now for binary int32 operations | |
2255 fn = create_external (JIT_FN (octave_jit_add_int32_int32), intN (32), intN (32), | |
2256 intN (32)); | |
2257 binary_ops[octave_value::op_add].add_overload (fn); | |
2258 fn = create_external (JIT_FN (octave_jit_sub_int32_int32), intN (32), intN (32), | |
2259 intN (32)); | |
2260 binary_ops[octave_value::op_sub].add_overload (fn); | |
2261 fn = create_external (JIT_FN (octave_jit_mul_int32_int32), intN (32), intN (32), | |
2262 intN (32)); | |
2263 binary_ops[octave_value::op_mul].add_overload (fn); | |
2264 binary_ops[octave_value::op_el_mul].add_overload (fn); | |
2265 | |
2266 add_binary_icmp (intN (32), octave_value::op_lt, llvm::CmpInst::ICMP_SLT); | |
2267 add_binary_icmp (intN (32), octave_value::op_le, llvm::CmpInst::ICMP_SLE); | |
2268 add_binary_icmp (intN (32), octave_value::op_eq, llvm::CmpInst::ICMP_EQ); | |
2269 add_binary_icmp (intN (32), octave_value::op_ge, llvm::CmpInst::ICMP_SGE); | |
2270 add_binary_icmp (intN (32), octave_value::op_gt, llvm::CmpInst::ICMP_SGT); | |
2271 add_binary_icmp (intN (32), octave_value::op_ne, llvm::CmpInst::ICMP_NE); | |
2272 | |
2273 // FIXME: saturation divide definition? interpreter convert int to double, calculate and round. | |
2274 // divide is annoying because it might error | |
2275 // FIXME: Implement div | |
2276 | |
2277 // FIXME: Implement pow | |
2278 | |
2279 // now for unary int32 operations | |
2280 // FIXME: Impelment not | |
2281 fn = create_external (JIT_FN (octave_jit_incr_int32), intN (32), intN (32)); | |
2282 unary_ops[octave_value::op_incr].add_overload (fn); | |
2283 | |
2284 fn = create_external (JIT_FN (octave_jit_decr_int32), intN (32), intN (32)); | |
2285 unary_ops[octave_value::op_decr].add_overload (fn); | |
2286 | |
2287 fn = create_internal ("octave_jit_uminus", intN (32), intN (32)); | |
2288 body = fn.new_block (); | |
2289 builder.SetInsertPoint (body); | |
2290 { | |
2291 llvm::Value *mone = llvm::ConstantInt::get (int32__t, -1); | |
2292 llvm::Value *val = fn.argument (builder, 0); | |
2293 val = builder.CreateMul (val, mone); | |
2294 fn.do_return (builder, val); | |
2295 } | |
2296 unary_ops[octave_value::op_uminus].add_overload (fn); | |
2297 | |
2298 fn = create_identity (intN (32)); | |
2299 unary_ops[octave_value::op_uplus].add_overload (fn); | |
2300 unary_ops[octave_value::op_transpose].add_overload (fn); | |
2301 unary_ops[octave_value::op_hermitian].add_overload (fn); | |
2302 | |
2303 /************************************************************ | |
2304 * | |
18558
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2305 * int64 related operations |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2306 * |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2307 ************************************************************/ |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2308 |
18559 | 2309 // FIXME: interpreter overflow occurs at minus + minus, minus - plus |
18558
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2310 // now for binary int64 operations |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2311 fn = create_external (JIT_FN (octave_jit_add_int64_int64), intN (64), intN (64), |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2312 intN (64)); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2313 binary_ops[octave_value::op_add].add_overload (fn); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2314 fn = create_external (JIT_FN (octave_jit_sub_int64_int64), intN (64), intN (64), |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2315 intN (64)); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2316 binary_ops[octave_value::op_sub].add_overload (fn); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2317 fn = create_external (JIT_FN (octave_jit_mul_int64_int64), intN (64), intN (64), |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2318 intN (64)); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2319 binary_ops[octave_value::op_mul].add_overload (fn); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2320 binary_ops[octave_value::op_el_mul].add_overload (fn); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2321 |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2322 add_binary_icmp (intN (64), octave_value::op_lt, llvm::CmpInst::ICMP_SLT); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2323 add_binary_icmp (intN (64), octave_value::op_le, llvm::CmpInst::ICMP_SLE); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2324 add_binary_icmp (intN (64), octave_value::op_eq, llvm::CmpInst::ICMP_EQ); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2325 add_binary_icmp (intN (64), octave_value::op_ge, llvm::CmpInst::ICMP_SGE); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2326 add_binary_icmp (intN (64), octave_value::op_gt, llvm::CmpInst::ICMP_SGT); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2327 add_binary_icmp (intN (64), octave_value::op_ne, llvm::CmpInst::ICMP_NE); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2328 |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2329 // FIXME: saturation divide definition? interpreter convert int to double, calculate and round. |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2330 // divide is annoying because it might error |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2331 // FIXME: Implement div |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2332 |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2333 // FIXME: Implement pow |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2334 |
18559 | 2335 // now for unary int64 operations |
18558
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2336 // FIXME: Impelment not |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2337 fn = create_external (JIT_FN (octave_jit_incr_int64), intN (64), intN (64)); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2338 unary_ops[octave_value::op_incr].add_overload (fn); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2339 |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2340 fn = create_external (JIT_FN (octave_jit_decr_int64), intN (64), intN (64)); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2341 unary_ops[octave_value::op_decr].add_overload (fn); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2342 |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2343 fn = create_internal ("octave_jit_uminus", intN (64), intN (64)); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2344 body = fn.new_block (); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2345 builder.SetInsertPoint (body); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2346 { |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2347 llvm::Value *mone = llvm::ConstantInt::get (int64__t, -1); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2348 llvm::Value *val = fn.argument (builder, 0); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2349 val = builder.CreateMul (val, mone); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2350 fn.do_return (builder, val); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2351 } |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2352 unary_ops[octave_value::op_uminus].add_overload (fn); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2353 |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2354 fn = create_identity (intN (64)); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2355 unary_ops[octave_value::op_uplus].add_overload (fn); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2356 unary_ops[octave_value::op_transpose].add_overload (fn); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2357 unary_ops[octave_value::op_hermitian].add_overload (fn); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2358 |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2359 /************************************************************ |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2360 * |
18561 | 2361 * uint8 related operations |
2362 * | |
2363 ************************************************************/ | |
2364 | |
2365 // now for binary uint8 operations | |
2366 fn = create_external (JIT_FN (octave_jit_add_uint8_uint8), uintN (8), uintN (8), | |
2367 uintN (8)); | |
2368 binary_ops[octave_value::op_add].add_overload (fn); | |
2369 fn = create_external (JIT_FN (octave_jit_sub_uint8_uint8), uintN (8), uintN (8), | |
2370 uintN (8)); | |
2371 binary_ops[octave_value::op_sub].add_overload (fn); | |
2372 fn = create_external (JIT_FN (octave_jit_mul_uint8_uint8), uintN (8), uintN (8), | |
2373 uintN (8)); | |
2374 binary_ops[octave_value::op_mul].add_overload (fn); | |
2375 binary_ops[octave_value::op_el_mul].add_overload (fn); | |
2376 | |
2377 add_binary_icmp (uintN (8), octave_value::op_lt, llvm::CmpInst::ICMP_ULT); | |
2378 add_binary_icmp (uintN (8), octave_value::op_le, llvm::CmpInst::ICMP_ULE); | |
2379 add_binary_icmp (uintN (8), octave_value::op_eq, llvm::CmpInst::ICMP_EQ); | |
2380 add_binary_icmp (uintN (8), octave_value::op_ge, llvm::CmpInst::ICMP_UGE); | |
2381 add_binary_icmp (uintN (8), octave_value::op_gt, llvm::CmpInst::ICMP_UGT); | |
2382 add_binary_icmp (uintN (8), octave_value::op_ne, llvm::CmpInst::ICMP_NE); | |
2383 | |
2384 // FIXME: saturation divide definition? interpreter convert uint to double, calculate and round. | |
2385 // divide is annoying because it might error | |
2386 // FIXME: Implement div | |
2387 | |
2388 // FIXME: Implement pow | |
2389 | |
2390 // now for unary uint8 operations | |
2391 // FIXME: Impelment not | |
2392 fn = create_external (JIT_FN (octave_jit_incr_uint8), uintN (8), uintN (8)); | |
2393 unary_ops[octave_value::op_incr].add_overload (fn); | |
2394 | |
2395 fn = create_external (JIT_FN (octave_jit_decr_uint8), uintN (8), uintN (8)); | |
2396 unary_ops[octave_value::op_decr].add_overload (fn); | |
2397 | |
2398 fn = create_internal ("octave_jit_uminus", uintN (8), uintN (8)); | |
2399 body = fn.new_block (); | |
2400 builder.SetInsertPoint (body); | |
2401 { | |
2402 llvm::Value *zero = llvm::ConstantInt::get (uint8__t, 0); | |
2403 | |
2404 fn.do_return (builder, zero); | |
2405 } | |
2406 unary_ops[octave_value::op_uminus].add_overload (fn); | |
2407 | |
2408 fn = create_identity (uintN (8)); | |
2409 unary_ops[octave_value::op_uplus].add_overload (fn); | |
2410 unary_ops[octave_value::op_transpose].add_overload (fn); | |
2411 unary_ops[octave_value::op_hermitian].add_overload (fn); | |
2412 | |
2413 /************************************************************ | |
2414 * | |
18555 | 2415 * uint16 related operations |
2416 * | |
2417 ************************************************************/ | |
2418 | |
2419 // now for binary uint16 operations | |
2420 fn = create_external (JIT_FN (octave_jit_add_uint16_uint16), uintN (16), uintN (16), | |
2421 uintN (16)); | |
2422 binary_ops[octave_value::op_add].add_overload (fn); | |
2423 fn = create_external (JIT_FN (octave_jit_sub_uint16_uint16), uintN (16), uintN (16), | |
2424 uintN (16)); | |
2425 binary_ops[octave_value::op_sub].add_overload (fn); | |
2426 fn = create_external (JIT_FN (octave_jit_mul_uint16_uint16), uintN (16), uintN (16), | |
2427 uintN (16)); | |
2428 binary_ops[octave_value::op_mul].add_overload (fn); | |
2429 binary_ops[octave_value::op_el_mul].add_overload (fn); | |
2430 | |
2431 add_binary_icmp (uintN (16), octave_value::op_lt, llvm::CmpInst::ICMP_ULT); | |
2432 add_binary_icmp (uintN (16), octave_value::op_le, llvm::CmpInst::ICMP_ULE); | |
2433 add_binary_icmp (uintN (16), octave_value::op_eq, llvm::CmpInst::ICMP_EQ); | |
2434 add_binary_icmp (uintN (16), octave_value::op_ge, llvm::CmpInst::ICMP_UGE); | |
2435 add_binary_icmp (uintN (16), octave_value::op_gt, llvm::CmpInst::ICMP_UGT); | |
2436 add_binary_icmp (uintN (16), octave_value::op_ne, llvm::CmpInst::ICMP_NE); | |
2437 | |
2438 // FIXME: saturation divide definition? interpreter convert uint to double, calculate and round. | |
2439 // divide is annoying because it might error | |
2440 #if 0 | |
2441 fn = create_internal ("octave_jit_div_uint16_uint16", uintN (16), uintN (16), uintN (16)); | |
2442 fn.mark_can_error (); | |
2443 | |
2444 body = fn.new_block (); | |
2445 builder.SetInsertPoint (body); | |
2446 { | |
2447 llvm::BasicBlock *warn_block = fn.new_block ("warn"); | |
2448 llvm::BasicBlock *normal_block = fn.new_block ("normal"); | |
2449 | |
2450 llvm::Value *zero = llvm::ConstantInt::get (uint16__t, 0); | |
2451 llvm::Value *check = builder.CreateICmpEQ (zero, fn.argument (builder, 1)); | |
2452 builder.CreateCondBr (check, warn_block, normal_block); | |
2453 | |
2454 builder.SetInsertPoint (warn_block); | |
2455 gripe_div0.call (builder); | |
2456 builder.CreateBr (normal_block); | |
2457 | |
2458 builder.SetInsertPoint (normal_block); | |
2459 llvm::Value *ret = builder.CreateUDiv (fn.argument (builder, 0), | |
2460 fn.argument (builder, 1)); | |
2461 fn.do_return (builder, ret); | |
2462 } | |
2463 binary_ops[octave_value::op_div].add_overload (fn); | |
2464 binary_ops[octave_value::op_el_div].add_overload (fn); | |
2465 | |
2466 // ldiv is the same as div with the operators reversed | |
2467 fn = mirror_binary (fn); | |
2468 binary_ops[octave_value::op_ldiv].add_overload (fn); | |
2469 binary_ops[octave_value::op_el_ldiv].add_overload (fn); | |
2470 #endif | |
2471 | |
2472 // FIXME: Implement pow | |
2473 | |
2474 // now for unary uint16 operations | |
2475 // FIXME: Impelment not | |
2476 fn = create_external (JIT_FN (octave_jit_incr_uint16), uintN (16), uintN (16)); | |
2477 unary_ops[octave_value::op_incr].add_overload (fn); | |
2478 | |
2479 fn = create_external (JIT_FN (octave_jit_decr_uint16), uintN (16), uintN (16)); | |
2480 unary_ops[octave_value::op_decr].add_overload (fn); | |
2481 | |
2482 fn = create_internal ("octave_jit_uminus", uintN (16), uintN (16)); | |
2483 body = fn.new_block (); | |
2484 builder.SetInsertPoint (body); | |
2485 { | |
2486 llvm::Value *zero = llvm::ConstantInt::get (uint16__t, 0); | |
2487 | |
2488 fn.do_return (builder, zero); | |
2489 } | |
2490 unary_ops[octave_value::op_uminus].add_overload (fn); | |
2491 | |
2492 fn = create_identity (uintN (16)); | |
2493 unary_ops[octave_value::op_uplus].add_overload (fn); | |
2494 unary_ops[octave_value::op_transpose].add_overload (fn); | |
2495 unary_ops[octave_value::op_hermitian].add_overload (fn); | |
2496 | |
18562
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
2497 /************************************************************ |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
2498 * |
18563 | 2499 * uint32 related operations |
2500 * | |
2501 ************************************************************/ | |
2502 | |
2503 // now for binary uint32 operations | |
2504 fn = create_external (JIT_FN (octave_jit_add_uint32_uint32), uintN (32), uintN (32), | |
2505 uintN (32)); | |
2506 binary_ops[octave_value::op_add].add_overload (fn); | |
2507 fn = create_external (JIT_FN (octave_jit_sub_uint32_uint32), uintN (32), uintN (32), | |
2508 uintN (32)); | |
2509 binary_ops[octave_value::op_sub].add_overload (fn); | |
2510 fn = create_external (JIT_FN (octave_jit_mul_uint32_uint32), uintN (32), uintN (32), | |
2511 uintN (32)); | |
2512 binary_ops[octave_value::op_mul].add_overload (fn); | |
2513 binary_ops[octave_value::op_el_mul].add_overload (fn); | |
2514 | |
2515 add_binary_icmp (uintN (32), octave_value::op_lt, llvm::CmpInst::ICMP_ULT); | |
2516 add_binary_icmp (uintN (32), octave_value::op_le, llvm::CmpInst::ICMP_ULE); | |
2517 add_binary_icmp (uintN (32), octave_value::op_eq, llvm::CmpInst::ICMP_EQ); | |
2518 add_binary_icmp (uintN (32), octave_value::op_ge, llvm::CmpInst::ICMP_UGE); | |
2519 add_binary_icmp (uintN (32), octave_value::op_gt, llvm::CmpInst::ICMP_UGT); | |
2520 add_binary_icmp (uintN (32), octave_value::op_ne, llvm::CmpInst::ICMP_NE); | |
2521 | |
2522 // FIXME: saturation divide definition? interpreter convert uint to double, calculate and round. | |
2523 // divide is annoying because it might error | |
2524 // FIXME: Implement div | |
2525 | |
2526 // FIXME: Implement pow | |
2527 | |
2528 // now for unary uint32 operations | |
2529 // FIXME: Impelment not | |
2530 fn = create_external (JIT_FN (octave_jit_incr_uint32), uintN (32), uintN (32)); | |
2531 unary_ops[octave_value::op_incr].add_overload (fn); | |
2532 | |
2533 fn = create_external (JIT_FN (octave_jit_decr_uint32), uintN (32), uintN (32)); | |
2534 unary_ops[octave_value::op_decr].add_overload (fn); | |
2535 | |
2536 fn = create_internal ("octave_jit_uminus", uintN (32), uintN (32)); | |
2537 body = fn.new_block (); | |
2538 builder.SetInsertPoint (body); | |
2539 { | |
2540 llvm::Value *zero = llvm::ConstantInt::get (uint32__t, 0); | |
2541 | |
2542 fn.do_return (builder, zero); | |
2543 } | |
2544 unary_ops[octave_value::op_uminus].add_overload (fn); | |
2545 | |
2546 fn = create_identity (uintN (32)); | |
2547 unary_ops[octave_value::op_uplus].add_overload (fn); | |
2548 unary_ops[octave_value::op_transpose].add_overload (fn); | |
2549 unary_ops[octave_value::op_hermitian].add_overload (fn); | |
2550 | |
2551 /************************************************************ | |
2552 * | |
18562
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
2553 * uint64 related operations |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
2554 * |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
2555 ************************************************************/ |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
2556 |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
2557 // now for binary uint64 operations |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
2558 fn = create_external (JIT_FN (octave_jit_add_uint64_uint64), uintN (64), uintN (64), |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
2559 uintN (64)); |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
2560 binary_ops[octave_value::op_add].add_overload (fn); |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
2561 fn = create_external (JIT_FN (octave_jit_sub_uint64_uint64), uintN (64), uintN (64), |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
2562 uintN (64)); |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
2563 binary_ops[octave_value::op_sub].add_overload (fn); |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
2564 fn = create_external (JIT_FN (octave_jit_mul_uint64_uint64), uintN (64), uintN (64), |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
2565 uintN (64)); |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
2566 binary_ops[octave_value::op_mul].add_overload (fn); |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
2567 binary_ops[octave_value::op_el_mul].add_overload (fn); |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
2568 |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
2569 add_binary_icmp (uintN (64), octave_value::op_lt, llvm::CmpInst::ICMP_ULT); |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
2570 add_binary_icmp (uintN (64), octave_value::op_le, llvm::CmpInst::ICMP_ULE); |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
2571 add_binary_icmp (uintN (64), octave_value::op_eq, llvm::CmpInst::ICMP_EQ); |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
2572 add_binary_icmp (uintN (64), octave_value::op_ge, llvm::CmpInst::ICMP_UGE); |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
2573 add_binary_icmp (uintN (64), octave_value::op_gt, llvm::CmpInst::ICMP_UGT); |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
2574 add_binary_icmp (uintN (64), octave_value::op_ne, llvm::CmpInst::ICMP_NE); |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
2575 |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
2576 // FIXME: saturation divide definition? interpreter convert uint to double, calculate and round. |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
2577 // divide is annoying because it might error |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
2578 // FIXME: Implement div |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
2579 |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
2580 // FIXME: Implement pow |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
2581 |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
2582 // now for unary uint8 operations |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
2583 // FIXME: Impelment not |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
2584 fn = create_external (JIT_FN (octave_jit_incr_uint64), uintN (64), uintN (64)); |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
2585 unary_ops[octave_value::op_incr].add_overload (fn); |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
2586 |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
2587 fn = create_external (JIT_FN (octave_jit_decr_uint64), uintN (64), uintN (64)); |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
2588 unary_ops[octave_value::op_decr].add_overload (fn); |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
2589 |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
2590 fn = create_internal ("octave_jit_uminus", uintN (64), uintN (64)); |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
2591 body = fn.new_block (); |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
2592 builder.SetInsertPoint (body); |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
2593 { |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
2594 llvm::Value *zero = llvm::ConstantInt::get (uint64__t, 0); |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
2595 |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
2596 fn.do_return (builder, zero); |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
2597 } |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
2598 unary_ops[octave_value::op_uminus].add_overload (fn); |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
2599 |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
2600 fn = create_identity (uintN (64)); |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
2601 unary_ops[octave_value::op_uplus].add_overload (fn); |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
2602 unary_ops[octave_value::op_transpose].add_overload (fn); |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
2603 unary_ops[octave_value::op_hermitian].add_overload (fn); |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
2604 |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2605 fn = create_internal ("octave_jit_*_scalar_complex", complex, scalar, |
15016 | 2606 complex); |
2607 jit_function mul_scalar_complex = fn; | |
2608 body = fn.new_block (); | |
2609 builder.SetInsertPoint (body); | |
2610 { | |
15583
0754bdfbc8fe
Correct multiplication complex multiplication with NaN in JIT
Max Brister <max@2bass.com>
parents:
15385
diff
changeset
|
2611 llvm::BasicBlock *complex_mul = fn.new_block ("complex_mul"); |
0754bdfbc8fe
Correct multiplication complex multiplication with NaN in JIT
Max Brister <max@2bass.com>
parents:
15385
diff
changeset
|
2612 llvm::BasicBlock *scalar_mul = fn.new_block ("scalar_mul"); |
0754bdfbc8fe
Correct multiplication complex multiplication with NaN in JIT
Max Brister <max@2bass.com>
parents:
15385
diff
changeset
|
2613 |
0754bdfbc8fe
Correct multiplication complex multiplication with NaN in JIT
Max Brister <max@2bass.com>
parents:
15385
diff
changeset
|
2614 llvm::Value *fzero = llvm::ConstantFP::get (scalar_t, 0); |
15016 | 2615 llvm::Value *lhs = fn.argument (builder, 0); |
2616 llvm::Value *rhs = fn.argument (builder, 1); | |
15583
0754bdfbc8fe
Correct multiplication complex multiplication with NaN in JIT
Max Brister <max@2bass.com>
parents:
15385
diff
changeset
|
2617 |
0754bdfbc8fe
Correct multiplication complex multiplication with NaN in JIT
Max Brister <max@2bass.com>
parents:
15385
diff
changeset
|
2618 llvm::Value *cmp = builder.CreateFCmpUEQ (complex_imag (rhs), fzero); |
0754bdfbc8fe
Correct multiplication complex multiplication with NaN in JIT
Max Brister <max@2bass.com>
parents:
15385
diff
changeset
|
2619 builder.CreateCondBr (cmp, scalar_mul, complex_mul); |
0754bdfbc8fe
Correct multiplication complex multiplication with NaN in JIT
Max Brister <max@2bass.com>
parents:
15385
diff
changeset
|
2620 |
0754bdfbc8fe
Correct multiplication complex multiplication with NaN in JIT
Max Brister <max@2bass.com>
parents:
15385
diff
changeset
|
2621 builder.SetInsertPoint (scalar_mul); |
0754bdfbc8fe
Correct multiplication complex multiplication with NaN in JIT
Max Brister <max@2bass.com>
parents:
15385
diff
changeset
|
2622 llvm::Value *temp = complex_real (rhs); |
0754bdfbc8fe
Correct multiplication complex multiplication with NaN in JIT
Max Brister <max@2bass.com>
parents:
15385
diff
changeset
|
2623 temp = builder.CreateFMul (lhs, temp); |
0754bdfbc8fe
Correct multiplication complex multiplication with NaN in JIT
Max Brister <max@2bass.com>
parents:
15385
diff
changeset
|
2624 fn.do_return (builder, complex_new (temp, fzero), false); |
0754bdfbc8fe
Correct multiplication complex multiplication with NaN in JIT
Max Brister <max@2bass.com>
parents:
15385
diff
changeset
|
2625 |
0754bdfbc8fe
Correct multiplication complex multiplication with NaN in JIT
Max Brister <max@2bass.com>
parents:
15385
diff
changeset
|
2626 |
0754bdfbc8fe
Correct multiplication complex multiplication with NaN in JIT
Max Brister <max@2bass.com>
parents:
15385
diff
changeset
|
2627 builder.SetInsertPoint (complex_mul); |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2628 temp = complex_new (builder.CreateFMul (lhs, complex_real (rhs)), |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2629 builder.CreateFMul (lhs, complex_imag (rhs))); |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2630 fn.do_return (builder, temp); |
15016 | 2631 } |
2632 binary_ops[octave_value::op_mul].add_overload (fn); | |
2633 binary_ops[octave_value::op_el_mul].add_overload (fn); | |
2634 | |
2635 | |
2636 fn = mirror_binary (mul_scalar_complex); | |
2637 binary_ops[octave_value::op_mul].add_overload (fn); | |
2638 binary_ops[octave_value::op_el_mul].add_overload (fn); | |
2639 | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2640 fn = create_internal ("octave_jit_+_scalar_complex", complex, scalar, |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2641 complex); |
15016 | 2642 body = fn.new_block (); |
2643 builder.SetInsertPoint (body); | |
2644 { | |
2645 llvm::Value *lhs = fn.argument (builder, 0); | |
2646 llvm::Value *rhs = fn.argument (builder, 1); | |
2647 llvm::Value *real = builder.CreateFAdd (lhs, complex_real (rhs)); | |
2648 fn.do_return (builder, complex_real (rhs, real)); | |
2649 } | |
2650 binary_ops[octave_value::op_add].add_overload (fn); | |
2651 | |
2652 fn = mirror_binary (fn); | |
2653 binary_ops[octave_value::op_add].add_overload (fn); | |
2654 | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2655 fn = create_internal ("octave_jit_-_complex_scalar", complex, complex, |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2656 scalar); |
15016 | 2657 body = fn.new_block (); |
2658 builder.SetInsertPoint (body); | |
2659 { | |
2660 llvm::Value *lhs = fn.argument (builder, 0); | |
2661 llvm::Value *rhs = fn.argument (builder, 1); | |
2662 llvm::Value *real = builder.CreateFSub (complex_real (lhs), rhs); | |
2663 fn.do_return (builder, complex_real (lhs, real)); | |
2664 } | |
2665 binary_ops[octave_value::op_sub].add_overload (fn); | |
2666 | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2667 fn = create_internal ("octave_jit_-_scalar_complex", complex, scalar, |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2668 complex); |
15016 | 2669 body = fn.new_block (); |
2670 builder.SetInsertPoint (body); | |
2671 { | |
2672 llvm::Value *lhs = fn.argument (builder, 0); | |
2673 llvm::Value *rhs = fn.argument (builder, 1); | |
2674 llvm::Value *real = builder.CreateFSub (lhs, complex_real (rhs)); | |
2675 fn.do_return (builder, complex_real (rhs, real)); | |
2676 } | |
2677 binary_ops[octave_value::op_sub].add_overload (fn); | |
2678 | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2679 fn = create_external (JIT_FN (octave_jit_pow_scalar_complex), complex, scalar, |
15016 | 2680 complex); |
2681 binary_ops[octave_value::op_pow].add_overload (fn); | |
2682 binary_ops[octave_value::op_el_pow].add_overload (fn); | |
2683 | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2684 fn = create_external (JIT_FN (octave_jit_pow_complex_scalar), complex, |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2685 complex, scalar); |
15016 | 2686 binary_ops[octave_value::op_pow].add_overload (fn); |
2687 binary_ops[octave_value::op_el_pow].add_overload (fn); | |
2688 | |
2689 // now for binary index operators | |
2690 add_binary_op (index, octave_value::op_add, llvm::Instruction::Add); | |
2691 | |
2692 // and binary bool operators | |
2693 add_binary_op (boolean, octave_value::op_el_or, llvm::Instruction::Or); | |
2694 add_binary_op (boolean, octave_value::op_el_and, llvm::Instruction::And); | |
2695 | |
2696 // now for printing functions | |
2697 print_fn.stash_name ("print"); | |
15019
ae3670d4df29
Update the execution engine's global mapping for external functions
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
2698 add_print (any, reinterpret_cast<void *> (&octave_jit_print_any)); |
ae3670d4df29
Update the execution engine's global mapping for external functions
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
2699 add_print (scalar, reinterpret_cast<void *> (&octave_jit_print_scalar)); |
15016 | 2700 |
2701 // initialize for loop | |
2702 for_init_fn.stash_name ("for_init"); | |
2703 | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2704 fn = create_internal ("octave_jit_for_range_init", index, range); |
15016 | 2705 body = fn.new_block (); |
2706 builder.SetInsertPoint (body); | |
2707 { | |
2708 llvm::Value *zero = llvm::ConstantInt::get (index_t, 0); | |
2709 fn.do_return (builder, zero); | |
2710 } | |
2711 for_init_fn.add_overload (fn); | |
2712 | |
2713 // bounds check for for loop | |
2714 for_check_fn.stash_name ("for_check"); | |
2715 | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2716 fn = create_internal ("octave_jit_for_range_check", boolean, range, index); |
15016 | 2717 body = fn.new_block (); |
2718 builder.SetInsertPoint (body); | |
2719 { | |
2720 llvm::Value *nelem | |
2721 = builder.CreateExtractValue (fn.argument (builder, 0), 3); | |
2722 llvm::Value *idx = fn.argument (builder, 1); | |
2723 llvm::Value *ret = builder.CreateICmpULT (idx, nelem); | |
2724 fn.do_return (builder, ret); | |
2725 } | |
2726 for_check_fn.add_overload (fn); | |
2727 | |
2728 // index variabe for for loop | |
2729 for_index_fn.stash_name ("for_index"); | |
2730 | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2731 fn = create_internal ("octave_jit_for_range_idx", scalar, range, index); |
15016 | 2732 body = fn.new_block (); |
2733 builder.SetInsertPoint (body); | |
2734 { | |
2735 llvm::Value *idx = fn.argument (builder, 1); | |
2736 llvm::Value *didx = builder.CreateSIToFP (idx, scalar_t); | |
2737 llvm::Value *rng = fn.argument (builder, 0); | |
2738 llvm::Value *base = builder.CreateExtractValue (rng, 0); | |
2739 llvm::Value *inc = builder.CreateExtractValue (rng, 2); | |
2740 | |
2741 llvm::Value *ret = builder.CreateFMul (didx, inc); | |
2742 ret = builder.CreateFAdd (base, ret); | |
2743 fn.do_return (builder, ret); | |
2744 } | |
2745 for_index_fn.add_overload (fn); | |
2746 | |
2747 // logically true | |
2748 logically_true_fn.stash_name ("logically_true"); | |
2749 | |
2750 jit_function gripe_nantl | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2751 = create_external (JIT_FN (octave_jit_gripe_nan_to_logical_conversion), 0); |
15016 | 2752 gripe_nantl.mark_can_error (); |
2753 | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2754 fn = create_internal ("octave_jit_logically_true_scalar", boolean, scalar); |
15016 | 2755 fn.mark_can_error (); |
2756 | |
2757 body = fn.new_block (); | |
2758 builder.SetInsertPoint (body); | |
2759 { | |
2760 llvm::BasicBlock *error_block = fn.new_block ("error"); | |
2761 llvm::BasicBlock *normal_block = fn.new_block ("normal"); | |
2762 | |
2763 llvm::Value *check = builder.CreateFCmpUNE (fn.argument (builder, 0), | |
2764 fn.argument (builder, 0)); | |
2765 builder.CreateCondBr (check, error_block, normal_block); | |
2766 | |
2767 builder.SetInsertPoint (error_block); | |
2768 gripe_nantl.call (builder); | |
2769 builder.CreateBr (normal_block); | |
2770 builder.SetInsertPoint (normal_block); | |
2771 | |
2772 llvm::Value *zero = llvm::ConstantFP::get (scalar_t, 0); | |
2773 llvm::Value *ret = builder.CreateFCmpONE (fn.argument (builder, 0), zero); | |
2774 fn.do_return (builder, ret); | |
2775 } | |
2776 logically_true_fn.add_overload (fn); | |
2777 | |
2778 // logically_true boolean | |
2779 fn = create_identity (boolean); | |
2780 logically_true_fn.add_overload (fn); | |
2781 | |
2782 // make_range | |
2783 // FIXME: May be benificial to implement all in LLVM | |
2784 make_range_fn.stash_name ("make_range"); | |
2785 jit_function compute_nelem | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2786 = create_external (JIT_FN (octave_jit_compute_nelem), |
15016 | 2787 index, scalar, scalar, scalar); |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2788 |
15016 | 2789 |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2790 fn = create_internal ("octave_jit_make_range", range, scalar, scalar, scalar); |
15016 | 2791 body = fn.new_block (); |
2792 builder.SetInsertPoint (body); | |
2793 { | |
2794 llvm::Value *base = fn.argument (builder, 0); | |
2795 llvm::Value *limit = fn.argument (builder, 1); | |
2796 llvm::Value *inc = fn.argument (builder, 2); | |
2797 llvm::Value *nelem = compute_nelem.call (builder, base, limit, inc); | |
2798 | |
2799 llvm::Value *dzero = llvm::ConstantFP::get (scalar_t, 0); | |
2800 llvm::Value *izero = llvm::ConstantInt::get (index_t, 0); | |
2801 llvm::Value *rng = llvm::ConstantStruct::get (range_t, dzero, dzero, dzero, | |
2802 izero, NULL); | |
2803 rng = builder.CreateInsertValue (rng, base, 0); | |
2804 rng = builder.CreateInsertValue (rng, limit, 1); | |
2805 rng = builder.CreateInsertValue (rng, inc, 2); | |
2806 rng = builder.CreateInsertValue (rng, nelem, 3); | |
2807 fn.do_return (builder, rng); | |
2808 } | |
2809 make_range_fn.add_overload (fn); | |
2810 | |
2811 // paren_subsref | |
2812 jit_type *jit_int = intN (sizeof (int) * 8); | |
2813 llvm::Type *int_t = jit_int->to_llvm (); | |
2814 jit_function ginvalid_index | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2815 = create_external (JIT_FN (octave_jit_ginvalid_index), 0); |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2816 jit_function gindex_range = create_external (JIT_FN (octave_jit_gindex_range), |
15016 | 2817 0, jit_int, jit_int, index, |
2818 index); | |
2819 | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2820 fn = create_internal ("()subsref", scalar, matrix, scalar); |
15016 | 2821 fn.mark_can_error (); |
2822 | |
2823 body = fn.new_block (); | |
2824 builder.SetInsertPoint (body); | |
2825 { | |
18274
e243b705a726
Fix building JIT with 64-bit indexing (bug #41163).
Lasse Schuirmann <lasse@schuirmann.net>
parents:
17787
diff
changeset
|
2826 llvm::Value *one_idx = llvm::ConstantInt::get (index_t, 1); |
e243b705a726
Fix building JIT with 64-bit indexing (bug #41163).
Lasse Schuirmann <lasse@schuirmann.net>
parents:
17787
diff
changeset
|
2827 llvm::Value *one_int = llvm::ConstantInt::get (int_t, 1); |
15016 | 2828 |
2829 llvm::Value *undef = llvm::UndefValue::get (scalar_t); | |
2830 llvm::Value *mat = fn.argument (builder, 0); | |
2831 llvm::Value *idx = fn.argument (builder, 1); | |
2832 | |
2833 // convert index to scalar to integer, and check index >= 1 | |
2834 llvm::Value *int_idx = builder.CreateFPToSI (idx, index_t); | |
2835 llvm::Value *check_idx = builder.CreateSIToFP (int_idx, scalar_t); | |
2836 llvm::Value *cond0 = builder.CreateFCmpUNE (idx, check_idx); | |
18274
e243b705a726
Fix building JIT with 64-bit indexing (bug #41163).
Lasse Schuirmann <lasse@schuirmann.net>
parents:
17787
diff
changeset
|
2837 llvm::Value *cond1 = builder.CreateICmpSLT (int_idx, one_idx); |
15016 | 2838 llvm::Value *cond = builder.CreateOr (cond0, cond1); |
2839 | |
2840 llvm::BasicBlock *done = fn.new_block ("done"); | |
2841 llvm::BasicBlock *conv_error = fn.new_block ("conv_error", done); | |
2842 llvm::BasicBlock *normal = fn.new_block ("normal", done); | |
2843 builder.CreateCondBr (cond, conv_error, normal); | |
2844 | |
2845 builder.SetInsertPoint (conv_error); | |
2846 ginvalid_index.call (builder); | |
2847 builder.CreateBr (done); | |
2848 | |
2849 builder.SetInsertPoint (normal); | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2850 llvm::Value *len |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2851 = builder.CreateExtractValue (mat, llvm::ArrayRef<unsigned> (2)); |
15016 | 2852 cond = builder.CreateICmpSGT (int_idx, len); |
2853 | |
2854 | |
2855 llvm::BasicBlock *bounds_error = fn.new_block ("bounds_error", done); | |
2856 llvm::BasicBlock *success = fn.new_block ("success", done); | |
2857 builder.CreateCondBr (cond, bounds_error, success); | |
2858 | |
2859 builder.SetInsertPoint (bounds_error); | |
18274
e243b705a726
Fix building JIT with 64-bit indexing (bug #41163).
Lasse Schuirmann <lasse@schuirmann.net>
parents:
17787
diff
changeset
|
2860 gindex_range.call (builder, one_int, one_int, int_idx, len); |
15016 | 2861 builder.CreateBr (done); |
2862 | |
2863 builder.SetInsertPoint (success); | |
2864 llvm::Value *data = builder.CreateExtractValue (mat, | |
2865 llvm::ArrayRef<unsigned> (1)); | |
2866 llvm::Value *gep = builder.CreateInBoundsGEP (data, int_idx); | |
2867 llvm::Value *ret = builder.CreateLoad (gep); | |
2868 builder.CreateBr (done); | |
2869 | |
2870 builder.SetInsertPoint (done); | |
2871 | |
2872 llvm::PHINode *merge = llvm::PHINode::Create (scalar_t, 3); | |
2873 builder.Insert (merge); | |
2874 merge->addIncoming (undef, conv_error); | |
2875 merge->addIncoming (undef, bounds_error); | |
2876 merge->addIncoming (ret, success); | |
2877 fn.do_return (builder, merge); | |
2878 } | |
2879 paren_subsref_fn.add_overload (fn); | |
2880 | |
2881 // paren subsasgn | |
2882 paren_subsasgn_fn.stash_name ("()subsasgn"); | |
2883 | |
2884 jit_function resize_paren_subsasgn | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2885 = create_external (JIT_FN (octave_jit_paren_subsasgn_impl), matrix, matrix, |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2886 index, scalar); |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2887 |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2888 fn = create_internal ("octave_jit_paren_subsasgn", matrix, matrix, scalar, |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2889 scalar); |
15016 | 2890 fn.mark_can_error (); |
2891 body = fn.new_block (); | |
2892 builder.SetInsertPoint (body); | |
2893 { | |
18274
e243b705a726
Fix building JIT with 64-bit indexing (bug #41163).
Lasse Schuirmann <lasse@schuirmann.net>
parents:
17787
diff
changeset
|
2894 llvm::Value *one_idx = llvm::ConstantInt::get (index_t, 1); |
e243b705a726
Fix building JIT with 64-bit indexing (bug #41163).
Lasse Schuirmann <lasse@schuirmann.net>
parents:
17787
diff
changeset
|
2895 llvm::Value *one_int = llvm::ConstantInt::get (int_t, 1); |
15016 | 2896 |
2897 llvm::Value *mat = fn.argument (builder, 0); | |
2898 llvm::Value *idx = fn.argument (builder, 1); | |
2899 llvm::Value *value = fn.argument (builder, 2); | |
2900 | |
2901 llvm::Value *int_idx = builder.CreateFPToSI (idx, index_t); | |
2902 llvm::Value *check_idx = builder.CreateSIToFP (int_idx, scalar_t); | |
2903 llvm::Value *cond0 = builder.CreateFCmpUNE (idx, check_idx); | |
18274
e243b705a726
Fix building JIT with 64-bit indexing (bug #41163).
Lasse Schuirmann <lasse@schuirmann.net>
parents:
17787
diff
changeset
|
2904 llvm::Value *cond1 = builder.CreateICmpSLT (int_idx, one_idx); |
15016 | 2905 llvm::Value *cond = builder.CreateOr (cond0, cond1); |
2906 | |
2907 llvm::BasicBlock *done = fn.new_block ("done"); | |
2908 | |
2909 llvm::BasicBlock *conv_error = fn.new_block ("conv_error", done); | |
2910 llvm::BasicBlock *normal = fn.new_block ("normal", done); | |
2911 builder.CreateCondBr (cond, conv_error, normal); | |
2912 builder.SetInsertPoint (conv_error); | |
2913 ginvalid_index.call (builder); | |
2914 builder.CreateBr (done); | |
2915 | |
2916 builder.SetInsertPoint (normal); | |
15056
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15027
diff
changeset
|
2917 llvm::Value *len = builder.CreateExtractValue (mat, 2); |
15016 | 2918 cond0 = builder.CreateICmpSGT (int_idx, len); |
2919 | |
2920 llvm::Value *rcount = builder.CreateExtractValue (mat, 0); | |
2921 rcount = builder.CreateLoad (rcount); | |
18274
e243b705a726
Fix building JIT with 64-bit indexing (bug #41163).
Lasse Schuirmann <lasse@schuirmann.net>
parents:
17787
diff
changeset
|
2922 cond1 = builder.CreateICmpSGT (rcount, one_int); |
15016 | 2923 cond = builder.CreateOr (cond0, cond1); |
2924 | |
2925 llvm::BasicBlock *bounds_error = fn.new_block ("bounds_error", done); | |
2926 llvm::BasicBlock *success = fn.new_block ("success", done); | |
2927 builder.CreateCondBr (cond, bounds_error, success); | |
2928 | |
2929 // resize on out of bounds access | |
2930 builder.SetInsertPoint (bounds_error); | |
15027
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
2931 llvm::Value *resize_result = resize_paren_subsasgn.call (builder, mat, |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
2932 int_idx, value); |
15016 | 2933 builder.CreateBr (done); |
2934 | |
2935 builder.SetInsertPoint (success); | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2936 llvm::Value *data |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2937 = builder.CreateExtractValue (mat, llvm::ArrayRef<unsigned> (1)); |
15016 | 2938 llvm::Value *gep = builder.CreateInBoundsGEP (data, int_idx); |
2939 builder.CreateStore (value, gep); | |
2940 builder.CreateBr (done); | |
2941 | |
2942 builder.SetInsertPoint (done); | |
2943 | |
2944 llvm::PHINode *merge = llvm::PHINode::Create (matrix_t, 3); | |
2945 builder.Insert (merge); | |
2946 merge->addIncoming (mat, conv_error); | |
2947 merge->addIncoming (resize_result, bounds_error); | |
2948 merge->addIncoming (mat, success); | |
2949 fn.do_return (builder, merge); | |
2950 } | |
2951 paren_subsasgn_fn.add_overload (fn); | |
2952 | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2953 fn = create_external (JIT_FN (octave_jit_paren_subsasgn_matrix_range), matrix, |
15016 | 2954 matrix, range, scalar); |
2955 fn.mark_can_error (); | |
2956 paren_subsasgn_fn.add_overload (fn); | |
2957 | |
15102
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
2958 end1_fn.stash_name ("end1"); |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2959 fn = create_internal ("octave_jit_end1_matrix", scalar, matrix, index, index); |
15056
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15027
diff
changeset
|
2960 body = fn.new_block (); |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15027
diff
changeset
|
2961 builder.SetInsertPoint (body); |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15027
diff
changeset
|
2962 { |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15027
diff
changeset
|
2963 llvm::Value *mat = fn.argument (builder, 0); |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15027
diff
changeset
|
2964 llvm::Value *ret = builder.CreateExtractValue (mat, 2); |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15027
diff
changeset
|
2965 fn.do_return (builder, builder.CreateSIToFP (ret, scalar_t)); |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15027
diff
changeset
|
2966 } |
15102
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
2967 end1_fn.add_overload (fn); |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
2968 |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
2969 end_fn.stash_name ("end"); |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2970 fn = create_external (JIT_FN (octave_jit_end_matrix),scalar, matrix, index, |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2971 index); |
15056
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15027
diff
changeset
|
2972 end_fn.add_overload (fn); |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15027
diff
changeset
|
2973 |
15337
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
2974 // -------------------- create_undef -------------------- |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
2975 create_undef_fn.stash_name ("create_undef"); |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2976 fn = create_external (JIT_FN (octave_jit_create_undef), any); |
15337
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
2977 create_undef_fn.add_overload (fn); |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
2978 |
15016 | 2979 casts[any->type_id ()].stash_name ("(any)"); |
2980 casts[scalar->type_id ()].stash_name ("(scalar)"); | |
18554 | 2981 casts[single->type_id ()].stash_name ("(single)"); |
18557 | 2982 casts[intN (8)->type_id ()].stash_name ("(int8)"); |
18559 | 2983 casts[intN (16)->type_id ()].stash_name ("(int16)"); |
18560 | 2984 casts[intN (32)->type_id ()].stash_name ("(int32)"); |
18558
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2985 casts[intN (64)->type_id ()].stash_name ("(int64)"); |
18561 | 2986 casts[uintN (8)->type_id ()].stash_name ("(uint8)"); |
18555 | 2987 casts[uintN (16)->type_id ()].stash_name ("(uint16)"); |
18563 | 2988 casts[uintN (32)->type_id ()].stash_name ("(uint32)"); |
18562
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
2989 casts[uintN (64)->type_id ()].stash_name ("(uint64)"); |
15016 | 2990 casts[complex->type_id ()].stash_name ("(complex)"); |
2991 casts[matrix->type_id ()].stash_name ("(matrix)"); | |
15603 | 2992 casts[range->type_id ()].stash_name ("(range)"); |
15016 | 2993 |
2994 // cast any <- matrix | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2995 fn = create_external (JIT_FN (octave_jit_cast_any_matrix), any, matrix); |
15016 | 2996 casts[any->type_id ()].add_overload (fn); |
2997 | |
2998 // cast matrix <- any | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2999 fn = create_external (JIT_FN (octave_jit_cast_matrix_any), matrix, any); |
15016 | 3000 casts[matrix->type_id ()].add_overload (fn); |
3001 | |
15027
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
3002 // cast any <- range |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
3003 fn = create_external (JIT_FN (octave_jit_cast_any_range), any, range); |
15027
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
3004 casts[any->type_id ()].add_overload (fn); |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
3005 |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
3006 // cast range <- any |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
3007 fn = create_external (JIT_FN (octave_jit_cast_range_any), range, any); |
15027
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
3008 casts[range->type_id ()].add_overload (fn); |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
3009 |
15016 | 3010 // cast any <- scalar |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
3011 fn = create_external (JIT_FN (octave_jit_cast_any_scalar), any, scalar); |
15016 | 3012 casts[any->type_id ()].add_overload (fn); |
3013 | |
3014 // cast scalar <- any | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
3015 fn = create_external (JIT_FN (octave_jit_cast_scalar_any), scalar, any); |
15016 | 3016 casts[scalar->type_id ()].add_overload (fn); |
3017 | |
18554 | 3018 // cast any <- single |
3019 fn = create_external (JIT_FN (octave_jit_cast_any_single), any, single); | |
3020 casts[any->type_id ()].add_overload (fn); | |
3021 | |
3022 // cast single <- any | |
3023 fn = create_external (JIT_FN (octave_jit_cast_single_any), single, any); | |
3024 casts[single->type_id ()].add_overload (fn); | |
3025 | |
18557 | 3026 // cast any <- int8 |
3027 fn = create_external (JIT_FN (octave_jit_cast_any_int8), any, intN (8)); | |
3028 casts[any->type_id ()].add_overload (fn); | |
3029 | |
3030 // cast int8 <- any | |
3031 fn = create_external (JIT_FN (octave_jit_cast_int8_any), intN (8), any); | |
3032 casts[intN (8)->type_id ()].add_overload (fn); | |
3033 | |
18559 | 3034 // cast any <- int16 |
3035 fn = create_external (JIT_FN (octave_jit_cast_any_int16), any, intN (16)); | |
3036 casts[any->type_id ()].add_overload (fn); | |
3037 | |
3038 // cast int16 <- any | |
3039 fn = create_external (JIT_FN (octave_jit_cast_int16_any), intN (16), any); | |
3040 casts[intN (16)->type_id ()].add_overload (fn); | |
3041 | |
18560 | 3042 // cast any <- int32 |
3043 fn = create_external (JIT_FN (octave_jit_cast_any_int32), any, intN (32)); | |
3044 casts[any->type_id ()].add_overload (fn); | |
3045 | |
3046 // cast int32 <- any | |
3047 fn = create_external (JIT_FN (octave_jit_cast_int32_any), intN (32), any); | |
3048 casts[intN (32)->type_id ()].add_overload (fn); | |
3049 | |
18558
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
3050 // cast any <- int64 |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
3051 fn = create_external (JIT_FN (octave_jit_cast_any_int64), any, intN (64)); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
3052 casts[any->type_id ()].add_overload (fn); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
3053 |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
3054 // cast int64 <- any |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
3055 fn = create_external (JIT_FN (octave_jit_cast_int64_any), intN (64), any); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
3056 casts[intN (64)->type_id ()].add_overload (fn); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
3057 |
18561 | 3058 // cast any <- uint8 |
3059 fn = create_external (JIT_FN (octave_jit_cast_any_uint8), any, uintN (8)); | |
3060 casts[any->type_id ()].add_overload (fn); | |
3061 | |
3062 // cast uint8 <- any | |
3063 fn = create_external (JIT_FN (octave_jit_cast_uint8_any), uintN (8), any); | |
3064 casts[uintN (8)->type_id ()].add_overload (fn); | |
3065 | |
18555 | 3066 // cast any <- uint16 |
3067 fn = create_external (JIT_FN (octave_jit_cast_any_uint16), any, uintN (16)); | |
3068 casts[any->type_id ()].add_overload (fn); | |
3069 | |
3070 // cast uint16 <- any | |
3071 fn = create_external (JIT_FN (octave_jit_cast_uint16_any), uintN (16), any); | |
3072 casts[uintN (16)->type_id ()].add_overload (fn); | |
3073 | |
18563 | 3074 // cast any <- uint32 |
3075 fn = create_external (JIT_FN (octave_jit_cast_any_uint32), any, uintN (32)); | |
3076 casts[any->type_id ()].add_overload (fn); | |
3077 | |
3078 // cast uint32 <- any | |
3079 fn = create_external (JIT_FN (octave_jit_cast_uint32_any), uintN (32), any); | |
3080 casts[uintN (32)->type_id ()].add_overload (fn); | |
3081 | |
18562
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
3082 // cast any <- uint64 |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
3083 fn = create_external (JIT_FN (octave_jit_cast_any_uint64), any, uintN (64)); |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
3084 casts[any->type_id ()].add_overload (fn); |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
3085 |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
3086 // cast uint64 <- any |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
3087 fn = create_external (JIT_FN (octave_jit_cast_uint64_any), uintN (64), any); |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
3088 casts[uintN (64)->type_id ()].add_overload (fn); |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
3089 |
15016 | 3090 // cast any <- complex |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
3091 fn = create_external (JIT_FN (octave_jit_cast_any_complex), any, complex); |
15016 | 3092 casts[any->type_id ()].add_overload (fn); |
3093 | |
3094 // cast complex <- any | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
3095 fn = create_external (JIT_FN (octave_jit_cast_complex_any), complex, any); |
15016 | 3096 casts[complex->type_id ()].add_overload (fn); |
3097 | |
3098 // cast complex <- scalar | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
3099 fn = create_internal ("octave_jit_cast_complex_scalar", complex, scalar); |
15016 | 3100 body = fn.new_block (); |
3101 builder.SetInsertPoint (body); | |
3102 { | |
3103 llvm::Value *zero = llvm::ConstantFP::get (scalar_t, 0); | |
3104 fn.do_return (builder, complex_new (fn.argument (builder, 0), zero)); | |
3105 } | |
3106 casts[complex->type_id ()].add_overload (fn); | |
3107 | |
3108 // cast scalar <- complex | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
3109 fn = create_internal ("octave_jit_cast_scalar_complex", scalar, complex); |
15016 | 3110 body = fn.new_block (); |
3111 builder.SetInsertPoint (body); | |
3112 fn.do_return (builder, complex_real (fn.argument (builder, 0))); | |
3113 casts[scalar->type_id ()].add_overload (fn); | |
3114 | |
3115 // cast any <- any | |
3116 fn = create_identity (any); | |
3117 casts[any->type_id ()].add_overload (fn); | |
3118 | |
3119 // cast scalar <- scalar | |
3120 fn = create_identity (scalar); | |
3121 casts[scalar->type_id ()].add_overload (fn); | |
3122 | |
18554 | 3123 // cast single <- single |
3124 fn = create_identity (single); | |
3125 casts[single->type_id ()].add_overload (fn); | |
3126 | |
18557 | 3127 // cast int8 <- int8 |
3128 fn = create_identity (intN (8)); | |
3129 casts[intN (8)->type_id ()].add_overload (fn); | |
3130 | |
18559 | 3131 // cast int16 <- int16 |
3132 fn = create_identity (intN (16)); | |
3133 casts[intN (16)->type_id ()].add_overload (fn); | |
3134 | |
18560 | 3135 // cast int32 <- int32 |
3136 fn = create_identity (intN (32)); | |
3137 casts[intN (32)->type_id ()].add_overload (fn); | |
3138 | |
18558
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
3139 // cast int64 <- int64 |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
3140 fn = create_identity (intN (64)); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
3141 casts[intN (64)->type_id ()].add_overload (fn); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
3142 |
18561 | 3143 // cast uint8 <- uint8 |
3144 fn = create_identity (uintN (8)); | |
3145 casts[uintN (8)->type_id ()].add_overload (fn); | |
3146 | |
18555 | 3147 // cast uint16 <- uint16 |
3148 fn = create_identity (uintN (16)); | |
3149 casts[uintN (16)->type_id ()].add_overload (fn); | |
3150 | |
18563 | 3151 // cast uint32 <- uint32 |
3152 fn = create_identity (uintN (32)); | |
3153 casts[uintN (32)->type_id ()].add_overload (fn); | |
3154 | |
18562
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
3155 // cast uint64 <- uint64 |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
3156 fn = create_identity (uintN (64)); |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
3157 casts[uintN (64)->type_id ()].add_overload (fn); |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
3158 |
15016 | 3159 // cast complex <- complex |
3160 fn = create_identity (complex); | |
3161 casts[complex->type_id ()].add_overload (fn); | |
3162 | |
3163 // -------------------- builtin functions -------------------- | |
3164 add_builtin ("#unknown_function"); | |
3165 unknown_function = builtins["#unknown_function"]; | |
3166 | |
3167 add_builtin ("sin"); | |
3168 register_intrinsic ("sin", llvm::Intrinsic::sin, scalar, scalar); | |
3169 register_generic ("sin", matrix, matrix); | |
3170 | |
3171 add_builtin ("cos"); | |
3172 register_intrinsic ("cos", llvm::Intrinsic::cos, scalar, scalar); | |
3173 register_generic ("cos", matrix, matrix); | |
3174 | |
3175 add_builtin ("exp"); | |
18446
634d9989bf7b
Fix copy&paste typo when registering exp with JIT (bug #41560).
Rik <rik@octave.org>
parents:
18323
diff
changeset
|
3176 register_intrinsic ("exp", llvm::Intrinsic::exp, scalar, scalar); |
15016 | 3177 register_generic ("exp", matrix, matrix); |
3178 | |
15169
6242904370bd
Support balance, cond, det, norm, rand, magic, eye, and mod in JIT
Max Brister <max@2bass.com>
parents:
15148
diff
changeset
|
3179 add_builtin ("balance"); |
6242904370bd
Support balance, cond, det, norm, rand, magic, eye, and mod in JIT
Max Brister <max@2bass.com>
parents:
15148
diff
changeset
|
3180 register_generic ("balance", matrix, matrix); |
6242904370bd
Support balance, cond, det, norm, rand, magic, eye, and mod in JIT
Max Brister <max@2bass.com>
parents:
15148
diff
changeset
|
3181 |
6242904370bd
Support balance, cond, det, norm, rand, magic, eye, and mod in JIT
Max Brister <max@2bass.com>
parents:
15148
diff
changeset
|
3182 add_builtin ("cond"); |
6242904370bd
Support balance, cond, det, norm, rand, magic, eye, and mod in JIT
Max Brister <max@2bass.com>
parents:
15148
diff
changeset
|
3183 register_generic ("cond", scalar, matrix); |
6242904370bd
Support balance, cond, det, norm, rand, magic, eye, and mod in JIT
Max Brister <max@2bass.com>
parents:
15148
diff
changeset
|
3184 |
6242904370bd
Support balance, cond, det, norm, rand, magic, eye, and mod in JIT
Max Brister <max@2bass.com>
parents:
15148
diff
changeset
|
3185 add_builtin ("det"); |
6242904370bd
Support balance, cond, det, norm, rand, magic, eye, and mod in JIT
Max Brister <max@2bass.com>
parents:
15148
diff
changeset
|
3186 register_generic ("det", scalar, matrix); |
6242904370bd
Support balance, cond, det, norm, rand, magic, eye, and mod in JIT
Max Brister <max@2bass.com>
parents:
15148
diff
changeset
|
3187 |
6242904370bd
Support balance, cond, det, norm, rand, magic, eye, and mod in JIT
Max Brister <max@2bass.com>
parents:
15148
diff
changeset
|
3188 add_builtin ("norm"); |
6242904370bd
Support balance, cond, det, norm, rand, magic, eye, and mod in JIT
Max Brister <max@2bass.com>
parents:
15148
diff
changeset
|
3189 register_generic ("norm", scalar, matrix); |
6242904370bd
Support balance, cond, det, norm, rand, magic, eye, and mod in JIT
Max Brister <max@2bass.com>
parents:
15148
diff
changeset
|
3190 |
6242904370bd
Support balance, cond, det, norm, rand, magic, eye, and mod in JIT
Max Brister <max@2bass.com>
parents:
15148
diff
changeset
|
3191 add_builtin ("rand"); |
6242904370bd
Support balance, cond, det, norm, rand, magic, eye, and mod in JIT
Max Brister <max@2bass.com>
parents:
15148
diff
changeset
|
3192 register_generic ("rand", matrix, scalar); |
6242904370bd
Support balance, cond, det, norm, rand, magic, eye, and mod in JIT
Max Brister <max@2bass.com>
parents:
15148
diff
changeset
|
3193 register_generic ("rand", matrix, std::vector<jit_type *> (2, scalar)); |
6242904370bd
Support balance, cond, det, norm, rand, magic, eye, and mod in JIT
Max Brister <max@2bass.com>
parents:
15148
diff
changeset
|
3194 |
6242904370bd
Support balance, cond, det, norm, rand, magic, eye, and mod in JIT
Max Brister <max@2bass.com>
parents:
15148
diff
changeset
|
3195 add_builtin ("magic"); |
6242904370bd
Support balance, cond, det, norm, rand, magic, eye, and mod in JIT
Max Brister <max@2bass.com>
parents:
15148
diff
changeset
|
3196 register_generic ("magic", matrix, scalar); |
6242904370bd
Support balance, cond, det, norm, rand, magic, eye, and mod in JIT
Max Brister <max@2bass.com>
parents:
15148
diff
changeset
|
3197 register_generic ("magic", matrix, std::vector<jit_type *> (2, scalar)); |
6242904370bd
Support balance, cond, det, norm, rand, magic, eye, and mod in JIT
Max Brister <max@2bass.com>
parents:
15148
diff
changeset
|
3198 |
6242904370bd
Support balance, cond, det, norm, rand, magic, eye, and mod in JIT
Max Brister <max@2bass.com>
parents:
15148
diff
changeset
|
3199 add_builtin ("eye"); |
6242904370bd
Support balance, cond, det, norm, rand, magic, eye, and mod in JIT
Max Brister <max@2bass.com>
parents:
15148
diff
changeset
|
3200 register_generic ("eye", matrix, scalar); |
6242904370bd
Support balance, cond, det, norm, rand, magic, eye, and mod in JIT
Max Brister <max@2bass.com>
parents:
15148
diff
changeset
|
3201 register_generic ("eye", matrix, std::vector<jit_type *> (2, scalar)); |
6242904370bd
Support balance, cond, det, norm, rand, magic, eye, and mod in JIT
Max Brister <max@2bass.com>
parents:
15148
diff
changeset
|
3202 |
6242904370bd
Support balance, cond, det, norm, rand, magic, eye, and mod in JIT
Max Brister <max@2bass.com>
parents:
15148
diff
changeset
|
3203 add_builtin ("mod"); |
6242904370bd
Support balance, cond, det, norm, rand, magic, eye, and mod in JIT
Max Brister <max@2bass.com>
parents:
15148
diff
changeset
|
3204 register_generic ("mod", scalar, std::vector<jit_type *> (2, scalar)); |
6242904370bd
Support balance, cond, det, norm, rand, magic, eye, and mod in JIT
Max Brister <max@2bass.com>
parents:
15148
diff
changeset
|
3205 |
15016 | 3206 casts.resize (next_id + 1); |
3207 jit_function any_id = create_identity (any); | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
3208 jit_function grab_any = create_external (JIT_FN (octave_jit_grab_any), |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
3209 any, any); |
15016 | 3210 jit_function release_any = get_release (any); |
3211 std::vector<jit_type *> args; | |
3212 args.resize (1); | |
3213 | |
3214 for (std::map<std::string, jit_type *>::iterator iter = builtins.begin (); | |
3215 iter != builtins.end (); ++iter) | |
3216 { | |
3217 jit_type *btype = iter->second; | |
3218 args[0] = btype; | |
3219 | |
15334
8125773322d4
Error on undefined an unused variables in JIT
Max Brister <max@2bass.com>
parents:
15311
diff
changeset
|
3220 grab_fn.add_overload (jit_function (grab_any, btype, args)); |
15016 | 3221 release_fn.add_overload (jit_function (release_any, 0, args)); |
3222 casts[any->type_id ()].add_overload (jit_function (any_id, any, args)); | |
3223 | |
3224 args[0] = any; | |
3225 casts[btype->type_id ()].add_overload (jit_function (any_id, btype, | |
3226 args)); | |
3227 } | |
3228 } | |
3229 | |
15102
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
3230 const jit_function& |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
3231 jit_typeinfo::do_end (jit_value *value, jit_value *idx, jit_value *count) |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
3232 { |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
3233 jit_const_index *ccount = dynamic_cast<jit_const_index *> (count); |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
3234 if (ccount && ccount->value () == 1) |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
3235 return end1_fn.overload (value->type (), idx->type (), count->type ()); |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
3236 |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
3237 return end_fn.overload (value->type (), idx->type (), count->type ()); |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
3238 } |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
3239 |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
3240 jit_type* |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
3241 jit_typeinfo::new_type (const std::string& name, jit_type *parent, |
15124
0464e3ceb85b
Skip functions when resolving end context in JIT
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
3242 llvm::Type *llvm_type, bool skip_paren) |
15102
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
3243 { |
15124
0464e3ceb85b
Skip functions when resolving end context in JIT
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
3244 jit_type *ret = new jit_type (name, parent, llvm_type, skip_paren, next_id++); |
15102
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
3245 id_to_type.push_back (ret); |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
3246 return ret; |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
3247 } |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
3248 |
15016 | 3249 void |
15019
ae3670d4df29
Update the execution engine's global mapping for external functions
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
3250 jit_typeinfo::add_print (jit_type *ty, void *fptr) |
15016 | 3251 { |
3252 std::stringstream name; | |
3253 name << "octave_jit_print_" << ty->name (); | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3254 jit_function fn = create_external (engine, fptr, name.str (), |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3255 0, intN (8), ty); |
15016 | 3256 print_fn.add_overload (fn); |
3257 } | |
3258 | |
3259 // FIXME: cp between add_binary_op, add_binary_icmp, and add_binary_fcmp | |
3260 void | |
3261 jit_typeinfo::add_binary_op (jit_type *ty, int op, int llvm_op) | |
3262 { | |
3263 std::stringstream fname; | |
3264 octave_value::binary_op ov_op = static_cast<octave_value::binary_op>(op); | |
3265 fname << "octave_jit_" << octave_value::binary_op_as_string (ov_op) | |
3266 << "_" << ty->name (); | |
3267 | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
3268 jit_function fn = create_internal (fname.str (), ty, ty, ty); |
15016 | 3269 llvm::BasicBlock *block = fn.new_block (); |
3270 builder.SetInsertPoint (block); | |
3271 llvm::Instruction::BinaryOps temp | |
3272 = static_cast<llvm::Instruction::BinaryOps>(llvm_op); | |
3273 | |
3274 llvm::Value *ret = builder.CreateBinOp (temp, fn.argument (builder, 0), | |
3275 fn.argument (builder, 1)); | |
3276 fn.do_return (builder, ret); | |
3277 binary_ops[op].add_overload (fn); | |
3278 } | |
3279 | |
3280 void | |
3281 jit_typeinfo::add_binary_icmp (jit_type *ty, int op, int llvm_op) | |
3282 { | |
3283 std::stringstream fname; | |
3284 octave_value::binary_op ov_op = static_cast<octave_value::binary_op>(op); | |
3285 fname << "octave_jit" << octave_value::binary_op_as_string (ov_op) | |
3286 << "_" << ty->name (); | |
3287 | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
3288 jit_function fn = create_internal (fname.str (), boolean, ty, ty); |
15016 | 3289 llvm::BasicBlock *block = fn.new_block (); |
3290 builder.SetInsertPoint (block); | |
3291 llvm::CmpInst::Predicate temp | |
3292 = static_cast<llvm::CmpInst::Predicate>(llvm_op); | |
3293 llvm::Value *ret = builder.CreateICmp (temp, fn.argument (builder, 0), | |
3294 fn.argument (builder, 1)); | |
3295 fn.do_return (builder, ret); | |
3296 binary_ops[op].add_overload (fn); | |
3297 } | |
3298 | |
3299 void | |
3300 jit_typeinfo::add_binary_fcmp (jit_type *ty, int op, int llvm_op) | |
3301 { | |
3302 std::stringstream fname; | |
3303 octave_value::binary_op ov_op = static_cast<octave_value::binary_op>(op); | |
3304 fname << "octave_jit" << octave_value::binary_op_as_string (ov_op) | |
3305 << "_" << ty->name (); | |
3306 | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
3307 jit_function fn = create_internal (fname.str (), boolean, ty, ty); |
15016 | 3308 llvm::BasicBlock *block = fn.new_block (); |
3309 builder.SetInsertPoint (block); | |
3310 llvm::CmpInst::Predicate temp | |
3311 = static_cast<llvm::CmpInst::Predicate>(llvm_op); | |
3312 llvm::Value *ret = builder.CreateFCmp (temp, fn.argument (builder, 0), | |
3313 fn.argument (builder, 1)); | |
3314 fn.do_return (builder, ret); | |
3315 binary_ops[op].add_overload (fn); | |
3316 } | |
3317 | |
3318 jit_function | |
3319 jit_typeinfo::create_function (jit_convention::type cc, const llvm::Twine& name, | |
3320 jit_type *ret, | |
3321 const std::vector<jit_type *>& args) | |
3322 { | |
3323 jit_function result (module, cc, name, ret, args); | |
3324 return result; | |
3325 } | |
3326 | |
3327 jit_function | |
3328 jit_typeinfo::create_identity (jit_type *type) | |
3329 { | |
3330 size_t id = type->type_id (); | |
3331 if (id >= identities.size ()) | |
3332 identities.resize (id + 1); | |
3333 | |
3334 if (! identities[id].valid ()) | |
3335 { | |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
3336 std::stringstream name; |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
3337 name << "id_" << type->name (); |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
3338 |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
3339 jit_function fn = create_internal (name.str (), type, type); |
15016 | 3340 llvm::BasicBlock *body = fn.new_block (); |
3341 builder.SetInsertPoint (body); | |
3342 fn.do_return (builder, fn.argument (builder, 0)); | |
3343 return identities[id] = fn; | |
3344 } | |
3345 | |
3346 return identities[id]; | |
3347 } | |
3348 | |
3349 llvm::Value * | |
15019
ae3670d4df29
Update the execution engine's global mapping for external functions
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
3350 jit_typeinfo::do_insert_error_check (llvm::IRBuilderD& abuilder) |
15016 | 3351 { |
15019
ae3670d4df29
Update the execution engine's global mapping for external functions
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
3352 return abuilder.CreateLoad (lerror_state); |
15016 | 3353 } |
3354 | |
15603 | 3355 llvm::Value * |
3356 jit_typeinfo::do_insert_interrupt_check (llvm::IRBuilderD& abuilder) | |
3357 { | |
3358 llvm::LoadInst *val = abuilder.CreateLoad (loctave_interrupt_state); | |
3359 val->setVolatile (true); | |
3360 return abuilder.CreateICmpSGT (val, abuilder.getInt32 (0)); | |
3361 } | |
3362 | |
15016 | 3363 void |
3364 jit_typeinfo::add_builtin (const std::string& name) | |
3365 { | |
15124
0464e3ceb85b
Skip functions when resolving end context in JIT
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
3366 jit_type *btype = new_type (name, any, any->to_llvm (), true); |
15016 | 3367 builtins[name] = btype; |
3368 | |
3369 octave_builtin *ov_builtin = find_builtin (name); | |
3370 if (ov_builtin) | |
3371 ov_builtin->stash_jit (*btype); | |
3372 } | |
3373 | |
3374 void | |
3375 jit_typeinfo::register_intrinsic (const std::string& name, size_t iid, | |
3376 jit_type *result, | |
3377 const std::vector<jit_type *>& args) | |
3378 { | |
3379 jit_type *builtin_type = builtins[name]; | |
3380 size_t nargs = args.size (); | |
3381 llvm::SmallVector<llvm::Type *, 5> llvm_args (nargs); | |
3382 for (size_t i = 0; i < nargs; ++i) | |
3383 llvm_args[i] = args[i]->to_llvm (); | |
3384 | |
3385 llvm::Intrinsic::ID id = static_cast<llvm::Intrinsic::ID> (iid); | |
3386 llvm::Function *ifun = llvm::Intrinsic::getDeclaration (module, id, | |
3387 llvm_args); | |
3388 std::stringstream fn_name; | |
3389 fn_name << "octave_jit_" << name; | |
3390 | |
3391 std::vector<jit_type *> args1 (nargs + 1); | |
3392 args1[0] = builtin_type; | |
3393 std::copy (args.begin (), args.end (), args1.begin () + 1); | |
3394 | |
3395 // The first argument will be the Octave function, but we already know that | |
3396 // the function call is the equivalent of the intrinsic, so we ignore it and | |
3397 // call the intrinsic with the remaining arguments. | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
3398 jit_function fn = create_internal (fn_name.str (), result, args1); |
15016 | 3399 llvm::BasicBlock *body = fn.new_block (); |
3400 builder.SetInsertPoint (body); | |
3401 | |
3402 llvm::SmallVector<llvm::Value *, 5> fargs (nargs); | |
3403 for (size_t i = 0; i < nargs; ++i) | |
3404 fargs[i] = fn.argument (builder, i + 1); | |
3405 | |
3406 llvm::Value *ret = builder.CreateCall (ifun, fargs); | |
3407 fn.do_return (builder, ret); | |
3408 paren_subsref_fn.add_overload (fn); | |
3409 } | |
3410 | |
3411 octave_builtin * | |
3412 jit_typeinfo::find_builtin (const std::string& name) | |
3413 { | |
3414 // FIXME: Finalize what we want to store in octave_builtin, then add functions | |
3415 // to access these values in octave_value | |
3416 octave_value ov_builtin = symbol_table::find (name); | |
3417 return dynamic_cast<octave_builtin *> (ov_builtin.internal_rep ()); | |
3418 } | |
3419 | |
3420 void | |
15135
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
3421 jit_typeinfo::register_generic (const std::string& name, jit_type *result, |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
3422 const std::vector<jit_type *>& args) |
15016 | 3423 { |
15135
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
3424 octave_builtin *builtin = find_builtin (name); |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
3425 if (! builtin) |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
3426 return; |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
3427 |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
3428 std::vector<jit_type *> fn_args (args.size () + 1); |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
3429 fn_args[0] = builtins[name]; |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
3430 std::copy (args.begin (), args.end (), fn_args.begin () + 1); |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
3431 jit_function fn = create_internal (name, result, fn_args); |
15136
eeaaac7c86b6
jit-typeinfo.cc (jit_typeinfo::register_generic): Mark can error
Max Brister <max@2bass.com>
parents:
15135
diff
changeset
|
3432 fn.mark_can_error (); |
15135
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
3433 llvm::BasicBlock *block = fn.new_block (); |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
3434 builder.SetInsertPoint (block); |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
3435 llvm::Type *any_t = any->to_llvm (); |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
3436 llvm::ArrayType *array_t = llvm::ArrayType::get (any_t, args.size ()); |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
3437 llvm::Value *array = llvm::UndefValue::get (array_t); |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
3438 for (size_t i = 0; i < args.size (); ++i) |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
3439 { |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
3440 llvm::Value *arg = fn.argument (builder, i + 1); |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
3441 jit_function agrab = get_grab (args[i]); |
15169
6242904370bd
Support balance, cond, det, norm, rand, magic, eye, and mod in JIT
Max Brister <max@2bass.com>
parents:
15148
diff
changeset
|
3442 if (agrab.valid ()) |
6242904370bd
Support balance, cond, det, norm, rand, magic, eye, and mod in JIT
Max Brister <max@2bass.com>
parents:
15148
diff
changeset
|
3443 arg = agrab.call (builder, arg); |
15135
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
3444 jit_function acast = cast (any, args[i]); |
15169
6242904370bd
Support balance, cond, det, norm, rand, magic, eye, and mod in JIT
Max Brister <max@2bass.com>
parents:
15148
diff
changeset
|
3445 array = builder.CreateInsertValue (array, acast.call (builder, arg), i); |
15135
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
3446 } |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
3447 |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
3448 llvm::Value *array_mem = builder.CreateAlloca (array_t); |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
3449 builder.CreateStore (array, array_mem); |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
3450 array = builder.CreateBitCast (array_mem, any_t->getPointerTo ()); |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
3451 |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
3452 jit_type *jintTy = intN (sizeof (octave_builtin::fcn) * 8); |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
3453 llvm::Type *intTy = jintTy->to_llvm (); |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
3454 size_t fcn_int = reinterpret_cast<size_t> (builtin->function ()); |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
3455 llvm::Value *fcn = llvm::ConstantInt::get (intTy, fcn_int); |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
3456 llvm::Value *nargin = llvm::ConstantInt::get (intTy, args.size ()); |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
3457 size_t result_int = reinterpret_cast<size_t> (result); |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
3458 llvm::Value *res_llvm = llvm::ConstantInt::get (intTy, result_int); |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
3459 llvm::Value *ret = any_call.call (builder, fcn, nargin, array, res_llvm); |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
3460 |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
3461 jit_function cast_result = cast (result, any); |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
3462 fn.do_return (builder, cast_result.call (builder, ret)); |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
3463 paren_subsref_fn.add_overload (fn); |
15016 | 3464 } |
3465 | |
3466 jit_function | |
3467 jit_typeinfo::mirror_binary (const jit_function& fn) | |
3468 { | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
3469 jit_function ret = create_internal (fn.name () + "_reverse", |
15016 | 3470 fn.result (), fn.argument_type (1), |
3471 fn.argument_type (0)); | |
3472 if (fn.can_error ()) | |
3473 ret.mark_can_error (); | |
3474 | |
3475 llvm::BasicBlock *body = ret.new_block (); | |
3476 builder.SetInsertPoint (body); | |
3477 llvm::Value *result = fn.call (builder, ret.argument (builder, 1), | |
3478 ret.argument (builder, 0)); | |
3479 if (ret.result ()) | |
3480 ret.do_return (builder, result); | |
3481 else | |
3482 ret.do_return (builder); | |
3483 | |
3484 return ret; | |
3485 } | |
3486 | |
18564
5a5a67799338
jit compiler: Use seperate function for division operation
Stefan Mahr <dac922@gmx.de>
parents:
18563
diff
changeset
|
3487 jit_function |
5a5a67799338
jit compiler: Use seperate function for division operation
Stefan Mahr <dac922@gmx.de>
parents:
18563
diff
changeset
|
3488 jit_typeinfo::divide_float (jit_type* ty) |
5a5a67799338
jit compiler: Use seperate function for division operation
Stefan Mahr <dac922@gmx.de>
parents:
18563
diff
changeset
|
3489 { |
5a5a67799338
jit compiler: Use seperate function for division operation
Stefan Mahr <dac922@gmx.de>
parents:
18563
diff
changeset
|
3490 jit_function gripe_div0 = create_external (engine, &gripe_divide_by_zero, "gripe_divide_by_zero", 0); |
5a5a67799338
jit compiler: Use seperate function for division operation
Stefan Mahr <dac922@gmx.de>
parents:
18563
diff
changeset
|
3491 gripe_div0.mark_can_error (); |
5a5a67799338
jit compiler: Use seperate function for division operation
Stefan Mahr <dac922@gmx.de>
parents:
18563
diff
changeset
|
3492 |
5a5a67799338
jit compiler: Use seperate function for division operation
Stefan Mahr <dac922@gmx.de>
parents:
18563
diff
changeset
|
3493 // divide is annoying because it might error |
5a5a67799338
jit compiler: Use seperate function for division operation
Stefan Mahr <dac922@gmx.de>
parents:
18563
diff
changeset
|
3494 std::stringstream fname; |
5a5a67799338
jit compiler: Use seperate function for division operation
Stefan Mahr <dac922@gmx.de>
parents:
18563
diff
changeset
|
3495 fname << "octave_jit_divide_" << ty->name (); |
5a5a67799338
jit compiler: Use seperate function for division operation
Stefan Mahr <dac922@gmx.de>
parents:
18563
diff
changeset
|
3496 jit_function fn = create_internal (fname.str (), ty, ty, ty); |
5a5a67799338
jit compiler: Use seperate function for division operation
Stefan Mahr <dac922@gmx.de>
parents:
18563
diff
changeset
|
3497 fn.mark_can_error (); |
5a5a67799338
jit compiler: Use seperate function for division operation
Stefan Mahr <dac922@gmx.de>
parents:
18563
diff
changeset
|
3498 |
5a5a67799338
jit compiler: Use seperate function for division operation
Stefan Mahr <dac922@gmx.de>
parents:
18563
diff
changeset
|
3499 llvm::BasicBlock *body = fn.new_block (); |
5a5a67799338
jit compiler: Use seperate function for division operation
Stefan Mahr <dac922@gmx.de>
parents:
18563
diff
changeset
|
3500 builder.SetInsertPoint (body); |
5a5a67799338
jit compiler: Use seperate function for division operation
Stefan Mahr <dac922@gmx.de>
parents:
18563
diff
changeset
|
3501 { |
5a5a67799338
jit compiler: Use seperate function for division operation
Stefan Mahr <dac922@gmx.de>
parents:
18563
diff
changeset
|
3502 llvm::BasicBlock *warn_block = fn.new_block ("warn"); |
5a5a67799338
jit compiler: Use seperate function for division operation
Stefan Mahr <dac922@gmx.de>
parents:
18563
diff
changeset
|
3503 llvm::BasicBlock *normal_block = fn.new_block ("normal"); |
5a5a67799338
jit compiler: Use seperate function for division operation
Stefan Mahr <dac922@gmx.de>
parents:
18563
diff
changeset
|
3504 |
5a5a67799338
jit compiler: Use seperate function for division operation
Stefan Mahr <dac922@gmx.de>
parents:
18563
diff
changeset
|
3505 llvm::Value *zero = llvm::ConstantFP::get (ty->to_llvm(), 0); |
5a5a67799338
jit compiler: Use seperate function for division operation
Stefan Mahr <dac922@gmx.de>
parents:
18563
diff
changeset
|
3506 llvm::Value *check = builder.CreateFCmpUEQ (zero, fn.argument (builder, 1)); |
5a5a67799338
jit compiler: Use seperate function for division operation
Stefan Mahr <dac922@gmx.de>
parents:
18563
diff
changeset
|
3507 builder.CreateCondBr (check, warn_block, normal_block); |
5a5a67799338
jit compiler: Use seperate function for division operation
Stefan Mahr <dac922@gmx.de>
parents:
18563
diff
changeset
|
3508 |
5a5a67799338
jit compiler: Use seperate function for division operation
Stefan Mahr <dac922@gmx.de>
parents:
18563
diff
changeset
|
3509 builder.SetInsertPoint (warn_block); |
5a5a67799338
jit compiler: Use seperate function for division operation
Stefan Mahr <dac922@gmx.de>
parents:
18563
diff
changeset
|
3510 gripe_div0.call (builder); |
5a5a67799338
jit compiler: Use seperate function for division operation
Stefan Mahr <dac922@gmx.de>
parents:
18563
diff
changeset
|
3511 builder.CreateBr (normal_block); |
5a5a67799338
jit compiler: Use seperate function for division operation
Stefan Mahr <dac922@gmx.de>
parents:
18563
diff
changeset
|
3512 |
5a5a67799338
jit compiler: Use seperate function for division operation
Stefan Mahr <dac922@gmx.de>
parents:
18563
diff
changeset
|
3513 builder.SetInsertPoint (normal_block); |
5a5a67799338
jit compiler: Use seperate function for division operation
Stefan Mahr <dac922@gmx.de>
parents:
18563
diff
changeset
|
3514 llvm::Value *ret = builder.CreateFDiv (fn.argument (builder, 0), |
5a5a67799338
jit compiler: Use seperate function for division operation
Stefan Mahr <dac922@gmx.de>
parents:
18563
diff
changeset
|
3515 fn.argument (builder, 1)); |
5a5a67799338
jit compiler: Use seperate function for division operation
Stefan Mahr <dac922@gmx.de>
parents:
18563
diff
changeset
|
3516 fn.do_return (builder, ret); |
5a5a67799338
jit compiler: Use seperate function for division operation
Stefan Mahr <dac922@gmx.de>
parents:
18563
diff
changeset
|
3517 } |
5a5a67799338
jit compiler: Use seperate function for division operation
Stefan Mahr <dac922@gmx.de>
parents:
18563
diff
changeset
|
3518 return fn; |
5a5a67799338
jit compiler: Use seperate function for division operation
Stefan Mahr <dac922@gmx.de>
parents:
18563
diff
changeset
|
3519 } |
5a5a67799338
jit compiler: Use seperate function for division operation
Stefan Mahr <dac922@gmx.de>
parents:
18563
diff
changeset
|
3520 |
15016 | 3521 llvm::Value * |
3522 jit_typeinfo::pack_complex (llvm::IRBuilderD& bld, llvm::Value *cplx) | |
3523 { | |
3524 llvm::Type *complex_ret = instance->complex_ret; | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
3525 llvm::Value *real = bld.CreateExtractValue (cplx, 0); |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
3526 llvm::Value *imag = bld.CreateExtractValue (cplx, 1); |
15016 | 3527 llvm::Value *ret = llvm::UndefValue::get (complex_ret); |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
3528 |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
3529 unsigned int re_idx[] = {0, 0}; |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
3530 unsigned int im_idx[] = {0, 1}; |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
3531 ret = bld.CreateInsertValue (ret, real, re_idx); |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
3532 return bld.CreateInsertValue (ret, imag, im_idx); |
15016 | 3533 } |
3534 | |
3535 llvm::Value * | |
3536 jit_typeinfo::unpack_complex (llvm::IRBuilderD& bld, llvm::Value *result) | |
3537 { | |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
3538 unsigned int re_idx[] = {0, 0}; |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
3539 unsigned int im_idx[] = {0, 1}; |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
3540 |
15016 | 3541 llvm::Type *complex_t = get_complex ()->to_llvm (); |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
3542 llvm::Value *real = bld.CreateExtractValue (result, re_idx); |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
3543 llvm::Value *imag = bld.CreateExtractValue (result, im_idx); |
15016 | 3544 llvm::Value *ret = llvm::UndefValue::get (complex_t); |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
3545 |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
3546 ret = bld.CreateInsertValue (ret, real, 0); |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
3547 return bld.CreateInsertValue (ret, imag, 1); |
15016 | 3548 } |
3549 | |
3550 llvm::Value * | |
3551 jit_typeinfo::complex_real (llvm::Value *cx) | |
3552 { | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
3553 return builder.CreateExtractValue (cx, 0); |
15016 | 3554 } |
3555 | |
3556 llvm::Value * | |
3557 jit_typeinfo::complex_real (llvm::Value *cx, llvm::Value *real) | |
3558 { | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
3559 return builder.CreateInsertValue (cx, real, 0); |
15016 | 3560 } |
3561 | |
3562 llvm::Value * | |
3563 jit_typeinfo::complex_imag (llvm::Value *cx) | |
3564 { | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
3565 return builder.CreateExtractValue (cx, 1); |
15016 | 3566 } |
3567 | |
3568 llvm::Value * | |
3569 jit_typeinfo::complex_imag (llvm::Value *cx, llvm::Value *imag) | |
3570 { | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
3571 return builder.CreateInsertValue (cx, imag, 1); |
15016 | 3572 } |
3573 | |
3574 llvm::Value * | |
3575 jit_typeinfo::complex_new (llvm::Value *real, llvm::Value *imag) | |
3576 { | |
3577 llvm::Value *ret = llvm::UndefValue::get (complex->to_llvm ()); | |
3578 ret = complex_real (ret, real); | |
3579 return complex_imag (ret, imag); | |
3580 } | |
3581 | |
3582 void | |
3583 jit_typeinfo::create_int (size_t nbits) | |
3584 { | |
3585 std::stringstream tname; | |
3586 tname << "int" << nbits; | |
3587 ints[nbits] = new_type (tname.str (), any, llvm::Type::getIntNTy (context, | |
3588 nbits)); | |
3589 } | |
3590 | |
18555 | 3591 void |
3592 jit_typeinfo::create_uint (size_t nbits) | |
3593 { | |
3594 std::stringstream tname; | |
3595 tname << "uint" << nbits; | |
3596 uints[nbits] = new_type (tname.str (), any, llvm::Type::getIntNTy (context, | |
3597 nbits)); | |
3598 } | |
3599 | |
15016 | 3600 jit_type * |
3601 jit_typeinfo::intN (size_t nbits) const | |
3602 { | |
3603 std::map<size_t, jit_type *>::const_iterator iter = ints.find (nbits); | |
3604 if (iter != ints.end ()) | |
3605 return iter->second; | |
3606 | |
3607 throw jit_fail_exception ("No such integer type"); | |
3608 } | |
3609 | |
3610 jit_type * | |
18555 | 3611 jit_typeinfo::uintN (size_t nbits) const |
3612 { | |
3613 std::map<size_t, jit_type *>::const_iterator iter = uints.find (nbits); | |
3614 if (iter != uints.end ()) | |
3615 return iter->second; | |
3616 | |
3617 throw jit_fail_exception ("No such unsigned integer type"); | |
3618 } | |
3619 | |
3620 jit_type * | |
15016 | 3621 jit_typeinfo::do_type_of (const octave_value &ov) const |
3622 { | |
3623 if (ov.is_function ()) | |
3624 { | |
3625 // FIXME: This is ugly, we need to finalize how we want to to this, then | |
3626 // have octave_value fully support the needed functionality | |
3627 octave_builtin *builtin | |
3628 = dynamic_cast<octave_builtin *> (ov.internal_rep ()); | |
3629 return builtin && builtin->to_jit () ? builtin->to_jit () | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3630 : unknown_function; |
15016 | 3631 } |
3632 | |
3633 if (ov.is_range ()) | |
3634 return get_range (); | |
3635 | |
15311
de9bfcf637df
Fix error when compiling with complex matrix (bug #37247)
Max Brister <max@2bass.com>
parents:
15219
diff
changeset
|
3636 if (ov.is_double_type () && ! ov.is_complex_type ()) |
15016 | 3637 { |
3638 if (ov.is_real_scalar ()) | |
3639 return get_scalar (); | |
3640 | |
3641 if (ov.is_matrix_type ()) | |
3642 return get_matrix (); | |
3643 } | |
3644 | |
18554 | 3645 if (ov.is_single_type () && ! ov.is_complex_type ()) |
3646 { | |
3647 if (ov.is_real_scalar ()) | |
3648 return get_single (); | |
3649 } | |
3650 | |
18557 | 3651 if (ov.is_int8_type()) |
3652 { | |
3653 return intN (8); | |
3654 } | |
3655 | |
18559 | 3656 if (ov.is_int16_type()) |
3657 { | |
3658 return intN (16); | |
3659 } | |
3660 | |
18560 | 3661 if (ov.is_int32_type()) |
3662 { | |
3663 return intN (32); | |
3664 } | |
3665 | |
18558
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
3666 if (ov.is_int64_type()) |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
3667 { |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
3668 return intN (64); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
3669 } |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
3670 |
18561 | 3671 if (ov.is_uint8_type()) |
3672 { | |
3673 return uintN (8); | |
3674 } | |
3675 | |
18555 | 3676 if (ov.is_uint16_type()) |
3677 { | |
3678 return uintN (16); | |
3679 } | |
3680 | |
18563 | 3681 if (ov.is_uint32_type()) |
3682 { | |
3683 return uintN (32); | |
3684 } | |
3685 | |
18562
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
3686 if (ov.is_uint64_type()) |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
3687 { |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
3688 return uintN (64); |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
3689 } |
2204a9a252c0
jit compiler: Add support for uint64 type
LYH <lyh.kernel@gmail.com>
parents:
18561
diff
changeset
|
3690 |
15016 | 3691 if (ov.is_complex_scalar ()) |
15583
0754bdfbc8fe
Correct multiplication complex multiplication with NaN in JIT
Max Brister <max@2bass.com>
parents:
15385
diff
changeset
|
3692 { |
0754bdfbc8fe
Correct multiplication complex multiplication with NaN in JIT
Max Brister <max@2bass.com>
parents:
15385
diff
changeset
|
3693 Complex cv = ov.complex_value (); |
0754bdfbc8fe
Correct multiplication complex multiplication with NaN in JIT
Max Brister <max@2bass.com>
parents:
15385
diff
changeset
|
3694 |
0754bdfbc8fe
Correct multiplication complex multiplication with NaN in JIT
Max Brister <max@2bass.com>
parents:
15385
diff
changeset
|
3695 // We don't really represent complex values, instead we represent |
0754bdfbc8fe
Correct multiplication complex multiplication with NaN in JIT
Max Brister <max@2bass.com>
parents:
15385
diff
changeset
|
3696 // complex_or_scalar. If the imag value is zero, we assume a scalar. |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
3697 if (cv.imag () != 0) |
15583
0754bdfbc8fe
Correct multiplication complex multiplication with NaN in JIT
Max Brister <max@2bass.com>
parents:
15385
diff
changeset
|
3698 return get_complex (); |
0754bdfbc8fe
Correct multiplication complex multiplication with NaN in JIT
Max Brister <max@2bass.com>
parents:
15385
diff
changeset
|
3699 } |
15016 | 3700 |
3701 return get_any (); | |
3702 } | |
3703 | |
3704 #endif | |
18553 | 3705 |
3706 #pragma GCC diagnostic pop |