forked from numpy/numpy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_simd.dispatch.c.src
786 lines (727 loc) · 22 KB
/
_simd.dispatch.c.src
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
/*@targets #simd_test*/
#include "_simd.h"
#include "_simd_inc.h"
#if NPY_SIMD
#include "_simd_data.inc"
#include "_simd_convert.inc"
#include "_simd_vector.inc"
#include "_simd_arg.inc"
#include "_simd_easyintrin.inc"
//#########################################################################
//## Defining NPYV intrinsics as module functions
//#########################################################################
/**begin repeat
* #sfx = u8, s8, u16, s16, u32, s32, u64, s64, f32, f64#
* #bsfx = b8, b8, b16, b16, b32, b32, b64, b64, b32, b64#
* #esfx = u16,s8, u32, s16, u32, s32, u64, s64, f32, f64#
* #size = 8, 8, 16, 16, 32, 32, 64, 64, 32, 64#
* #expand_sup= 1, 0, 1, 0, 0, 0, 0, 0, 0, 0#
* #simd_sup = 1, 1, 1, 1, 1, 1, 1, 1, 1, NPY_SIMD_F64#
* #fp_only = 0, 0, 0, 0, 0, 0, 0, 0, 1, 1#
* #sat_sup = 1, 1, 1, 1, 0, 0, 0, 0, 0, 0#
* #mul_sup = 1, 1, 1, 1, 1, 1, 0, 0, 1, 1#
* #div_sup = 0, 0, 0, 0, 0, 0, 0, 0, 1, 1#
* #fused_sup = 0, 0, 0, 0, 0, 0, 0, 0, 1, 1#
* #sumup_sup = 1, 0, 1, 0, 0, 0, 0, 0, 0, 0#
* #sum_sup = 0, 0, 0, 0, 1, 0, 1, 0, 1, 1#
* #rev64_sup = 1, 1, 1, 1, 1, 1, 0, 0, 1, 0#
* #ncont_sup = 0, 0, 0, 0, 1, 1, 1, 1, 1, 1#
* #intdiv_sup= 1, 1, 1, 1, 1, 1, 1, 1, 0, 0#
* #shl_imm = 0, 0, 15, 15, 31, 31, 63, 63, 0, 0#
* #shr_imm = 0, 0, 16, 16, 32, 32, 64, 64, 0, 0#
*/
#if @simd_sup@
/***************************
* Memory
***************************/
/**begin repeat1
* # intrin = load, loada, loads, loadl#
*/
SIMD_IMPL_INTRIN_1(@intrin@_@sfx@, v@sfx@, q@sfx@)
/**end repeat1**/
/**begin repeat1
* # intrin = store, storea, stores, storel, storeh#
*/
// special definition due to the nature of @intrin@
static PyObject *
simd__intrin_@intrin@_@sfx@(PyObject* NPY_UNUSED(self), PyObject *args)
{
simd_arg seq_arg = {.dtype = simd_data_q@sfx@};
simd_arg vec_arg = {.dtype = simd_data_v@sfx@};
if (!PyArg_ParseTuple(
args, "O&O&:@intrin@_@sfx@",
simd_arg_converter, &seq_arg,
simd_arg_converter, &vec_arg
)) {
return NULL;
}
npyv_@intrin@_@sfx@(seq_arg.data.q@sfx@, vec_arg.data.v@sfx@);
// write-back
if (simd_sequence_fill_iterable(seq_arg.obj, seq_arg.data.q@sfx@, simd_data_q@sfx@)) {
simd_arg_free(&seq_arg);
return NULL;
}
simd_arg_free(&seq_arg);
Py_RETURN_NONE;
}
/**end repeat1**/
/****************************************
* Non-contiguous/Partial Memory access
****************************************/
#if @ncont_sup@
// Partial Load
SIMD_IMPL_INTRIN_3(load_till_@sfx@, v@sfx@, q@sfx@, u32, @sfx@)
SIMD_IMPL_INTRIN_2(load_tillz_@sfx@, v@sfx@, q@sfx@, u32)
// Partial Store
static PyObject *
simd__intrin_store_till_@sfx@(PyObject* NPY_UNUSED(self), PyObject *args)
{
simd_arg seq_arg = {.dtype = simd_data_q@sfx@};
simd_arg nlane_arg = {.dtype = simd_data_u32};
simd_arg vec_arg = {.dtype = simd_data_v@sfx@};
if (!PyArg_ParseTuple(
args, "O&O&O&:store_till_@sfx@",
simd_arg_converter, &seq_arg,
simd_arg_converter, &nlane_arg,
simd_arg_converter, &vec_arg
)) {
return NULL;
}
npyv_store_till_@sfx@(
seq_arg.data.q@sfx@, nlane_arg.data.u32, vec_arg.data.v@sfx@
);
// write-back
if (simd_sequence_fill_iterable(seq_arg.obj, seq_arg.data.q@sfx@, simd_data_q@sfx@)) {
simd_arg_free(&seq_arg);
return NULL;
}
simd_arg_free(&seq_arg);
Py_RETURN_NONE;
}
// Non-contiguous Load
/**begin repeat1
* #intrin = loadn, loadn_till, loadn_tillz#
* #till = 0, 1, 1#
* #fill = 0, 1, 0#
* #format = , O&O&, O&#
*/
static PyObject *
simd__intrin_@intrin@_@sfx@(PyObject* NPY_UNUSED(self), PyObject *args)
{
simd_arg seq_arg = {.dtype = simd_data_q@sfx@};
simd_arg stride_arg = {.dtype = simd_data_s64};
#if @till@
simd_arg nlane_arg = {.dtype = simd_data_u32};
#endif // till
#if @fill@
simd_arg fill_arg = {.dtype = simd_data_@sfx@};
#endif
if (!PyArg_ParseTuple(
args, "@format@O&O&:@intrin@_@sfx@",
simd_arg_converter, &seq_arg,
simd_arg_converter, &stride_arg
#if @till@
,simd_arg_converter, &nlane_arg
#endif
#if @fill@
,simd_arg_converter, &fill_arg
#endif
)) {
return NULL;
}
npyv_lanetype_@sfx@ *seq_ptr = seq_arg.data.q@sfx@;
npy_intp stride = (npy_intp)stride_arg.data.s64;
Py_ssize_t cur_seq_len = simd_sequence_len(seq_ptr);
Py_ssize_t min_seq_len = stride * npyv_nlanes_@sfx@;
if (stride < 0) {
seq_ptr += cur_seq_len -1;
min_seq_len = -min_seq_len;
}
if (cur_seq_len < min_seq_len) {
PyErr_Format(PyExc_ValueError,
"@intrin@_@sfx@(), according to provided stride %d, the "
"minimum acceptable size of the required sequence is %d, given(%d)",
stride, min_seq_len, cur_seq_len
);
goto err;
}
npyv_@sfx@ rvec = npyv_@intrin@_@sfx@(
seq_ptr, stride
#if @till@
, nlane_arg.data.u32
#endif
#if @fill@
, fill_arg.data.@sfx@
#endif
);
simd_arg ret = {
.dtype = simd_data_v@sfx@, .data = {.v@sfx@=rvec}
};
simd_arg_free(&seq_arg);
return simd_arg_to_obj(&ret);
err:
simd_arg_free(&seq_arg);
return NULL;
}
/**end repeat1**/
// Non-contiguous Store
/**begin repeat1
* #intrin = storen, storen_till#
* #till = 0, 1#
* #format = , O&#
*/
static PyObject *
simd__intrin_@intrin@_@sfx@(PyObject* NPY_UNUSED(self), PyObject *args)
{
simd_arg seq_arg = {.dtype = simd_data_q@sfx@};
simd_arg stride_arg = {.dtype = simd_data_s64};
simd_arg vec_arg = {.dtype = simd_data_v@sfx@};
#if @till@
simd_arg nlane_arg = {.dtype = simd_data_u32};
#endif
if (!PyArg_ParseTuple(
args, "@format@O&O&O&:storen_@sfx@",
simd_arg_converter, &seq_arg,
simd_arg_converter, &stride_arg
#if @till@
,simd_arg_converter, &nlane_arg
#endif
,simd_arg_converter, &vec_arg
)) {
return NULL;
}
npyv_lanetype_@sfx@ *seq_ptr = seq_arg.data.q@sfx@;
npy_intp stride = (npy_intp)stride_arg.data.s64;
Py_ssize_t cur_seq_len = simd_sequence_len(seq_ptr);
Py_ssize_t min_seq_len = stride * npyv_nlanes_@sfx@;
if (stride < 0) {
seq_ptr += cur_seq_len -1;
min_seq_len = -min_seq_len;
}
// overflow guard
if (cur_seq_len < min_seq_len) {
PyErr_Format(PyExc_ValueError,
"@intrin@_@sfx@(), according to provided stride %d, the"
"minimum acceptable size of the required sequence is %d, given(%d)",
stride, min_seq_len, cur_seq_len
);
goto err;
}
npyv_@intrin@_@sfx@(
seq_ptr, stride
#if @till@
,nlane_arg.data.u32
#endif
,vec_arg.data.v@sfx@
);
// write-back
if (simd_sequence_fill_iterable(seq_arg.obj, seq_arg.data.q@sfx@, simd_data_q@sfx@)) {
goto err;
}
simd_arg_free(&seq_arg);
Py_RETURN_NONE;
err:
simd_arg_free(&seq_arg);
return NULL;
}
/**end repeat1**/
#endif // @ncont_sup@
/****************************
* Lookup tables
****************************/
#if @size@ == 32
SIMD_IMPL_INTRIN_2(lut32_@sfx@, v@sfx@, q@sfx@, vu@size@)
#endif
#if @size@ == 64
SIMD_IMPL_INTRIN_2(lut16_@sfx@, v@sfx@, q@sfx@, vu@size@)
#endif
/***************************
* Misc
***************************/
SIMD_IMPL_INTRIN_0(zero_@sfx@, v@sfx@)
SIMD_IMPL_INTRIN_1(setall_@sfx@, v@sfx@, @sfx@)
SIMD_IMPL_INTRIN_3(select_@sfx@, v@sfx@, v@bsfx@, v@sfx@, v@sfx@)
/**begin repeat1
* #sfx_to = u8, s8, u16, s16, u32, s32, u64, s64, f32, f64#
* #simd_sup2 = 1, 1, 1, 1, 1, 1, 1, 1, 1, NPY_SIMD_F64#
*/
#if @simd_sup2@
SIMD_IMPL_INTRIN_1(reinterpret_@sfx_to@_@sfx@, v@sfx_to@, v@sfx@)
#endif // simd_sup2
/**end repeat1**/
/**
* special definition due to the nature of intrinsics
* npyv_setf_@sfx@ and npy_set_@sfx@.
*/
/**begin repeat1
* #intrin = setf, set#
*/
static PyObject *
simd__intrin_@intrin@_@sfx@(PyObject* NPY_UNUSED(self), PyObject *args)
{
npyv_lanetype_@sfx@ *data = simd_sequence_from_iterable(args, simd_data_q@sfx@, npyv_nlanes_@sfx@);
if (data == NULL) {
return NULL;
}
simd_data r = {.v@sfx@ = npyv_@intrin@_@sfx@(
data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7],
data[8], data[9], data[10], data[11], data[12], data[13], data[14], data[15],
data[16], data[17], data[18], data[19], data[20], data[21], data[22], data[23],
data[24], data[25], data[26], data[27], data[28], data[29], data[30], data[31],
data[32], data[33], data[34], data[35], data[36], data[37], data[38], data[39],
data[40], data[41], data[42], data[43], data[44], data[45], data[46], data[47],
data[48], data[49], data[50], data[51], data[52], data[53], data[54], data[55],
data[56], data[57], data[58], data[59], data[60], data[61], data[62], data[63],
data[64] // for setf
)};
simd_sequence_free(data);
return (PyObject*)PySIMDVector_FromData(r, simd_data_v@sfx@);
}
/**end repeat1**/
/***************************
* Reorder
***************************/
/**begin repeat1
* # intrin = combinel, combineh#
*/
SIMD_IMPL_INTRIN_2(@intrin@_@sfx@, v@sfx@, v@sfx@, v@sfx@)
/**end repeat1**/
/**begin repeat1
* # intrin = combine, zip#
*/
SIMD_IMPL_INTRIN_2(@intrin@_@sfx@, v@sfx@x2, v@sfx@, v@sfx@)
/**end repeat1**/
#if @rev64_sup@
SIMD_IMPL_INTRIN_1(rev64_@sfx@, v@sfx@, v@sfx@)
#endif
/***************************
* Operators
***************************/
#if @shl_imm@ > 0
SIMD_IMPL_INTRIN_2(shl_@sfx@, v@sfx@, v@sfx@, u8)
SIMD_IMPL_INTRIN_2(shr_@sfx@, v@sfx@, v@sfx@, u8)
// immediate constant
SIMD_IMPL_INTRIN_2IMM(shli_@sfx@, v@sfx@, v@sfx@, @shl_imm@)
SIMD_IMPL_INTRIN_2IMM(shri_@sfx@, v@sfx@, v@sfx@, @shr_imm@)
#endif // shl_imm
/**begin repeat1
* #intrin = and, or, xor#
*/
SIMD_IMPL_INTRIN_2(@intrin@_@sfx@, v@sfx@, v@sfx@, v@sfx@)
/**end repeat1**/
SIMD_IMPL_INTRIN_1(not_@sfx@, v@sfx@, v@sfx@)
/**begin repeat1
* #intrin = cmpeq, cmpneq, cmpgt, cmpge, cmplt, cmple#
*/
SIMD_IMPL_INTRIN_2(@intrin@_@sfx@, v@bsfx@, v@sfx@, v@sfx@)
/**end repeat1**/
/***************************
* Conversion
***************************/
SIMD_IMPL_INTRIN_1(cvt_@sfx@_@bsfx@, v@sfx@, v@bsfx@)
SIMD_IMPL_INTRIN_1(cvt_@bsfx@_@sfx@, v@bsfx@, v@sfx@)
#if @expand_sup@
SIMD_IMPL_INTRIN_1(expand_@esfx@_@sfx@, v@esfx@x2, v@sfx@)
#endif // expand_sup
/***************************
* Arithmetic
***************************/
/**begin repeat1
* #intrin = add, sub#
*/
SIMD_IMPL_INTRIN_2(@intrin@_@sfx@, v@sfx@, v@sfx@, v@sfx@)
/**end repeat1**/
#if @sat_sup@
/**begin repeat1
* #intrin = adds, subs#
*/
SIMD_IMPL_INTRIN_2(@intrin@_@sfx@, v@sfx@, v@sfx@, v@sfx@)
/**end repeat1**/
#endif // sat_sup
#if @mul_sup@
SIMD_IMPL_INTRIN_2(mul_@sfx@, v@sfx@, v@sfx@, v@sfx@)
#endif // mul_sup
#if @div_sup@
SIMD_IMPL_INTRIN_2(div_@sfx@, v@sfx@, v@sfx@, v@sfx@)
#endif // div_sup
#if @intdiv_sup@
SIMD_IMPL_INTRIN_1(divisor_@sfx@, v@sfx@x3, @sfx@)
SIMD_IMPL_INTRIN_2(divc_@sfx@, v@sfx@, v@sfx@, v@sfx@x3)
#endif // intdiv_sup
#if @fused_sup@
/**begin repeat1
* #intrin = muladd, mulsub, nmuladd, nmulsub#
*/
SIMD_IMPL_INTRIN_3(@intrin@_@sfx@, v@sfx@, v@sfx@, v@sfx@, v@sfx@)
/**end repeat1**/
#endif // fused_sup
#if @sum_sup@
SIMD_IMPL_INTRIN_1(sum_@sfx@, @sfx@, v@sfx@)
#endif // sum_sup
#if @sumup_sup@
SIMD_IMPL_INTRIN_1(sumup_@sfx@, @esfx@, v@sfx@)
#endif // sumup_sup
/***************************
* Math
***************************/
#if @fp_only@
/**begin repeat1
* #intrin = sqrt, recip, abs, square, rint, ceil, trunc, floor#
*/
SIMD_IMPL_INTRIN_1(@intrin@_@sfx@, v@sfx@, v@sfx@)
/**end repeat1**/
#endif
/**begin repeat1
* #intrin = max, min#
*/
SIMD_IMPL_INTRIN_2(@intrin@_@sfx@, v@sfx@, v@sfx@, v@sfx@)
/**end repeat1**/
#if @fp_only@
/**begin repeat1
* #intrin = maxp, minp#
*/
SIMD_IMPL_INTRIN_2(@intrin@_@sfx@, v@sfx@, v@sfx@, v@sfx@)
/**end repeat1**/
#endif
/***************************
* Mask operations
***************************/
/**begin repeat1
* #intrin = ifadd, ifsub#
*/
SIMD_IMPL_INTRIN_4(@intrin@_@sfx@, v@sfx@, v@bsfx@, v@sfx@, v@sfx@, v@sfx@)
/**end repeat1**/
#endif // simd_sup
/**end repeat**/
/*************************************************************************
* Variant
************************************************************************/
SIMD_IMPL_INTRIN_0N(cleanup)
/*************************************************************************
* A special section for f32/f64 intrinsics outside the main repeater
************************************************************************/
/***************************
* Operators
***************************/
// check special cases
SIMD_IMPL_INTRIN_1(notnan_f32, vb32, vf32)
#if NPY_SIMD_F64
SIMD_IMPL_INTRIN_1(notnan_f64, vb64, vf64)
#endif
/***************************
* Conversions
***************************/
// round to nearest integer (assume even)
SIMD_IMPL_INTRIN_1(round_s32_f32, vs32, vf32)
#if NPY_SIMD_F64
SIMD_IMPL_INTRIN_2(round_s32_f64, vs32, vf64, vf64)
#endif
/*************************************************************************
* A special section for boolean intrinsics outside the main repeater
************************************************************************/
/***************************
* Operators
***************************/
// Logical
/**begin repeat
* #bsfx = b8, b16, b32, b64#
*/
SIMD_IMPL_INTRIN_2(and_@bsfx@, v@bsfx@, v@bsfx@, v@bsfx@)
SIMD_IMPL_INTRIN_2(or_@bsfx@, v@bsfx@, v@bsfx@, v@bsfx@)
SIMD_IMPL_INTRIN_2(xor_@bsfx@, v@bsfx@, v@bsfx@, v@bsfx@)
SIMD_IMPL_INTRIN_1(not_@bsfx@, v@bsfx@, v@bsfx@)
/**end repeat**/
/***************************
* Conversions
***************************/
// Convert mask vector to integer bitfield
/**begin repeat
* #bsfx = b8, b16, b32, b64#
*/
SIMD_IMPL_INTRIN_1(tobits_@bsfx@, u64, v@bsfx@)
/**end repeat**/
SIMD_IMPL_INTRIN_2(pack_b8_b16, vb8, vb16, vb16)
SIMD_IMPL_INTRIN_4(pack_b8_b32, vb8, vb32, vb32, vb32, vb32)
SIMD_IMPL_INTRIN_8(pack_b8_b64, vb8, vb64, vb64, vb64, vb64,
vb64, vb64, vb64, vb64)
//#########################################################################
//## Attach module functions
//#########################################################################
static PyMethodDef simd__intrinsics_methods[] = {
/**begin repeat
* #sfx = u8, s8, u16, s16, u32, s32, u64, s64, f32, f64#
* #bsfx = b8, b8, b16, b16, b32, b32, b64, b64, b32, b64#
* #esfx = u16,s8, u32, s16, u32, s32, u64, s64, f32, f64#
* #size = 8, 8, 16, 16, 32, 32, 64, 64, 32, 64#
* #expand_sup= 1, 0, 1, 0, 0, 0, 0, 0, 0, 0#
* #simd_sup = 1, 1, 1, 1, 1, 1, 1, 1, 1, NPY_SIMD_F64#
* #fp_only = 0, 0, 0, 0, 0, 0, 0, 0, 1, 1#
* #sat_sup = 1, 1, 1, 1, 0, 0, 0, 0, 0, 0#
* #mul_sup = 1, 1, 1, 1, 1, 1, 0, 0, 1, 1#
* #div_sup = 0, 0, 0, 0, 0, 0, 0, 0, 1, 1#
* #fused_sup = 0, 0, 0, 0, 0, 0, 0, 0, 1, 1#
* #sumup_sup = 1, 0, 1, 0, 0, 0, 0, 0, 0, 0#
* #sum_sup = 0, 0, 0, 0, 1, 0, 1, 0, 1, 1#
* #rev64_sup = 1, 1, 1, 1, 1, 1, 0, 0, 1, 0#
* #ncont_sup = 0, 0, 0, 0, 1, 1, 1, 1, 1, 1#
* #intdiv_sup= 1, 1, 1, 1, 1, 1, 1, 1, 0, 0#
* #shl_imm = 0, 0, 15, 15, 31, 31, 63, 63, 0, 0#
* #shr_imm = 0, 0, 16, 16, 32, 32, 64, 64, 0, 0#
*/
#if @simd_sup@
/***************************
* Memory
***************************/
/**begin repeat1
* # intrin = load, loada, loads, loadl, store, storea, stores, storel, storeh#
*/
SIMD_INTRIN_DEF(@intrin@_@sfx@)
/**end repeat1**/
/****************************************
* Non-contiguous/Partial Memory access
****************************************/
#if @ncont_sup@
/**begin repeat1
* #intrin = load_till, load_tillz, loadn, loadn_till, loadn_tillz,
* store_till, storen, storen_till#
*/
SIMD_INTRIN_DEF(@intrin@_@sfx@)
/**end repeat1**/
#endif // ncont_sup
/****************************
* Lookup tables
****************************/
#if @size@ == 32
SIMD_INTRIN_DEF(lut32_@sfx@)
#endif
#if @size@ == 64
SIMD_INTRIN_DEF(lut16_@sfx@)
#endif
/***************************
* Misc
***************************/
/**begin repeat1
* #sfx_to = u8, s8, u16, s16, u32, s32, u64, s64, f32, f64#
* #simd_sup2 = 1, 1, 1, 1, 1, 1, 1, 1, 1, NPY_SIMD_F64#
*/
#if @simd_sup2@
SIMD_INTRIN_DEF(reinterpret_@sfx_to@_@sfx@)
#endif // simd_sup2
/**end repeat1**/
/**begin repeat1
* # intrin = set, setf, setall, zero, select#
*/
SIMD_INTRIN_DEF(@intrin@_@sfx@)
/**end repeat1**/
/***************************
* Reorder
***************************/
/**begin repeat1
* # intrin = combinel, combineh, combine, zip#
*/
SIMD_INTRIN_DEF(@intrin@_@sfx@)
/**end repeat1**/
#if @rev64_sup@
SIMD_INTRIN_DEF(rev64_@sfx@)
#endif
/***************************
* Operators
***************************/
#if @shl_imm@ > 0
/**begin repeat1
* # intrin = shl, shr, shli, shri#
*/
SIMD_INTRIN_DEF(@intrin@_@sfx@)
/**end repeat1**/
#endif // shl_imm
/**begin repeat1
* #intrin = and, or, xor, not, cmpeq, cmpneq, cmpgt, cmpge, cmplt, cmple#
*/
SIMD_INTRIN_DEF(@intrin@_@sfx@)
/**end repeat1**/
/***************************
* Conversion
***************************/
SIMD_INTRIN_DEF(cvt_@sfx@_@bsfx@)
SIMD_INTRIN_DEF(cvt_@bsfx@_@sfx@)
#if @expand_sup@
SIMD_INTRIN_DEF(expand_@esfx@_@sfx@)
#endif // expand_sup
/***************************
* Arithmetic
***************************/
/**begin repeat1
* #intrin = add, sub#
*/
SIMD_INTRIN_DEF(@intrin@_@sfx@)
/**end repeat1**/
#if @sat_sup@
/**begin repeat1
* #intrin = adds, subs#
*/
SIMD_INTRIN_DEF(@intrin@_@sfx@)
/**end repeat1**/
#endif // sat_sup
#if @mul_sup@
SIMD_INTRIN_DEF(mul_@sfx@)
#endif // mul_sup
#if @div_sup@
SIMD_INTRIN_DEF(div_@sfx@)
#endif // div_sup
#if @intdiv_sup@
SIMD_INTRIN_DEF(divisor_@sfx@)
SIMD_INTRIN_DEF(divc_@sfx@)
#endif // intdiv_sup
#if @fused_sup@
/**begin repeat1
* #intrin = muladd, mulsub, nmuladd, nmulsub#
*/
SIMD_INTRIN_DEF(@intrin@_@sfx@)
/**end repeat1**/
#endif // fused_sup
#if @sum_sup@
SIMD_INTRIN_DEF(sum_@sfx@)
#endif // sum_sup
#if @sumup_sup@
SIMD_INTRIN_DEF(sumup_@sfx@)
#endif // sumup_sup
/***************************
* Math
***************************/
#if @fp_only@
/**begin repeat1
* #intrin = sqrt, recip, abs, square, rint, ceil, trunc, floor#
*/
SIMD_INTRIN_DEF(@intrin@_@sfx@)
/**end repeat1**/
#endif
/**begin repeat1
* #intrin = max, min#
*/
SIMD_INTRIN_DEF(@intrin@_@sfx@)
/**end repeat1**/
#if @fp_only@
/**begin repeat1
* #intrin = maxp, minp#
*/
SIMD_INTRIN_DEF(@intrin@_@sfx@)
/**end repeat1**/
#endif
/***************************
* Mask operations
***************************/
/**begin repeat1
* #intrin = ifadd, ifsub#
*/
SIMD_INTRIN_DEF(@intrin@_@sfx@)
/**end repeat1**/
#endif // simd_sup
/**end repeat**/
/*************************************************************************
* Variant
************************************************************************/
SIMD_INTRIN_DEF(cleanup)
/*************************************************************************
* A special section for f32/f64 intrinsics outside the main repeater
************************************************************************/
/***************************
* Operators
***************************/
// check special cases
SIMD_INTRIN_DEF(notnan_f32)
#if NPY_SIMD_F64
SIMD_INTRIN_DEF(notnan_f64)
#endif
/***************************
* Conversions
***************************/
// round to nearest integer (assume even)
SIMD_INTRIN_DEF(round_s32_f32)
#if NPY_SIMD_F64
SIMD_INTRIN_DEF(round_s32_f64)
#endif
/*************************************************************************
* A special section for boolean intrinsics outside the main repeater
************************************************************************/
/***************************
* Operators
***************************/
// Logical
/**begin repeat
* #bsfx = b8, b16, b32, b64#
*/
SIMD_INTRIN_DEF(and_@bsfx@)
SIMD_INTRIN_DEF(or_@bsfx@)
SIMD_INTRIN_DEF(xor_@bsfx@)
SIMD_INTRIN_DEF(not_@bsfx@)
/**end repeat**/
/***************************
* Conversions
***************************/
// Convert mask vector to integer bitfield
/**begin repeat
* #bsfx = b8, b16, b32, b64#
*/
SIMD_INTRIN_DEF(tobits_@bsfx@)
/**end repeat**/
// Pack multiple vectors into one
SIMD_INTRIN_DEF(pack_b8_b16)
SIMD_INTRIN_DEF(pack_b8_b32)
SIMD_INTRIN_DEF(pack_b8_b64)
/************************************************************************/
{NULL, NULL, 0, NULL}
}; // PyMethodDef
#endif // NPY_SIMD
//#########################################################################
//## Defining a separate module for each target
//#########################################################################
NPY_VISIBILITY_HIDDEN PyObject *
NPY_CPU_DISPATCH_CURFX(simd_create_module)(void)
{
static struct PyModuleDef defs = {
.m_base = PyModuleDef_HEAD_INIT,
.m_size = -1,
#ifdef NPY__CPU_TARGET_CURRENT
.m_name = "numpy.core._simd." NPY_TOSTRING(NPY__CPU_TARGET_CURRENT),
#else
.m_name = "numpy.core._simd.baseline",
#endif
#if NPY_SIMD
.m_methods = simd__intrinsics_methods
#else
.m_methods = NULL
#endif
};
PyObject *m = PyModule_Create(&defs);
if (m == NULL) {
return NULL;
}
if (PyModule_AddIntConstant(m, "simd", NPY_SIMD)) {
goto err;
}
if (PyModule_AddIntConstant(m, "simd_f64", NPY_SIMD_F64)) {
goto err;
}
if (PyModule_AddIntConstant(m, "simd_fma3", NPY_SIMD_FMA3)) {
goto err;
}
if (PyModule_AddIntConstant(m, "simd_width", NPY_SIMD_WIDTH)) {
goto err;
}
#if NPY_SIMD
if (PySIMDVectorType_Init(m)) {
goto err;
}
/**begin repeat
* #sfx = u8, s8, u16, s16, u32, s32, u64, s64, f32, f64#
*/
if (PyModule_AddIntConstant(m, "nlanes_@sfx@", npyv_nlanes_@sfx@)) {
goto err;
}
/**end repeat**/
#endif // NPY_SIMD
return m;
err:
Py_DECREF(m);
return NULL;
}