-
-
Notifications
You must be signed in to change notification settings - Fork 290
/
core-builtin.h
924 lines (802 loc) · 21.2 KB
/
core-builtin.h
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
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
/*
* Copyright (C) 2022-2024 Colin Ian King
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#ifndef CORE_BUILTIN_H
#define CORE_BUILTIN_H
#if defined(HAVE_X86INTRIN_H)
#include <x86intrin.h>
#endif
#if defined(HAVE_BUILTIN_ASSUME_ALIGNED)
#define shim_assume_aligned(arg, n) __builtin_assume_aligned((arg), (n))
#else
#define shim_assume_aligned(arg, n) arg
#endif
#if defined(HAVE_BUILTIN_MEMSET)
#define shim_memset(s, c, n) __builtin_memset((s), (c), (n))
#else
#define shim_memset(s, c, n) memset((s), (c), (n))
#endif
#if defined(HAVE_BUILTIN_MEMCPY)
#define shim_memcpy(dst, src, n) __builtin_memcpy((dst), (src), (n))
#else
#define shim_memcpy(dst, src, n) memcpy((dst), (src), (n))
#endif
#if defined(HAVE_BUILTIN_MEMMOVE)
#define shim_memmove(dst, src, n) __builtin_memmove((dst), (src), (n))
#else
#define shim_memmove(dst, src, n) memmove((dst), (src), (n))
#endif
#if defined(HAVE_BUILTIN_MEMCMP)
#define shim_memcmp(dst, src, n) __builtin_memcmp((dst), (src), (n))
#else
#define shim_memcmp(dst, src, n) memcmp((dst), (src), (n))
#endif
#if defined(HAVE_BUILTIN_CABS)
#define shim_cabs(x) __builtin_cabs((x))
#else
#define shim_cabs(x) cabs((x))
#endif
#if defined(HAVE_BUILTIN_CABSF)
#define shim_cabsf(x) __builtin_cabsf((x))
#else
#define shim_cabsf(x) cabsf((x))
#endif
#if defined(HAVE_BUILTIN_CABSL)
#define shim_cabsl(x) __builtin_cabsl((x))
#else
#if defined(HAVE_CABSL)
#define shim_cabsl(x) cabsl((x))
#else
#define shim_cabsl(x) ((long double)cabs((double complex)(x)))
#endif
#endif
#if defined(HAVE_BUILTIN_LGAMMAL)
#define shim_lgammal(x) __builtin_lgammal((x))
#else
#if defined(HAVE_LGAMMAL)
#define shim_lgammal(x) lgammal((x))
#else
#define shim_lgammal(x) ((long double)lgamma((double)(x)))
#endif
#endif
#if defined(HAVE_BUILTIN_CPOW)
#define shim_cpow(x, z) __builtin_cpow((x), (z))
#else
#if defined(HAVE_CPOW)
#define shim_cpow(x, z) cpow((x), (z))
#else
#define shim_cpow(x, z) (shim_cexp((z) * shim_clog((x))))
#endif
#endif
#if defined(HAVE_BUILTIN_CPOWF)
#define shim_cpowf(x, z) __builtin_cpowf((x), (z))
#else
#if defined(HAVE_CPOWF)
#define shim_cpowf(x, z) cpowf((x), (z))
#else
#define shim_cpowf(x, z) (shim_cexpf(z) * shim_clogf((x))))
#endif
#endif
#if defined(HAVE_BUILTIN_CPOWL)
#define shim_cpowl(x, z) __builtin_cpowl((x), (z))
#else
#if defined(HAVE_CPOWL)
#define shim_cpowl(x, z) cpowl((x), (z))
#else
#define shim_cpowl(x, z) (shim_cexpl((z) * shim_clogl((l))))
#endif
#endif
#if defined(HAVE_BUILTIN_HYPOT)
#define shim_hypot(x, y) __builtin_hypot((x), (y))
#else
#define shim_hypot(x, y) hypot((x), (y))
#endif
#if defined(HAVE_BUILTIN_HYPOTF)
#define shim_hypotf(x, y) __builtin_hypotf((x), (y))
#else
#define shim_hypotf(x, y) hypotf((x), (y))
#endif
#if defined(HAVE_BUILTIN_HYPOTL)
#define shim_hypotl(x, y) __builtin_hypotl((x), (y))
#else
#if defined(HAVE_HYPOTL)
#define shim_hypotl(x, y) hypotl((x), (y))
#else
#define shim_hypotl(x, y) ((long double)hypot((double)(x), (double)(y)))
#endif
#endif
#if defined(HAVE_BUILTIN_POW)
#define shim_pow(x, y) __builtin_pow((x), (y))
#else
#define shim_pow(x, y) pow((x), (y))
#endif
#if defined(HAVE_BUILTIN_POWF)
#define shim_powf(x, y) __builtin_powf((x), (y))
#else
#define shim_powf(x, y) powf((x), (y))
#endif
#if defined(HAVE_BUILTIN_POWL)
#define shim_powl(x, y) __builtin_powl((x), (y))
#else
#if defined(HAVE_POWL)
#define shim_powl(x, y) powl((x), (y))
#else
#define shim_powl(x, y) ((long double)pow((double)(x), (double)(y)))
#endif
#endif
#if defined(HAVE_BUILTIN_RINTL)
#define shim_rintl(x) __builtin_rintl((x))
#else
#if defined(HAVE_RINTL)
#define shim_rintl(x) rintl((x))
#else
#define shim_rintl(x) ((long double)shim_rint((double)(x)))
#endif
#endif
#if defined(HAVE_BUILTIN_CLOGF)
#define shim_clogf(x) __builtin_clogf((x))
#else
#define shim_clogf(x) clogf((x))
#endif
#if defined(HAVE_BUILTIN_CLOG)
#define shim_clog(x) __builtin_clog((x))
#else
#define shim_clog(x) clog((x))
#endif
#if defined(HAVE_BUILTIN_CLOGL)
#define shim_clogl(x) __builtin_clogl((x))
#else
#if defined(HAVE_CLOGL)
#define shim_clogl(x) clogl((x))
#else
#define shim_clogl(x) ((long double complex)shim_clog((double complex)(x)))
#endif
#endif
#if defined(HAVE_BUILTIN_LOGF)
#define shim_logf(x) __builtin_logf((x))
#else
#define shim_logf(x) logf((x))
#endif
#if defined(HAVE_BUILTIN_LOG)
#define shim_log(x) __builtin_log((x))
#else
#define shim_log(x) log((x))
#endif
#if defined(HAVE_BUILTIN_LOGL)
#define shim_logl(x) __builtin_logl((x))
#else
#if defined(HAVE_LOGL)
#define shim_logl(x) logl((x))
#else
#define shim_logl(x) ((long double)shim_log((double)(x)))
#endif
#endif
#if defined(HAVE_BUILTIN_LOGBF)
#define shim_logbf(x) __builtin_logbf((x))
#else
#define shim_logbf(x) logbf((x))
#endif
#if defined(HAVE_BUILTIN_LOGB)
#define shim_logb(x) __builtin_logb((x))
#else
#define shim_logb(x) logb((x))
#endif
#if defined(HAVE_BUILTIN_LOGBL)
#define shim_logbl(x) __builtin_logbl((x))
#else
#if defined(HAVE_LOGBL)
#define shim_logbl(x) logbl((x))
#else
#define shim_logbl(x) ((long double)shim_logb((double)(x)))
#endif
#endif
#if defined(HAVE_BUILTIN_LOG10F)
#define shim_log10f(x) __builtin_log10f((x))
#else
#define shim_log10f(x) log10f((x))
#endif
#if defined(HAVE_BUILTIN_LOG10)
#define shim_log10(x) __builtin_log10((x))
#else
#define shim_log10(x) log10((x))
#endif
#if defined(HAVE_BUILTIN_LOG10L)
#define shim_log10l(x) __builtin_log10l((x))
#else
#if defined(HAVE_LOG10L)
#define shim_log10l(x) log10l((x))
#else
#define shim_log10l(x) ((long double)shim_log10((double)(x)))
#endif
#endif
#if defined(HAVE_BUILTIN_LOG2F)
#define shim_log2f(x) __builtin_log2f((x))
#else
#define shim_log2f(x) log2f((x))
#endif
#if defined(HAVE_BUILTIN_LOG2)
#define shim_log2(x) __builtin_log2((x))
#else
#define shim_log2(x) log2((x))
#endif
#if defined(HAVE_BUILTIN_LOG2L)
#define shim_log2l(x) __builtin_log2l((x))
#else
#if defined(HAVE_LOG2L)
#define shim_log2l(x) log2l((x))
#else
#define shim_log2l(x) ((long double)shim_log2((double)(x)))
#endif
#endif
#if defined(HAVE_BUILTIN_EXP)
#define shim_exp(x) __builtin_exp((x))
#else
#define shim_exp(x) exp((x))
#endif
#if defined(HAVE_BUILTIN_EXPF)
#define shim_expf(x) __builtin_expf((x))
#else
#define shim_expf(x) expf((x))
#endif
#if defined(HAVE_BUILTIN_EXPL)
#define shim_expl(x) __builtin_expl((x))
#else
#if defined(HAVE_EXPL) && !defined(__HAIKU__)
#define shim_expl(x) expl((x))
#else
#define shim_expl(x) ((long double)shim_exp((double)(x)))
#endif
#endif
#if defined(HAVE_BUILTIN_EXP2)
#define shim_exp2(x) __builtin_exp2((x))
#else
#define shim_exp2(x) exp2((x))
#endif
#if defined(HAVE_BUILTIN_EXP2F)
#define shim_exp2f(x) __builtin_exp2f((x))
#else
#define shim_exp2f(x) exp2f((x))
#endif
#if defined(HAVE_BUILTIN_EXP2L)
#define shim_exp2l(x) __builtin_exp2l((x))
#else
#if defined(HAVE_EXP2L) && !defined(__HAIKU__)
#define shim_exp2l(x) exp2l((x))
#else
#define shim_exp2l(x) ((long double)shim_exp2((double)(x)))
#endif
#endif
#if defined(HAVE_BUILTIN_EXP10)
#define shim_exp10(x) __builtin_exp10((x))
#else
#define shim_exp10(x) exp10((x))
#endif
#if defined(HAVE_BUILTIN_EXP10F)
#define shim_exp10f(x) __builtin_exp10f((x))
#else
#define shim_exp10f(x) exp10f((x))
#endif
#if defined(HAVE_BUILTIN_EXP10L)
#define shim_exp10l(x) __builtin_exp10l((x))
#else
#if defined(HAVE_EXP10L) && !defined(__HAIKU__)
#define shim_exp10l(x) exp10l((x))
#else
#define shim_exp10l(x) ((long double)shim_exp10((double)(x)))
#endif
#endif
#if defined(HAVE_BUILTIN_FMA)
#define shim_fma(x, y, z) __builtin_fma((x), (y), (z))
#else
#define shim_fma(x, y, z) fma((x), (y), (z))
#endif
#if defined(HAVE_BUILTIN_FMAF)
#define shim_fmaf(x, y, z) __builtin_fmaf((x), (y), (z))
#else
#define shim_fmaf(x, y, z) fmaf((x), (y), (z))
#endif
#if defined(HAVE_BUILTIN_CBRT)
#define shim_cbrt(x) __builtin_cbrt((x))
#else
#define shim_cbrt(x) cbrt((x))
#endif
#if defined(HAVE_BUILTIN_CBRTF)
#define shim_cbrtf(x) __builtin_cbrtf((x))
#else
#define shim_cbrtf(x) cbrtf((x))
#endif
#if defined(HAVE_BUILTIN_CBRTL)
#define shim_cbrtl(x) __builtin_cbrtl((x))
#else
#if defined(HAVE_SQRTL)
#define shim_cbrtl(x) cbrtl((x))
#else
#define shim_cbrtl(x) ((long double)shim_cbrt((double)(x)))
#endif
#endif
#if defined(HAVE_BUILTIN_CEXP)
#define shim_cexp(x) __builtin_cexp((x))
#else
#define shim_cexp(x) cexp((x))
#endif
#if defined(HAVE_BUILTIN_CEXPF)
#define shim_cexpf(x) __builtin_cexpf((x))
#else
#define shim_cexpf(x) cexpf((x))
#endif
#if defined(HAVE_BUILTIN_CEXPL)
#define shim_cexpl(x) __builtin_cexpl((x))
#else
#if defined(HAVE_CEXPL)
#define shim_cexpl(x) cexpl((x))
#else
#define shim_cexpl(x) ((long double complex)cexp((double complex)(x)))
#endif
#endif
#if defined(HAVE_BUILTIN_COSF)
#define shim_cosf(x) __builtin_cosf((x))
#else
#define shim_cosf(x) cosf((x))
#endif
#if defined(HAVE_BUILTIN_COS)
#define shim_cos(x) __builtin_cos((x))
#else
#define shim_cos(x) cos((x))
#endif
#if defined(HAVE_BUILTIN_COSL)
#define shim_cosl(x) __builtin_cosl((x))
#else
#if defined(HAVE_COSL)
#define shim_cosl(x) cosl((x))
#else
#define shim_cosl(x) ((long double)shim_cos((double)(x)))
#endif
#endif
#if defined(HAVE_BUILTIN_COSHF)
#define shim_coshf(x) __builtin_coshf((x))
#else
#define shim_coshf(x) coshf((x))
#endif
#if defined(HAVE_BUILTIN_COSH)
#define shim_cosh(x) __builtin_cosh((x))
#else
#define shim_cosh(x) cosh((x))
#endif
#if defined(HAVE_BUILTIN_COSHL)
#define shim_coshl(x) __builtin_coshl((x))
#else
#if defined(HAVE_COSHL)
#define shim_coshl(x) coshl((x))
#else
#define shim_coshl(x) ((long double)cosh((double)(x)))
#endif
#endif
#if defined(HAVE_BUILTIN_CCOS)
#define shim_ccos(x) __builtin_ccos((x))
#else
#if defined(HAVE_CCOS)
#define shim_ccos(x) ccos((x))
#else
#define shim_ccos(x) ((shim_exp(I * (x)) + shim_exp(-I * (x))) / 2.0)
#endif
#endif
#if defined(HAVE_BUILTIN_CCOSF)
#define shim_ccosf(x) __builtin_ccosf((x))
#else
#if defined(HAVE_CCOSF)
#define shim_ccosf(x) ccosf((x))
#else
#define shim_ccosf(x) ((shim_expf(I * (x)) + shim_expf(-I * (x))) / 2.0)
#endif
#endif
#if defined(HAVE_BUILTIN_CCOSL)
#define shim_ccosl(x) __builtin_ccosl((x))
#else
#if defined(HAVE_CCOSL)
#define shim_ccosl(x) ccosl((x))
#else
#define shim_ccosl(x) ((shim_expl(I * (x)) + shim_expl(-I * (x))) / 2.0)
#endif
#endif
#if defined(HAVE_BUILTIN_CSQRT)
#define shim_csqrt(x) __builtin_csqrt((x))
#else
#define shim_csqrt(x) csqrt((x))
#endif
#if defined(HAVE_BUILTIN_CSQRTF)
#define shim_csqrtf(x) __builtin_csqrtf((x))
#else
#define shim_csqrtf(x) csqrtf((x))
#endif
#if defined(HAVE_BUILTIN_CSQRTL)
#define shim_csqrtl(x) __builtin_csqrtl((x))
#else
#if defined(HAVE_CSQRTL)
#define shim_csqrtl(x) csqrtl((x))
#else
#define shim_csqrtl(x) ((long double)shim_csqrt((double)(x)))
#endif
#endif
#if defined(HAVE_BUILTIN_SINF)
#define shim_sinf(x) __builtin_sinf((x))
#else
#define shim_sinf(x) sinf((x))
#endif
#if defined(HAVE_BUILTIN_SIN)
#define shim_sin(x) __builtin_sin((x))
#else
#define shim_sin(x) sin((x))
#endif
#if defined(HAVE_BUILTIN_SINL)
#define shim_sinl(x) __builtin_sinl((x))
#else
#if defined(HAVE_SINL)
#define shim_sinl(x) sinl((x))
#else
#define shim_sinl(x) ((long double)shim_sin((double)(x)))
#endif
#endif
#if defined(HAVE_BUILTIN_SINCOSF)
#define shim_sincosf(x, s, c) __builtin_sincosf((x), (s), (c))
#else
#define shim_sincosf(x, s, c) sincosf((x), (s), (c))
#endif
#if defined(HAVE_BUILTIN_SINCOS)
#define shim_sincos(x, s, c) __builtin_sincos((x), (s), (c))
#else
#define shim_sincos(x, s, c) sincos((x), (s), (c))
#endif
#if defined(HAVE_BUILTIN_SINCOSL)
#define shim_sincosl(x, s, c) __builtin_sincosl((x), (s), (c))
#else
#define shim_sincosl(x, s, c) sincosl((x), (s), (c))
#endif
#if defined(HAVE_BUILTIN_SINHF)
#define shim_sinhf(x) __builtin_sinhf((x))
#else
#define shim_sinhf(x) sinhf((x))
#endif
#if defined(HAVE_BUILTIN_SINH)
#define shim_sinh(x) __builtin_sinh((x))
#else
#define shim_sinh(x) sinh((x))
#endif
#if defined(HAVE_BUILTIN_SINHL)
#define shim_sinhl(x) __builtin_sinhl((x))
#else
#if defined(HAVE_SINHL)
#define shim_sinhl(x) sinhl((x))
#else
#define shim_sinhl(x) ((long double)sinh((double)(x)))
#endif
#endif
#if defined(HAVE_BUILTIN_CSIN)
#define shim_csin(x) __builtin_csin((x))
#else
#if defined(HAVE_CSIN)
#define shim_csin(x) csin((x))
#else
#define shim_csin(x) ((shim_exp(I * (x)) - shim_exp(-I * (x))) / (2.0 * I))
#endif
#endif
#if defined(HAVE_BUILTIN_CSINF)
#define shim_csinf(x) __builtin_csinf((x))
#else
#if defined(HAVE_CSINF)
#define shim_csinf(x) csinf((x))
#else
#define shim_csinf(x) ((shim_expf(I * (x)) - shim_expf(-I * (x))) / (2.0 * I))
#endif
#endif
#if defined(HAVE_BUILTIN_CSINL)
#define shim_csinl(x) __builtin_csinl((x))
#else
#if defined(HAVE_CSINL)
#define shim_csinl(x) csinl((x))
#else
#define shim_csinl(x) ((shim_expl(I * (x)) - shim_expl(-I * (x))) / (2.0 * I))
#endif
#endif
#if defined(HAVE_BUILTIN_TANF)
#define shim_tanf(x) __builtin_tanf((x))
#else
#define shim_tanf(x) tanf((x))
#endif
#if defined(HAVE_BUILTIN_TAN)
#define shim_tan(x) __builtin_tan((x))
#else
#define shim_tan(x) tan((x))
#endif
#if defined(HAVE_BUILTIN_TANL)
#define shim_tanl(x) __builtin_tanl((x))
#else
#define shim_tanl(x) tanl((x))
#endif
#if defined(HAVE_BUILTIN_TANHF)
#define shim_tanhf(x) __builtin_tanhf((x))
#else
#define shim_tanhf(x) tanhf((x))
#endif
#if defined(HAVE_BUILTIN_TANH)
#define shim_tanh(x) __builtin_tanh((x))
#else
#define shim_tanh(x) tanh((x))
#endif
#if defined(HAVE_BUILTIN_TANHL)
#define shim_tanhl(x) __builtin_tanhl((x))
#else
#define shim_tanhl(x) tanhl((x))
#endif
#if defined(HAVE_BUILTIN_SQRT)
#define shim_sqrt(x) __builtin_sqrt((x))
#else
#define shim_sqrt(x) sqrt((x))
#endif
#if defined(HAVE_BUILTIN_SQRTF)
#define shim_sqrtf(x) __builtin_sqrtf((x))
#else
#define shim_sqrtf(x) sqrtf((x))
#endif
#if defined(HAVE_BUILTIN_SQRTL)
#define shim_sqrtl(x) __builtin_sqrtl((x))
#else
#if defined(HAVE_SQRTL)
#define shim_sqrtl(x) sqrtl((x))
#else
#define shim_sqrtl(x) ((long double)shim_sqrt((double)x))
#endif
#endif
#if defined(HAVE_BUILTIN_FABS)
#define shim_fabs(x) __builtin_fabs((x))
#else
#define shim_fabs(x) fabs((x))
#endif
#if defined(HAVE_BUILTIN_FABSF)
#define shim_fabsf(x) __builtin_fabsf((x))
#else
#define shim_fabsf(x) fabsf((x))
#endif
#if defined(HAVE_BUILTIN_FABSL)
#define shim_fabsl(x) __builtin_fabsl((x))
#else
#define shim_fabsl(x) fabsl((x))
#endif
#if defined(HAVE_BUILTIN_LLABS)
#define shim_llabs(x) __builtin_llabs((x))
#else
#define shim_llabs(x) llabs((x))
#endif
#if defined(HAVE_BUILTIN_J0)
#define shim_j0(x) __builtin_j0((x))
#else
#define shim_j0(x) j0((x))
#endif
#if defined(HAVE_BUILTIN_J0F)
#define shim_j0f(x) __builtin_j0f((x))
#else
#define shim_j0f(x) j0f((x))
#endif
#if defined(HAVE_BUILTIN_J0L)
#define shim_j0l(x) __builtin_j0l((x))
#else
#define shim_j0l(x) j0l((x))
#endif
#if defined(HAVE_BUILTIN_J1)
#define shim_j1(x) __builtin_j1((x))
#else
#define shim_j1(x) j1((x))
#endif
#if defined(HAVE_BUILTIN_J1F)
#define shim_j1f(x) __builtin_j1f((x))
#else
#define shim_j1f(x) j1f((x))
#endif
#if defined(HAVE_BUILTIN_J1L)
#define shim_j1l(x) __builtin_j1l((x))
#else
#define shim_j1l(x) j1l((x))
#endif
#if defined(HAVE_BUILTIN_JN)
#define shim_jn(n, x) __builtin_jn((n), (x))
#else
#define shim_jn(n, x) jn((n), (x))
#endif
#if defined(HAVE_BUILTIN_JNF)
#define shim_jnf(n, x) __builtin_jnf((n), (x))
#else
#define shim_jnf(n, x) jnf((n), (x))
#endif
#if defined(HAVE_BUILTIN_JNL)
#define shim_jnl(n, x) __builtin_jnl((n), (x))
#else
#define shim_jnl(n, x) jnl((n), (x))
#endif
#if defined(HAVE_BUILTIN_RINT)
#define shim_rint(x) __builtin_rint((x))
#else
#define shim_rint(x) rint((x))
#endif
#if defined(HAVE_BUILTIN_Y0)
#define shim_y0(x) __builtin_y0((x))
#else
#define shim_y0(x) y0((x))
#endif
#if defined(HAVE_BUILTIN_Y0F)
#define shim_y0f(x) __builtin_y0f((x))
#else
#define shim_y0f(x) y0f((x))
#endif
#if defined(HAVE_BUILTIN_Y0L)
#define shim_y0l(x) __builtin_y0l((x))
#else
#define shim_y0l(x) y0l((x))
#endif
#if defined(HAVE_BUILTIN_Y1)
#define shim_y1(x) __builtin_y1((x))
#else
#define shim_y1(x) y1((x))
#endif
#if defined(HAVE_BUILTIN_Y1F)
#define shim_y1f(x) __builtin_y1f((x))
#else
#define shim_y1f(x) y1f((x))
#endif
#if defined(HAVE_BUILTIN_Y1L)
#define shim_y1l(x) __builtin_y1l((x))
#else
#define shim_y1l(x) y1l((x))
#endif
#if defined(HAVE_BUILTIN_YN)
#define shim_yn(n, x) __builtin_yn((n), (x))
#else
#define shim_yn(n, x) yn((n), (x))
#endif
#if defined(HAVE_BUILTIN_YNF)
#define shim_ynf(n, x) __builtin_ynf((n), (x))
#else
#define shim_ynf(n, x) ynf((n), (x))
#endif
#if defined(HAVE_BUILTIN_YNL)
#define shim_ynl(n, x) __builtin_ynl((n), (x))
#else
#define shim_ynl(n, x) ynl((n), (x))
#endif
#if defined(HAVE_BUILTIN_ROUNDL)
#define shim_roundl(x) __builtin_roundl((x))
#else
#define shim_roundl(x) roundl((x))
#endif
#if defined(HAVE_BUILTIN_ROTATELEFT8)
#define shim_rol8n(x, bits) __builtin_rotateleft8(x, bits)
#elif defined(HAVE_INTRINSIC_ROLB) && \
defined(HAVE_X86INTRIN_H) && \
!defined(HAVE_COMPILER_ICC)
#define shim_rol8n(x, bits) __rolb(x, bits)
#else
static inline uint8_t ALWAYS_INLINE shim_rol8n(const uint8_t x, const unsigned int bits)
{
return ((x << bits) | x >> (8 - bits));
}
#endif
#if defined(HAVE_BUILTIN_ROTATELEFT16)
#define shim_rol16n(x, bits) __builtin_rotateleft16(x, bits)
#elif defined(HAVE_INTRINSIC_ROLW) && \
defined(HAVE_X86INTRIN_H) && \
!defined(HAVE_COMPILER_ICC)
#define shim_rol16n(x, bits) __rolw(x, bits)
#else
static inline uint16_t ALWAYS_INLINE shim_rol16n(const uint16_t x, const unsigned int bits)
{
return ((x << bits) | x >> (16 - bits));
}
#endif
#if defined(HAVE_BUILTIN_ROTATELEFT32)
#define shim_rol32n(x, bits) __builtin_rotateleft32(x, bits)
#elif defined(HAVE_INTRINSIC_ROLD) && \
defined(HAVE_X86INTRIN_H) && \
!defined(HAVE_COMPILER_ICC)
#define shim_rol32n(x, bits) __rold(x, bits)
#else
static inline uint32_t ALWAYS_INLINE shim_rol32n(const uint32_t x, const unsigned int bits)
{
return ((x << bits) | x >> (32 - bits));
}
#endif
#if defined(HAVE_BUILTIN_ROTATELEFT64)
#define shim_rol64n(x, bits) __builtin_rotateleft64(x, bits)
#elif defined(HAVE_INTRINSIC_ROLQ) && \
defined(HAVE_X86INTRIN_H) && \
!defined(HAVE_COMPILER_ICC)
#define shim_rol64n(x, bits) __rolq(x, bits)
#else
static inline uint64_t ALWAYS_INLINE shim_rol64n(const uint64_t x, const unsigned int bits)
{
return ((x << bits) | x >> (64 - bits));
}
#endif
#if defined(HAVE_INT128_T)
static inline __uint128_t ALWAYS_INLINE shim_rol128n(const __uint128_t x, const unsigned int bits)
{
return ((x << bits) | x >> (128 - bits));
}
#endif
#if defined(HAVE_BUILTIN_ROTATERIGHT8)
#define shim_ror8n(x, bits) __builtin_rotateright8(x, bits)
#elif defined(HAVE_INTRINSIC_RORB) && \
defined(HAVE_X86INTRIN_H) && \
!defined(HAVE_COMPILER_ICC)
#define shim_ror8n(x, bits) __rorb(x, bits)
#else
static inline uint8_t ALWAYS_INLINE shim_ror8n(const uint8_t x, const unsigned int bits)
{
return ((x >> bits) | x << (8 - bits));
}
#endif
#if defined(HAVE_BUILTIN_ROTATERIGHT16)
#define shim_ror16n(x, bits) __builtin_rotateright16(x, bits)
#elif defined(HAVE_INTRINSIC_RORW) && \
defined(HAVE_X86INTRIN_H) && \
!defined(HAVE_COMPILER_ICC)
#define shim_ror16n(x, bits) __rorw(x, bits)
#else
static inline uint16_t ALWAYS_INLINE shim_ror16n(const uint16_t x, const unsigned int bits)
{
return ((x >> bits) | x << (16 - bits));
}
#endif
#if defined(HAVE_BUILTIN_ROTATERIGHT32)
#define shim_ror32n(x, bits) __builtin_rotateright32(x, bits)
#elif defined(HAVE_INTRINSIC_RORD) && \
defined(HAVE_X86INTRIN_H) && \
!defined(HAVE_COMPILER_ICC)
#define shim_ror32n(x, bits) __rord(x, bits)
#else
static inline uint32_t ALWAYS_INLINE shim_ror32n(const uint32_t x, const unsigned int bits)
{
return ((x >> bits) | x << (32 - bits));
}
#endif
#if defined(HAVE_BUILTIN_ROTATERIGHT64)
#define shim_ror64n(x, bits) __builtin_rotateright64(x, bits)
#elif defined(HAVE_INTRINSIC_RORQ) && \
defined(HAVE_X86INTRIN_H) && \
!defined(HAVE_COMPILER_ICC)
#define shim_ror64n(x, bits) __rorq(x, bits)
#else
static inline uint64_t ALWAYS_INLINE shim_ror64n(const uint64_t x, const unsigned int bits)
{
return ((x >> bits) | x << (64 - bits));
}
#endif
#if defined(HAVE_INT128_T)
static inline __uint128_t ALWAYS_INLINE shim_ror128n(const __uint128_t x, const unsigned int bits)
{
return ((x >> bits) | x << (128 - bits));
}
#endif
#define shim_rol8(x) shim_rol8n((x), 1)
#define shim_rol16(x) shim_rol16n((x), 1)
#define shim_rol32(x) shim_rol32n((x), 1)
#define shim_rol64(x) shim_rol64n((x), 1)
#define shim_rol128(x) shim_rol128n((x), 1)
#define shim_ror8(x) shim_ror8n((x), 1)
#define shim_ror16(x) shim_ror16n((x), 1)
#define shim_ror32(x) shim_ror32n((x), 1)
#define shim_ror64(x) shim_ror64n((x), 1)
#define shim_ror128(x) shim_ror128n((x), 1)
#endif