slot 0.0.1
A real time UI render framework
载入中...
搜索中...
未找到
slang-cpp-scalar-intrinsics.h
浏览该文件的文档.
1#ifndef SLANG_PRELUDE_SCALAR_INTRINSICS_H
2#define SLANG_PRELUDE_SCALAR_INTRINSICS_H
3
4#if !defined(SLANG_LLVM) && SLANG_PROCESSOR_X86_64 && SLANG_VC
5// If we have visual studio and 64 bit processor, we can assume we have popcnt, and can include
6// x86 intrinsics
7#include <intrin.h>
8#endif
9
10#ifndef SLANG_FORCE_INLINE
11#define SLANG_FORCE_INLINE inline
12#endif
13
14#ifdef SLANG_PRELUDE_NAMESPACE
16{
17#endif
18
19#ifndef SLANG_PRELUDE_PI
20#define SLANG_PRELUDE_PI 3.14159265358979323846
21#endif
22
24{
25 uint32_t u;
26 int32_t i;
27 float f;
28};
29
31{
32 uint64_t u;
33 int64_t i;
34 double d;
35};
36
37// 32 bit cast conversions
39{
40 Union32 u;
41 u.f = f;
42 return u.i;
43}
45{
46 Union32 u;
47 u.i = i;
48 return u.f;
49}
51{
52 Union32 u;
53 u.f = f;
54 return u.u;
55}
57{
58 Union32 u;
59 u.u = ui;
60 return u.f;
61}
62
63// ----------------------------- F32 -----------------------------------------
64
65// Helpers
66SLANG_FORCE_INLINE float F32_calcSafeRadians(float radians);
67
68#ifdef SLANG_LLVM
69
71
72// Unary
73float F32_ceil(float f);
74float F32_floor(float f);
75float F32_round(float f);
76float F32_sin(float f);
77float F32_cos(float f);
78float F32_tan(float f);
79float F32_asin(float f);
80float F32_acos(float f);
81float F32_atan(float f);
82float F32_sinh(float f);
83float F32_cosh(float f);
84float F32_tanh(float f);
85float F32_asinh(float f);
86float F32_acosh(float f);
87float F32_atanh(float f);
88float F32_log2(float f);
89float F32_log(float f);
90float F32_log10(float f);
91float F32_exp2(float f);
92float F32_exp(float f);
93float F32_abs(float f);
94float F32_trunc(float f);
95float F32_sqrt(float f);
96
97bool F32_isnan(float f);
98bool F32_isfinite(float f);
99bool F32_isinf(float f);
100
101// Binary
102SLANG_FORCE_INLINE float F32_min(float a, float b)
103{
104 return a < b ? a : b;
105}
106SLANG_FORCE_INLINE float F32_max(float a, float b)
107{
108 return a > b ? a : b;
109}
110float F32_pow(float a, float b);
111float F32_fmod(float a, float b);
112float F32_remainder(float a, float b);
113float F32_atan2(float a, float b);
114
115float F32_frexp(float x, int* e);
116
117float F32_modf(float x, float* ip);
118
119// Ternary
120SLANG_FORCE_INLINE float F32_fma(float a, float b, float c)
121{
122 return a * b + c;
123}
124
126
127#else
128
129// Unary
131{
132 return ::ceilf(f);
133}
135{
136 return ::floorf(f);
137}
139{
140 return ::roundf(f);
141}
143{
144 return ::sinf(f);
145}
147{
148 return ::cosf(f);
149}
151{
152 return ::tanf(f);
153}
155{
156 return ::asinf(f);
157}
159{
160 return ::acosf(f);
161}
163{
164 return ::atanf(f);
165}
167{
168 return ::sinhf(f);
169}
171{
172 return ::coshf(f);
173}
175{
176 return ::tanhf(f);
177}
179{
180 return ::asinhf(f);
181}
183{
184 return ::acoshf(f);
185}
187{
188 return ::atanhf(f);
189}
191{
192 return ::log2f(f);
193}
195{
196 return ::logf(f);
197}
199{
200 return ::log10f(f);
201}
203{
204 return ::exp2f(f);
205}
207{
208 return ::expf(f);
209}
211{
212 return ::fabsf(f);
213}
215{
216 return ::truncf(f);
217}
219{
220 return ::sqrtf(f);
221}
222
224{
225 return SLANG_PRELUDE_STD isnan(f);
226}
228{
229 return SLANG_PRELUDE_STD isfinite(f);
230}
232{
233 return SLANG_PRELUDE_STD isinf(f);
234}
235
236// Binary
237SLANG_FORCE_INLINE float F32_min(float a, float b)
238{
239 return ::fminf(a, b);
240}
241SLANG_FORCE_INLINE float F32_max(float a, float b)
242{
243 return ::fmaxf(a, b);
244}
245SLANG_FORCE_INLINE float F32_pow(float a, float b)
246{
247 return ::powf(a, b);
248}
249SLANG_FORCE_INLINE float F32_fmod(float a, float b)
250{
251 return ::fmodf(a, b);
252}
253SLANG_FORCE_INLINE float F32_remainder(float a, float b)
254{
255 return ::remainderf(a, b);
256}
257SLANG_FORCE_INLINE float F32_atan2(float a, float b)
258{
259 return float(::atan2(a, b));
260}
261
262SLANG_FORCE_INLINE float F32_frexp(float x, int* e)
263{
264 return ::frexpf(x, e);
265}
266
267SLANG_FORCE_INLINE float F32_modf(float x, float* ip)
268{
269 return ::modff(x, ip);
270}
271
272// Ternary
273SLANG_FORCE_INLINE float F32_fma(float a, float b, float c)
274{
275 return ::fmaf(a, b, c);
276}
277
278#endif
279
281{
282 // Put 0 to 2pi cycles to cycle around 0 to 1
283 float a = radians * (1.0f / float(SLANG_PRELUDE_PI * 2));
284 // Get truncated fraction, as value in 0 - 1 range
285 a = a - F32_floor(a);
286 // Convert back to 0 - 2pi range
287 return (a * float(SLANG_PRELUDE_PI * 2));
288}
289
291{
292 return 1.0f / F32_sqrt(f);
293}
295{
296 return (f == 0.0f) ? 0 : ((f < 0.0f) ? -1 : 1);
297}
299{
300 return f - F32_floor(f);
301}
302
304{
305 Union32 u;
306 u.f = f;
307 return u.u;
308}
310{
311 Union32 u;
312 u.f = f;
313 return u.i;
314}
315
316// ----------------------------- F64 -----------------------------------------
317
318SLANG_FORCE_INLINE double F64_calcSafeRadians(double radians);
319
320#ifdef SLANG_LLVM
321
323
324// Unary
325double F64_ceil(double f);
326double F64_floor(double f);
327double F64_round(double f);
328double F64_sin(double f);
329double F64_cos(double f);
330double F64_tan(double f);
331double F64_asin(double f);
332double F64_acos(double f);
333double F64_atan(double f);
334double F64_sinh(double f);
335double F64_cosh(double f);
336double F64_tanh(double f);
337double F64_asinh(double f);
338double F64_acosh(double f);
339double F64_atanh(double f);
340double F64_log2(double f);
341double F64_log(double f);
342double F64_log10(double f);
343double F64_exp2(double f);
344double F64_exp(double f);
345double F64_abs(double f);
346double F64_trunc(double f);
347double F64_sqrt(double f);
348
349bool F64_isnan(double f);
350bool F64_isfinite(double f);
351bool F64_isinf(double f);
352
353// Binary
354SLANG_FORCE_INLINE double F64_min(double a, double b)
355{
356 return a < b ? a : b;
357}
358SLANG_FORCE_INLINE double F64_max(double a, double b)
359{
360 return a > b ? a : b;
361}
362double F64_pow(double a, double b);
363double F64_fmod(double a, double b);
364double F64_remainder(double a, double b);
365double F64_atan2(double a, double b);
366
367double F64_frexp(double x, int* e);
368
369double F64_modf(double x, double* ip);
370
371// Ternary
372SLANG_FORCE_INLINE double F64_fma(double a, double b, double c)
373{
374 return a * b + c;
375}
376
378
379#else // SLANG_LLVM
380
381// Unary
383{
384 return ::ceil(f);
385}
387{
388 return ::floor(f);
389}
391{
392 return ::round(f);
393}
395{
396 return ::sin(f);
397}
399{
400 return ::cos(f);
401}
403{
404 return ::tan(f);
405}
407{
408 return ::asin(f);
409}
411{
412 return ::acos(f);
413}
415{
416 return ::atan(f);
417}
419{
420 return ::sinh(f);
421}
423{
424 return ::cosh(f);
425}
427{
428 return ::tanh(f);
429}
431{
432 return ::log2(f);
433}
435{
436 return ::log(f);
437}
439{
440 return ::log10(f);
441}
443{
444 return ::exp2(f);
445}
447{
448 return ::exp(f);
449}
451{
452 return ::fabs(f);
453}
455{
456 return ::trunc(f);
457}
459{
460 return ::sqrt(f);
461}
462
463
465{
466 return SLANG_PRELUDE_STD isnan(f);
467}
469{
470 return SLANG_PRELUDE_STD isfinite(f);
471}
473{
474 return SLANG_PRELUDE_STD isinf(f);
475}
476
477// Binary
478SLANG_FORCE_INLINE double F64_min(double a, double b)
479{
480 return ::fmin(a, b);
481}
482SLANG_FORCE_INLINE double F64_max(double a, double b)
483{
484 return ::fmax(a, b);
485}
486SLANG_FORCE_INLINE double F64_pow(double a, double b)
487{
488 return ::pow(a, b);
489}
490SLANG_FORCE_INLINE double F64_fmod(double a, double b)
491{
492 return ::fmod(a, b);
493}
494SLANG_FORCE_INLINE double F64_remainder(double a, double b)
495{
496 return ::remainder(a, b);
497}
498SLANG_FORCE_INLINE double F64_atan2(double a, double b)
499{
500 return ::atan2(a, b);
501}
502
503SLANG_FORCE_INLINE double F64_frexp(double x, int* e)
504{
505 return ::frexp(x, e);
506}
507
508SLANG_FORCE_INLINE double F64_modf(double x, double* ip)
509{
510 return ::modf(x, ip);
511}
512
513// Ternary
514SLANG_FORCE_INLINE double F64_fma(double a, double b, double c)
515{
516 return ::fma(a, b, c);
517}
518
519#endif // SLANG_LLVM
520
522{
523 return 1.0 / F64_sqrt(f);
524}
526{
527 return (f == 0.0) ? 0 : ((f < 0.0) ? -1 : 1);
528}
530{
531 return f - F64_floor(f);
532}
533
534SLANG_FORCE_INLINE void F64_asuint(double d, uint32_t* low, uint32_t* hi)
535{
536 Union64 u;
537 u.d = d;
538 *low = uint32_t(u.u);
539 *hi = uint32_t(u.u >> 32);
540}
541
542SLANG_FORCE_INLINE void F64_asint(double d, int32_t* low, int32_t* hi)
543{
544 Union64 u;
545 u.d = d;
546 *low = int32_t(u.u);
547 *hi = int32_t(u.u >> 32);
548}
549
551{
552 // Put 0 to 2pi cycles to cycle around 0 to 1
553 double a = radians * (1.0f / (SLANG_PRELUDE_PI * 2));
554 // Get truncated fraction, as value in 0 - 1 range
555 a = a - F64_floor(a);
556 // Convert back to 0 - 2pi range
557 return (a * (SLANG_PRELUDE_PI * 2));
558}
559
560// ----------------------------- F16 -----------------------------------------
561
562// This impl is based on FloatToHalf that is in Slang codebase
563SLANG_FORCE_INLINE uint32_t f32tof16(const float value)
564{
565 const uint32_t inBits = _bitCastFloatToUInt(value);
566
567 // bits initially set to just the sign bit
568 uint32_t bits = (inBits >> 16) & 0x8000;
569 // Mantissa can't be used as is, as it holds last bit, for rounding.
570 uint32_t m = (inBits >> 12) & 0x07ff;
571 uint32_t e = (inBits >> 23) & 0xff;
572
573 if (e < 103)
574 {
575 // It's zero
576 return bits;
577 }
578 if (e == 0xff)
579 {
580 // Could be a NAN or INF. Is INF if *input* mantissa is 0.
581
582 // Remove last bit for rounding to make output mantissa.
583 m >>= 1;
584
585 // We *assume* float16/float32 signaling bit and remaining bits
586 // semantics are the same. (The signalling bit convention is target specific!).
587 // Non signal bit's usage within mantissa for a NAN are also target specific.
588
589 // If the m is 0, it could be because the result is INF, but it could also be because all
590 // the bits that made NAN were dropped as we have less mantissa bits in f16.
591
592 // To fix for this we make non zero if m is 0 and the input mantissa was not.
593 // This will (typically) produce a signalling NAN.
594 m += uint32_t(m == 0 && (inBits & 0x007fffffu));
595
596 // Combine for output
597 return (bits | 0x7c00u | m);
598 }
599 if (e > 142)
600 {
601 // INF.
602 return bits | 0x7c00u;
603 }
604 if (e < 113)
605 {
606 m |= 0x0800u;
607 bits |= (m >> (114 - e)) + ((m >> (113 - e)) & 1);
608 return bits;
609 }
610 bits |= ((e - 112) << 10) | (m >> 1);
611 bits += m & 1;
612 return bits;
613}
614
615static const float g_f16tof32Magic = _bitCastIntToFloat((127 + (127 - 15)) << 23);
616
617SLANG_FORCE_INLINE float f16tof32(const uint32_t value)
618{
619 const uint32_t sign = (value & 0x8000) << 16;
620 uint32_t exponent = (value & 0x7c00) >> 10;
621 uint32_t mantissa = (value & 0x03ff);
622
623 if (exponent == 0)
624 {
625 // If mantissa is 0 we are done, as output is 0.
626 // If it's not zero we must have a denormal.
627 if (mantissa)
628 {
629 // We have a denormal so use the magic to do exponent adjust
630 return _bitCastIntToFloat(sign | ((value & 0x7fff) << 13)) * g_f16tof32Magic;
631 }
632 }
633 else
634 {
635 // If the exponent is NAN or INF exponent is 0x1f on input.
636 // If that's the case, we just need to set the exponent to 0xff on output
637 // and the mantissa can just stay the same. If its 0 it's INF, else it is NAN and we just
638 // copy the bits
639 //
640 // Else we need to correct the exponent in the normalized case.
641 exponent = (exponent == 0x1F) ? 0xff : (exponent + (-15 + 127));
642 }
643
644 return _bitCastUIntToFloat(sign | (exponent << 23) | (mantissa << 13));
645}
646
647#ifndef SLANG_LLVM
648#if __cplusplus >= 202302L
649#include <stdfloat> // C++23
650#else
651// Define __STDC_WANT_IEC_60559_TYPES_EXT__ for compilers with reliable _Float16 support:
652// - Clang 15+
653// - GCC 12+
654#if (defined(__clang__) && __clang_major__ >= 15) || (defined(__GNUC__) && __GNUC__ >= 12)
655#ifndef __STDC_WANT_IEC_60559_TYPES_EXT__
656#define __STDC_WANT_IEC_60559_TYPES_EXT__
657#endif
658#include <float.h>
659#endif // __STDC_WANT_IEC_60559_TYPES_EXT__
660#endif // (defined(__clang__) && __clang_major__ >= 15) || (defined(__GNUC__) && __GNUC__ >= 12)
661#endif // C++23
662
663#ifdef FLT16_MIN
664typedef _Float16 half;
665#elif __STDCPP_FLOAT16_T__ == 1
666typedef std::float16_t half;
667#else
668uint32_t f32tof16(const float value);
669float f16tof32(const uint32_t value);
670struct half
671{
672 uint16_t data;
673
674 half() = default;
675 explicit half(float f) { store(f); }
676
677 SLANG_FORCE_INLINE void store(float f) { data = f32tof16(f); }
678 SLANG_FORCE_INLINE float load() const { return f16tof32(data); }
679
680 half operator+(half other) const { return half(load() + other.load()); }
681 half operator-(half other) const { return half(load() - other.load()); }
682 half operator*(half other) const { return half(load() * other.load()); }
683 half operator/(half other) const { return half(load() / other.load()); }
685 {
686 store(load() + other.load());
687 return *this;
688 }
690 {
691 store(load() - other.load());
692 return *this;
693 }
695 {
696 store(load() * other.load());
697 return *this;
698 }
700 {
701 store(load() / other.load());
702 return *this;
703 }
704
705 bool operator<(half other) const { return load() < other.load(); }
706 bool operator>(half other) const { return load() > other.load(); }
707 bool operator<=(half other) const { return load() <= other.load(); }
708 bool operator>=(half other) const { return load() >= other.load(); }
709 bool operator==(half other) const { return load() == other.load(); }
710 bool operator!=(half other) const { return load() != other.load(); }
711
712 explicit operator float() const { return load(); }
713};
714#endif
715
716half U16_ashalf(uint16_t x);
717
719{
720 uint16_t u;
721 int16_t i;
723};
724
726{
727 Union16 u;
728 u.h = h;
729 return u.u;
730}
731
733{
734 Union16 u;
735 u.h = h;
736 return u.i;
737}
738
740{
741 return half(F32_ceil(float(f)));
742}
743
745{
746 return half(F32_floor(float(f)));
747}
748
750{
751 return half(F32_round(float(f)));
752}
753
755{
756 return half(F32_sin(float(f)));
757}
758
760{
761 return half(F32_cos(float(f)));
762}
763
765{
766 return half(F32_tan(float(f)));
767}
768
770{
771 return half(F32_asin(float(f)));
772}
773
775{
776 return half(F32_acos(float(f)));
777}
778
780{
781 return half(F32_atan(float(f)));
782}
783
785{
786 return half(F32_sinh(float(f)));
787}
788
790{
791 return half(F32_cosh(float(f)));
792}
793
795{
796 return half(F32_tanh(float(f)));
797}
798
800{
801 return half(F32_asinh(float(f)));
802}
803
805{
806 return half(F32_acosh(float(f)));
807}
808
810{
811 return half(F32_atanh(float(f)));
812}
813
815{
816 return half(F32_log2(float(f)));
817}
818
820{
821 return half(F32_log(float(f)));
822}
823
825{
826 return half(F32_log10(float(f)));
827}
828
830{
831 return half(F32_exp2(float(f)));
832}
833
835{
836 return half(F32_exp(float(f)));
837}
838
840{
841 return U16_ashalf(F16_asuint(f) & 0x7FFF);
842}
843
845{
846 return half(F32_trunc(float(f)));
847}
848
850{
851 return half(F32_sqrt(float(f)));
852}
853
855{
856 uint16_t u = F16_asuint(f);
857 return (u & 0x7C00) == 0x7C00 && (u & 0x3FF) != 0;
858}
859
861{
862 uint16_t u = F16_asuint(f);
863 return (u & 0x7C00) != 0x7C00;
864}
865
867{
868 uint16_t u = F16_asuint(f);
869 return (u & 0x7C00) == 0x7C00 && (u & 0x3FF) == 0;
870}
871
873{
874 if (F16_isnan(a))
875 return b;
876 if (F16_isnan(b))
877 return a;
878 return a < b ? a : b;
879}
880
882{
883 if (F16_isnan(a))
884 return b;
885 if (F16_isnan(b))
886 return a;
887 return a > b ? a : b;
888}
889
891{
892 return half(F32_pow(float(a), float(b)));
893}
894
896{
897 return half(F32_fmod(float(a), float(b)));
898}
899
901{
902 return half(F32_remainder(float(a), float(b)));
903}
904
906{
907 return half(F32_atan2(float(a), float(b)));
908}
909
911{
912 return half(F32_frexp(float(x), e));
913}
914
916{
917 float ipf;
918 float res = F32_modf(float(x), &ipf);
919 *ip = half(ipf);
920 return half(res);
921}
922
924{
925 return half(F32_fma(float(a), float(b), float(c)));
926}
927
929{
930 // Put 0 to 2pi cycles to cycle around 0 to 1
931 float a = float(radians) * (1.0f / float(SLANG_PRELUDE_PI * 2));
932 // Get truncated fraction, as value in 0 - 1 range
933 a = a - F32_floor(a);
934 // Convert back to 0 - 2pi range
935 return half(a * float(SLANG_PRELUDE_PI * 2));
936}
937
939{
940 return half(1.0f / F32_sqrt(float(f)));
941}
942
944{
945 uint16_t u = F16_asuint(f);
946 if ((u & 0x7FFF) == 0)
947 return 0;
948 return (u & 0x8000) != 0 ? -1 : 1;
949}
950
952{
953 float f = float(h);
954 return half(f - F32_floor(f));
955}
956
957// ----------------------------- U16 -----------------------------------------
959{
960#if SLANG_GCC_FAMILY && !defined(SLANG_LLVM)
961 return __builtin_popcount(uint32_t(v));
962#elif SLANG_PROCESSOR_X86_64 && SLANG_VC
963 return __popcnt16(v);
964#else
965 uint32_t c = 0;
966 while (v)
967 {
968 c++;
969 v &= v - 1;
970 }
971 return c;
972#endif
973}
974
976{
977 Union16 u;
978 u.u = x;
979 return u.h;
980}
981
982// ----------------------------- I16 -----------------------------------------
984{
985 return U16_countbits(uint16_t(v));
986}
987
988// ----------------------------- U8 -----------------------------------------
990{
991 // No native 8bit __popcnt yet, just cast and use 16bit variant
992 return U16_countbits(uint16_t(v));
993}
994
995// ----------------------------- I8 -----------------------------------------
997{
998 return U8_countbits(uint8_t(v));
999}
1000
1001// ----------------------------- U32 -----------------------------------------
1002
1003SLANG_FORCE_INLINE uint32_t U32_abs(uint32_t f)
1004{
1005 return f;
1006}
1007
1008SLANG_FORCE_INLINE uint32_t U32_min(uint32_t a, uint32_t b)
1009{
1010 return a < b ? a : b;
1011}
1012SLANG_FORCE_INLINE uint32_t U32_max(uint32_t a, uint32_t b)
1013{
1014 return a > b ? a : b;
1015}
1016
1018{
1019 Union32 u;
1020 u.u = x;
1021 return u.f;
1022}
1024{
1025 return uint32_t(x);
1026}
1027
1028SLANG_FORCE_INLINE double U32_asdouble(uint32_t low, uint32_t hi)
1029{
1030 Union64 u;
1031 u.u = (uint64_t(hi) << 32) | low;
1032 return u.d;
1033}
1034
1036{
1037#if SLANG_GCC_FAMILY && !defined(SLANG_LLVM)
1038 return __builtin_popcount(v);
1039#elif SLANG_PROCESSOR_X86_64 && SLANG_VC
1040 return __popcnt(v);
1041#else
1042 uint32_t c = 0;
1043 while (v)
1044 {
1045 c++;
1046 v &= v - 1;
1047 }
1048 return c;
1049#endif
1050}
1051
1053{
1054 if (v == 0)
1055 return ~0u;
1056
1057#if SLANG_GCC_FAMILY && !defined(SLANG_LLVM)
1058 // __builtin_ctz returns number of trailing zeros, which is the 0-based index of first set bit
1059 return __builtin_ctz(v);
1060#elif SLANG_PROCESSOR_X86_64 && SLANG_VC
1061 // _BitScanForward returns 1 on success, 0 on failure, and sets index
1062 unsigned long index;
1063 return _BitScanForward(&index, v) ? index : ~0u;
1064#else
1065 // Generic implementation - find first set bit
1066 uint32_t result = 0;
1067 while (result < 32 && !(v & (1u << result)))
1068 result++;
1069 return result;
1070#endif
1071}
1072
1074{
1075 if (v == 0)
1076 return ~0u;
1077#if SLANG_GCC_FAMILY && !defined(SLANG_LLVM)
1078 // __builtin_clz returns number of leading zeros
1079 // firstbithigh should return 0-based bit position of MSB
1080 return 31 - __builtin_clz(v);
1081#elif SLANG_PROCESSOR_X86_64 && SLANG_VC
1082 // _BitScanReverse returns 1 on success, 0 on failure, and sets index
1083 unsigned long index;
1084 return _BitScanReverse(&index, v) ? index : ~0u;
1085#else
1086 // Generic implementation - find highest set bit
1087 int result = 31;
1088 while (result >= 0 && !(v & (1u << result)))
1089 result--;
1090 return result;
1091#endif
1092}
1093
1095{
1096 v = ((v >> 1) & 0x55555555u) | ((v & 0x55555555u) << 1);
1097 v = ((v >> 2) & 0x33333333u) | ((v & 0x33333333u) << 2);
1098 v = ((v >> 4) & 0x0F0F0F0Fu) | ((v & 0x0F0F0F0Fu) << 4);
1099 v = ((v >> 8) & 0x00FF00FFu) | ((v & 0x00FF00FFu) << 8);
1100 v = (v >> 16) | (v << 16);
1101 return v;
1102}
1103
1104// ----------------------------- I32 -----------------------------------------
1105
1106SLANG_FORCE_INLINE int32_t I32_abs(int32_t f)
1107{
1108 return (f < 0) ? -f : f;
1109}
1110
1111SLANG_FORCE_INLINE int32_t I32_min(int32_t a, int32_t b)
1112{
1113 return a < b ? a : b;
1114}
1115SLANG_FORCE_INLINE int32_t I32_max(int32_t a, int32_t b)
1116{
1117 return a > b ? a : b;
1118}
1119
1121{
1122 Union32 u;
1123 u.i = x;
1124 return u.f;
1125}
1127{
1128 return uint32_t(x);
1129}
1130SLANG_FORCE_INLINE double I32_asdouble(int32_t low, int32_t hi)
1131{
1132 Union64 u;
1133 u.u = (uint64_t(hi) << 32) | uint32_t(low);
1134 return u.d;
1135}
1136
1138{
1139 return U32_countbits(uint32_t(v));
1140}
1141
1143{
1144 return U32_firstbitlow(uint32_t(v));
1145}
1146
1148{
1149 if (v < 0)
1150 v = ~v;
1151 return U32_firstbithigh(uint32_t(v));
1152}
1153
1155{
1156 return U32_reversebits(int32_t(v));
1157}
1158
1159// ----------------------------- U64 -----------------------------------------
1160
1161SLANG_FORCE_INLINE uint64_t U64_abs(uint64_t f)
1162{
1163 return f;
1164}
1165
1166SLANG_FORCE_INLINE uint64_t U64_min(uint64_t a, uint64_t b)
1167{
1168 return a < b ? a : b;
1169}
1170SLANG_FORCE_INLINE uint64_t U64_max(uint64_t a, uint64_t b)
1171{
1172 return a > b ? a : b;
1173}
1174
1176{
1177#if SLANG_GCC_FAMILY && !defined(SLANG_LLVM)
1178 return uint32_t(__builtin_popcountll(v));
1179#elif SLANG_PROCESSOR_X86_64 && SLANG_VC
1180 return uint32_t(__popcnt64(v));
1181#else
1182 uint32_t c = 0;
1183 while (v)
1184 {
1185 c++;
1186 v &= v - 1;
1187 }
1188 return c;
1189#endif
1190}
1191
1193{
1194 if (v == 0)
1195 return ~uint32_t(0);
1196
1197#if SLANG_GCC_FAMILY && !defined(SLANG_LLVM)
1198 // __builtin_ctz returns number of trailing zeros, which is the 0-based index of first set bit
1199 return __builtin_ctz(v);
1200#elif SLANG_PROCESSOR_X86_64 && SLANG_VC
1201 // _BitScanForward returns 1 on success, 0 on failure, and sets index
1202 unsigned long index;
1203 return _BitScanForward64(&index, v) ? index : ~uint32_t(0);
1204#else
1205 // Generic implementation - find first set bit
1206 uint32_t result = 0;
1207 while (result < 64 && !(v & (uint64_t(1) << result)))
1208 result++;
1209 return result;
1210#endif
1211}
1212
1214{
1215 if (v == 0)
1216 return ~uint32_t(0);
1217
1218#if SLANG_GCC_FAMILY && !defined(SLANG_LLVM)
1219 // __builtin_clz returns number of leading zeros
1220 // firstbithigh should return 0-based bit position of MSB
1221 return 63 - __builtin_clz(v);
1222#elif SLANG_PROCESSOR_X86_64 && SLANG_VC
1223 // _BitScanReverse returns 1 on success, 0 on failure, and sets index
1224 unsigned long index;
1225 return _BitScanReverse64(&index, v) ? index : ~uint32_t(0);
1226#else
1227 // Generic implementation - find highest set bit
1228 int result = 63;
1229 while (result >= 0 && !(v & (uint64_t(1) << result)))
1230 result--;
1231 return result;
1232#endif
1233}
1234
1236{
1237 v = ((v >> 1) & 0x5555555555555555ull) | ((v & 0x5555555555555555ull) << 1);
1238 v = ((v >> 2) & 0x3333333333333333ull) | ((v & 0x3333333333333333ull) << 2);
1239 v = ((v >> 4) & 0x0F0F0F0F0F0F0F0Full) | ((v & 0x0F0F0F0F0F0F0F0Full) << 4);
1240 v = ((v >> 8) & 0x00FF00FF00FF00FFull) | ((v & 0x00FF00FF00FF00FFull) << 8);
1241 v = ((v >> 16) & 0x0000FFFF0000FFFFull) | ((v & 0x0000FFFF0000FFFFull) << 16);
1242 v = (v >> 32) | (v << 32);
1243 return v;
1244}
1245
1246// ----------------------------- I64 -----------------------------------------
1247
1248SLANG_FORCE_INLINE int64_t I64_abs(int64_t f)
1249{
1250 return (f < 0) ? -f : f;
1251}
1252
1253SLANG_FORCE_INLINE int64_t I64_min(int64_t a, int64_t b)
1254{
1255 return a < b ? a : b;
1256}
1257SLANG_FORCE_INLINE int64_t I64_max(int64_t a, int64_t b)
1258{
1259 return a > b ? a : b;
1260}
1261
1263{
1264 return U64_countbits(uint64_t(v));
1265}
1266
1268{
1269 return U64_firstbitlow(uint64_t(v));
1270}
1271
1273{
1274 if (v < 0)
1275 v = ~v;
1276 return U64_firstbithigh(uint64_t(v));
1277}
1278
1280{
1281 return int64_t(U64_reversebits(uint64_t(v)));
1282}
1283
1284// ----------------------------- UPTR -----------------------------------------
1285
1287{
1288 return f;
1289}
1290
1292{
1293 return a < b ? a : b;
1294}
1295
1297{
1298 return a > b ? a : b;
1299}
1300
1301// ----------------------------- IPTR -----------------------------------------
1302
1304{
1305 return (f < 0) ? -f : f;
1306}
1307
1309{
1310 return a < b ? a : b;
1311}
1312
1314{
1315 return a > b ? a : b;
1316}
1317
1318// ----------------------------- Interlocked ---------------------------------
1319
1320#if SLANG_LLVM
1321
1322#else // SLANG_LLVM
1323
1324#ifdef _WIN32
1325#include <intrin.h>
1326#endif
1327
1328SLANG_FORCE_INLINE void InterlockedAdd(uint32_t* dest, uint32_t value, uint32_t* oldValue)
1329{
1330#ifdef _WIN32
1331 *oldValue = _InterlockedExchangeAdd((long*)dest, (long)value);
1332#else
1333 *oldValue = __sync_fetch_and_add(dest, value);
1334#endif
1335}
1336
1337#endif // SLANG_LLVM
1338
1339
1340// ----------------------- fmod --------------------------
1341SLANG_FORCE_INLINE float _slang_fmod(float x, float y)
1342{
1343 return F32_fmod(x, y);
1344}
1345SLANG_FORCE_INLINE double _slang_fmod(double x, double y)
1346{
1347 return F64_fmod(x, y);
1348}
1349
1350#ifdef SLANG_PRELUDE_NAMESPACE
1351}
1352#endif
1353
1354#endif
#define SLANG_PRELUDE_EXTERN_C_END
Definition slang-cpp-host-prelude.h:55
#define SLANG_PRELUDE_STD
Definition slang-cpp-host-prelude.h:22
#define SLANG_PRELUDE_EXTERN_C_START
Definition slang-cpp-host-prelude.h:54
#define SLANG_FORCE_INLINE
Definition slang-cpp-prelude.h:286
SLANG_FORCE_INLINE uint32_t U32_reversebits(uint32_t v)
Definition slang-cpp-scalar-intrinsics.h:1094
SLANG_FORCE_INLINE int32_t I32_abs(int32_t f)
Definition slang-cpp-scalar-intrinsics.h:1106
half U16_ashalf(uint16_t x)
Definition slang-cpp-scalar-intrinsics.h:975
SLANG_FORCE_INLINE float F32_rsqrt(float f)
Definition slang-cpp-scalar-intrinsics.h:290
SLANG_FORCE_INLINE int16_t F16_asint(half h)
Definition slang-cpp-scalar-intrinsics.h:732
SLANG_FORCE_INLINE double F64_modf(double x, double *ip)
Definition slang-cpp-scalar-intrinsics.h:508
SLANG_FORCE_INLINE half F16_exp(half f)
Definition slang-cpp-scalar-intrinsics.h:834
SLANG_FORCE_INLINE double F64_frexp(double x, int *e)
Definition slang-cpp-scalar-intrinsics.h:503
SLANG_FORCE_INLINE double F64_atan2(double a, double b)
Definition slang-cpp-scalar-intrinsics.h:498
SLANG_FORCE_INLINE uint32_t U32_max(uint32_t a, uint32_t b)
Definition slang-cpp-scalar-intrinsics.h:1012
SLANG_FORCE_INLINE intptr_t IPTR_max(intptr_t a, intptr_t b)
Definition slang-cpp-scalar-intrinsics.h:1313
SLANG_FORCE_INLINE double U32_asdouble(uint32_t low, uint32_t hi)
Definition slang-cpp-scalar-intrinsics.h:1028
SLANG_FORCE_INLINE double F64_exp(double f)
Definition slang-cpp-scalar-intrinsics.h:446
SLANG_FORCE_INLINE double F64_trunc(double f)
Definition slang-cpp-scalar-intrinsics.h:454
SLANG_FORCE_INLINE uintptr_t UPTR_max(uintptr_t a, uintptr_t b)
Definition slang-cpp-scalar-intrinsics.h:1296
SLANG_FORCE_INLINE half F16_acosh(half f)
Definition slang-cpp-scalar-intrinsics.h:804
SLANG_FORCE_INLINE half F16_fmod(half a, half b)
Definition slang-cpp-scalar-intrinsics.h:895
SLANG_FORCE_INLINE float F32_calcSafeRadians(float radians)
Definition slang-cpp-scalar-intrinsics.h:280
SLANG_FORCE_INLINE void F64_asint(double d, int32_t *low, int32_t *hi)
Definition slang-cpp-scalar-intrinsics.h:542
SLANG_FORCE_INLINE uint32_t I32_countbits(int32_t v)
Definition slang-cpp-scalar-intrinsics.h:1137
SLANG_FORCE_INLINE float F32_ceil(float f)
Definition slang-cpp-scalar-intrinsics.h:130
SLANG_FORCE_INLINE double F64_asin(double f)
Definition slang-cpp-scalar-intrinsics.h:406
SLANG_FORCE_INLINE uint32_t I64_firstbithigh(int64_t v)
Definition slang-cpp-scalar-intrinsics.h:1272
SLANG_FORCE_INLINE half F16_tan(half f)
Definition slang-cpp-scalar-intrinsics.h:764
SLANG_FORCE_INLINE intptr_t IPTR_min(intptr_t a, intptr_t b)
Definition slang-cpp-scalar-intrinsics.h:1308
SLANG_FORCE_INLINE int32_t I32_min(int32_t a, int32_t b)
Definition slang-cpp-scalar-intrinsics.h:1111
SLANG_FORCE_INLINE half F16_tanh(half f)
Definition slang-cpp-scalar-intrinsics.h:794
SLANG_FORCE_INLINE float F32_log2(float f)
Definition slang-cpp-scalar-intrinsics.h:190
SLANG_FORCE_INLINE uint32_t U64_firstbitlow(uint64_t v)
Definition slang-cpp-scalar-intrinsics.h:1192
SLANG_FORCE_INLINE uintptr_t UPTR_min(uintptr_t a, uintptr_t b)
Definition slang-cpp-scalar-intrinsics.h:1291
SLANG_FORCE_INLINE float F32_pow(float a, float b)
Definition slang-cpp-scalar-intrinsics.h:245
SLANG_FORCE_INLINE uintptr_t UPTR_abs(uintptr_t f)
Definition slang-cpp-scalar-intrinsics.h:1286
SLANG_FORCE_INLINE uint32_t I16_countbits(int16_t v)
Definition slang-cpp-scalar-intrinsics.h:983
SLANG_FORCE_INLINE float F32_log(float f)
Definition slang-cpp-scalar-intrinsics.h:194
SLANG_FORCE_INLINE uint32_t f32tof16(const float value)
Definition slang-cpp-scalar-intrinsics.h:563
SLANG_FORCE_INLINE float F32_log10(float f)
Definition slang-cpp-scalar-intrinsics.h:198
SLANG_FORCE_INLINE double F64_fma(double a, double b, double c)
Definition slang-cpp-scalar-intrinsics.h:514
SLANG_FORCE_INLINE double F64_pow(double a, double b)
Definition slang-cpp-scalar-intrinsics.h:486
SLANG_FORCE_INLINE half F16_atan2(half a, half b)
Definition slang-cpp-scalar-intrinsics.h:905
SLANG_FORCE_INLINE bool F16_isnan(half f)
Definition slang-cpp-scalar-intrinsics.h:854
SLANG_FORCE_INLINE double F64_log10(float f)
Definition slang-cpp-scalar-intrinsics.h:438
SLANG_FORCE_INLINE float F32_asinh(float f)
Definition slang-cpp-scalar-intrinsics.h:178
SLANG_FORCE_INLINE double F64_frac(double f)
Definition slang-cpp-scalar-intrinsics.h:529
SLANG_FORCE_INLINE uint32_t U32_firstbitlow(uint32_t v)
Definition slang-cpp-scalar-intrinsics.h:1052
SLANG_FORCE_INLINE float F32_asin(float f)
Definition slang-cpp-scalar-intrinsics.h:154
SLANG_FORCE_INLINE float F32_max(float a, float b)
Definition slang-cpp-scalar-intrinsics.h:241
SLANG_FORCE_INLINE half F16_frac(half h)
Definition slang-cpp-scalar-intrinsics.h:951
SLANG_FORCE_INLINE bool F16_isinf(half f)
Definition slang-cpp-scalar-intrinsics.h:866
SLANG_FORCE_INLINE half F16_frexp(half x, int *e)
Definition slang-cpp-scalar-intrinsics.h:910
SLANG_FORCE_INLINE double F64_cos(double f)
Definition slang-cpp-scalar-intrinsics.h:398
SLANG_FORCE_INLINE float F32_atan2(float a, float b)
Definition slang-cpp-scalar-intrinsics.h:257
SLANG_FORCE_INLINE bool F16_isfinite(half f)
Definition slang-cpp-scalar-intrinsics.h:860
SLANG_FORCE_INLINE float F32_frexp(float x, int *e)
Definition slang-cpp-scalar-intrinsics.h:262
SLANG_FORCE_INLINE float F32_exp2(float f)
Definition slang-cpp-scalar-intrinsics.h:202
SLANG_FORCE_INLINE bool F64_isnan(double f)
Definition slang-cpp-scalar-intrinsics.h:464
SLANG_FORCE_INLINE uint32_t U32_firstbithigh(uint32_t v)
Definition slang-cpp-scalar-intrinsics.h:1073
SLANG_FORCE_INLINE half F16_pow(half a, half b)
Definition slang-cpp-scalar-intrinsics.h:890
SLANG_FORCE_INLINE float _slang_fmod(float x, float y)
Definition slang-cpp-scalar-intrinsics.h:1341
SLANG_FORCE_INLINE half F16_cos(half f)
Definition slang-cpp-scalar-intrinsics.h:759
SLANG_FORCE_INLINE float F32_min(float a, float b)
Definition slang-cpp-scalar-intrinsics.h:237
SLANG_FORCE_INLINE half F16_sinh(half f)
Definition slang-cpp-scalar-intrinsics.h:784
SLANG_FORCE_INLINE uint32_t I64_firstbitlow(int64_t v)
Definition slang-cpp-scalar-intrinsics.h:1267
SLANG_FORCE_INLINE float F32_cos(float f)
Definition slang-cpp-scalar-intrinsics.h:146
SLANG_FORCE_INLINE int64_t I64_abs(int64_t f)
Definition slang-cpp-scalar-intrinsics.h:1248
SLANG_FORCE_INLINE double F64_acos(double f)
Definition slang-cpp-scalar-intrinsics.h:410
SLANG_FORCE_INLINE uint32_t U64_countbits(uint64_t v)
Definition slang-cpp-scalar-intrinsics.h:1175
SLANG_FORCE_INLINE half F16_asin(half f)
Definition slang-cpp-scalar-intrinsics.h:769
SLANG_FORCE_INLINE int64_t I64_min(int64_t a, int64_t b)
Definition slang-cpp-scalar-intrinsics.h:1253
SLANG_FORCE_INLINE uint64_t U64_reversebits(uint64_t v)
Definition slang-cpp-scalar-intrinsics.h:1235
SLANG_FORCE_INLINE half F16_modf(half x, half *ip)
Definition slang-cpp-scalar-intrinsics.h:915
SLANG_FORCE_INLINE double F64_log(double f)
Definition slang-cpp-scalar-intrinsics.h:434
SLANG_FORCE_INLINE half F16_sin(half f)
Definition slang-cpp-scalar-intrinsics.h:754
SLANG_FORCE_INLINE half F16_exp2(half f)
Definition slang-cpp-scalar-intrinsics.h:829
SLANG_FORCE_INLINE double F64_ceil(double f)
Definition slang-cpp-scalar-intrinsics.h:382
SLANG_FORCE_INLINE uint32_t _bitCastFloatToUInt(float f)
Definition slang-cpp-scalar-intrinsics.h:50
SLANG_FORCE_INLINE half F16_trunc(half f)
Definition slang-cpp-scalar-intrinsics.h:844
SLANG_FORCE_INLINE float F32_acos(float f)
Definition slang-cpp-scalar-intrinsics.h:158
SLANG_FORCE_INLINE half F16_log2(half f)
Definition slang-cpp-scalar-intrinsics.h:814
SLANG_FORCE_INLINE double F64_calcSafeRadians(double radians)
Definition slang-cpp-scalar-intrinsics.h:550
SLANG_FORCE_INLINE uint32_t U32_abs(uint32_t f)
Definition slang-cpp-scalar-intrinsics.h:1003
static const float g_f16tof32Magic
Definition slang-cpp-scalar-intrinsics.h:615
SLANG_FORCE_INLINE int F64_sign(double f)
Definition slang-cpp-scalar-intrinsics.h:525
SLANG_FORCE_INLINE int F16_sign(half f)
Definition slang-cpp-scalar-intrinsics.h:943
SLANG_FORCE_INLINE float F32_trunc(float f)
Definition slang-cpp-scalar-intrinsics.h:214
SLANG_FORCE_INLINE uint32_t U32_asint(int32_t x)
Definition slang-cpp-scalar-intrinsics.h:1023
SLANG_FORCE_INLINE double F64_tan(double f)
Definition slang-cpp-scalar-intrinsics.h:402
SLANG_FORCE_INLINE uint64_t U64_max(uint64_t a, uint64_t b)
Definition slang-cpp-scalar-intrinsics.h:1170
SLANG_FORCE_INLINE bool F64_isinf(double f)
Definition slang-cpp-scalar-intrinsics.h:472
SLANG_FORCE_INLINE uint32_t U16_countbits(uint16_t v)
Definition slang-cpp-scalar-intrinsics.h:958
SLANG_FORCE_INLINE half F16_round(half f)
Definition slang-cpp-scalar-intrinsics.h:749
SLANG_FORCE_INLINE bool F64_isfinite(double f)
Definition slang-cpp-scalar-intrinsics.h:468
SLANG_FORCE_INLINE uint32_t I8_countbits(int16_t v)
Definition slang-cpp-scalar-intrinsics.h:996
SLANG_FORCE_INLINE float F32_exp(float f)
Definition slang-cpp-scalar-intrinsics.h:206
SLANG_FORCE_INLINE float F32_fma(float a, float b, float c)
Definition slang-cpp-scalar-intrinsics.h:273
SLANG_FORCE_INLINE float F32_atan(float f)
Definition slang-cpp-scalar-intrinsics.h:162
SLANG_FORCE_INLINE void InterlockedAdd(uint32_t *dest, uint32_t value, uint32_t *oldValue)
Definition slang-cpp-scalar-intrinsics.h:1328
SLANG_FORCE_INLINE half F16_calcSafeRadians(half radians)
Definition slang-cpp-scalar-intrinsics.h:928
SLANG_FORCE_INLINE float f16tof32(const uint32_t value)
Definition slang-cpp-scalar-intrinsics.h:617
SLANG_FORCE_INLINE float F32_sin(float f)
Definition slang-cpp-scalar-intrinsics.h:142
SLANG_FORCE_INLINE float F32_floor(float f)
Definition slang-cpp-scalar-intrinsics.h:134
SLANG_FORCE_INLINE half F16_max(half a, half b)
Definition slang-cpp-scalar-intrinsics.h:881
SLANG_FORCE_INLINE half F16_log(half f)
Definition slang-cpp-scalar-intrinsics.h:819
SLANG_FORCE_INLINE float F32_tan(float f)
Definition slang-cpp-scalar-intrinsics.h:150
SLANG_FORCE_INLINE double F64_round(double f)
Definition slang-cpp-scalar-intrinsics.h:390
SLANG_FORCE_INLINE half F16_acos(half f)
Definition slang-cpp-scalar-intrinsics.h:774
SLANG_FORCE_INLINE float F32_cosh(float f)
Definition slang-cpp-scalar-intrinsics.h:170
SLANG_FORCE_INLINE float _bitCastIntToFloat(int32_t i)
Definition slang-cpp-scalar-intrinsics.h:44
SLANG_FORCE_INLINE float F32_atanh(float f)
Definition slang-cpp-scalar-intrinsics.h:186
SLANG_FORCE_INLINE double F64_remainder(double a, double b)
Definition slang-cpp-scalar-intrinsics.h:494
SLANG_FORCE_INLINE uint32_t I32_firstbitlow(int32_t v)
Definition slang-cpp-scalar-intrinsics.h:1142
SLANG_FORCE_INLINE bool F32_isnan(float f)
Definition slang-cpp-scalar-intrinsics.h:223
SLANG_FORCE_INLINE uint32_t F32_asuint(float f)
Definition slang-cpp-scalar-intrinsics.h:303
SLANG_FORCE_INLINE uint32_t I32_firstbithigh(int32_t v)
Definition slang-cpp-scalar-intrinsics.h:1147
SLANG_FORCE_INLINE int64_t I64_max(int64_t a, int64_t b)
Definition slang-cpp-scalar-intrinsics.h:1257
SLANG_FORCE_INLINE float F32_modf(float x, float *ip)
Definition slang-cpp-scalar-intrinsics.h:267
SLANG_FORCE_INLINE float _bitCastUIntToFloat(uint32_t ui)
Definition slang-cpp-scalar-intrinsics.h:56
SLANG_FORCE_INLINE double F64_atan(double f)
Definition slang-cpp-scalar-intrinsics.h:414
SLANG_FORCE_INLINE float F32_tanh(float f)
Definition slang-cpp-scalar-intrinsics.h:174
SLANG_FORCE_INLINE float F32_remainder(float a, float b)
Definition slang-cpp-scalar-intrinsics.h:253
SLANG_FORCE_INLINE int32_t F32_asint(float f)
Definition slang-cpp-scalar-intrinsics.h:309
SLANG_FORCE_INLINE half F16_atanh(half f)
Definition slang-cpp-scalar-intrinsics.h:809
SLANG_FORCE_INLINE float I32_asfloat(int32_t x)
Definition slang-cpp-scalar-intrinsics.h:1120
SLANG_FORCE_INLINE int F32_sign(float f)
Definition slang-cpp-scalar-intrinsics.h:294
SLANG_FORCE_INLINE float F32_fmod(float a, float b)
Definition slang-cpp-scalar-intrinsics.h:249
SLANG_FORCE_INLINE uint32_t U32_min(uint32_t a, uint32_t b)
Definition slang-cpp-scalar-intrinsics.h:1008
SLANG_FORCE_INLINE uint32_t U64_firstbithigh(uint64_t v)
Definition slang-cpp-scalar-intrinsics.h:1213
SLANG_FORCE_INLINE half F16_sqrt(half f)
Definition slang-cpp-scalar-intrinsics.h:849
SLANG_FORCE_INLINE uint32_t U8_countbits(uint8_t v)
Definition slang-cpp-scalar-intrinsics.h:989
SLANG_FORCE_INLINE half F16_cosh(half f)
Definition slang-cpp-scalar-intrinsics.h:789
SLANG_FORCE_INLINE half F16_asinh(half f)
Definition slang-cpp-scalar-intrinsics.h:799
SLANG_FORCE_INLINE uint32_t I64_countbits(int64_t v)
Definition slang-cpp-scalar-intrinsics.h:1262
SLANG_FORCE_INLINE intptr_t IPTR_abs(intptr_t f)
Definition slang-cpp-scalar-intrinsics.h:1303
SLANG_FORCE_INLINE float F32_abs(float f)
Definition slang-cpp-scalar-intrinsics.h:210
SLANG_FORCE_INLINE int32_t I32_max(int32_t a, int32_t b)
Definition slang-cpp-scalar-intrinsics.h:1115
SLANG_FORCE_INLINE half F16_abs(half f)
Definition slang-cpp-scalar-intrinsics.h:839
SLANG_FORCE_INLINE double F64_min(double a, double b)
Definition slang-cpp-scalar-intrinsics.h:478
SLANG_FORCE_INLINE float U32_asfloat(uint32_t x)
Definition slang-cpp-scalar-intrinsics.h:1017
SLANG_FORCE_INLINE uint32_t U32_countbits(uint32_t v)
Definition slang-cpp-scalar-intrinsics.h:1035
#define SLANG_PRELUDE_PI
Definition slang-cpp-scalar-intrinsics.h:20
SLANG_FORCE_INLINE uint32_t I32_asuint(int32_t x)
Definition slang-cpp-scalar-intrinsics.h:1126
SLANG_FORCE_INLINE void F64_asuint(double d, uint32_t *low, uint32_t *hi)
Definition slang-cpp-scalar-intrinsics.h:534
SLANG_FORCE_INLINE int32_t _bitCastFloatToInt(float f)
Definition slang-cpp-scalar-intrinsics.h:38
SLANG_FORCE_INLINE double F64_sinh(double f)
Definition slang-cpp-scalar-intrinsics.h:418
SLANG_FORCE_INLINE double F64_log2(double f)
Definition slang-cpp-scalar-intrinsics.h:430
SLANG_FORCE_INLINE bool F32_isinf(float f)
Definition slang-cpp-scalar-intrinsics.h:231
SLANG_FORCE_INLINE uint16_t F16_asuint(half h)
Definition slang-cpp-scalar-intrinsics.h:725
SLANG_FORCE_INLINE float F32_acosh(float f)
Definition slang-cpp-scalar-intrinsics.h:182
SLANG_FORCE_INLINE double F64_abs(double f)
Definition slang-cpp-scalar-intrinsics.h:450
SLANG_FORCE_INLINE double F64_exp2(double f)
Definition slang-cpp-scalar-intrinsics.h:442
SLANG_FORCE_INLINE half F16_rsqrt(half f)
Definition slang-cpp-scalar-intrinsics.h:938
SLANG_FORCE_INLINE double F64_sin(double f)
Definition slang-cpp-scalar-intrinsics.h:394
SLANG_FORCE_INLINE float F32_sinh(float f)
Definition slang-cpp-scalar-intrinsics.h:166
SLANG_FORCE_INLINE int32_t I32_reversebits(int32_t v)
Definition slang-cpp-scalar-intrinsics.h:1154
SLANG_FORCE_INLINE double F64_tanh(double f)
Definition slang-cpp-scalar-intrinsics.h:426
SLANG_FORCE_INLINE uint64_t U64_abs(uint64_t f)
Definition slang-cpp-scalar-intrinsics.h:1161
SLANG_FORCE_INLINE half F16_fma(half a, half b, half c)
Definition slang-cpp-scalar-intrinsics.h:923
SLANG_FORCE_INLINE double F64_cosh(double f)
Definition slang-cpp-scalar-intrinsics.h:422
SLANG_FORCE_INLINE half F16_min(half a, half b)
Definition slang-cpp-scalar-intrinsics.h:872
SLANG_FORCE_INLINE double I32_asdouble(int32_t low, int32_t hi)
Definition slang-cpp-scalar-intrinsics.h:1130
SLANG_FORCE_INLINE double F64_fmod(double a, double b)
Definition slang-cpp-scalar-intrinsics.h:490
SLANG_FORCE_INLINE half F16_atan(half f)
Definition slang-cpp-scalar-intrinsics.h:779
SLANG_FORCE_INLINE half F16_floor(half f)
Definition slang-cpp-scalar-intrinsics.h:744
SLANG_FORCE_INLINE uint64_t U64_min(uint64_t a, uint64_t b)
Definition slang-cpp-scalar-intrinsics.h:1166
SLANG_FORCE_INLINE double F64_sqrt(double f)
Definition slang-cpp-scalar-intrinsics.h:458
SLANG_FORCE_INLINE bool F32_isfinite(float f)
Definition slang-cpp-scalar-intrinsics.h:227
SLANG_FORCE_INLINE float F32_frac(float f)
Definition slang-cpp-scalar-intrinsics.h:298
SLANG_FORCE_INLINE float F32_sqrt(float f)
Definition slang-cpp-scalar-intrinsics.h:218
SLANG_FORCE_INLINE int64_t I64_reversebits(int64_t v)
Definition slang-cpp-scalar-intrinsics.h:1279
SLANG_FORCE_INLINE half F16_log10(half f)
Definition slang-cpp-scalar-intrinsics.h:824
SLANG_FORCE_INLINE float F32_round(float f)
Definition slang-cpp-scalar-intrinsics.h:138
SLANG_FORCE_INLINE double F64_max(double a, double b)
Definition slang-cpp-scalar-intrinsics.h:482
SLANG_FORCE_INLINE double F64_rsqrt(double f)
Definition slang-cpp-scalar-intrinsics.h:521
SLANG_FORCE_INLINE double F64_floor(double f)
Definition slang-cpp-scalar-intrinsics.h:386
SLANG_FORCE_INLINE half F16_remainder(half a, half b)
Definition slang-cpp-scalar-intrinsics.h:900
SLANG_FORCE_INLINE half F16_ceil(half f)
Definition slang-cpp-scalar-intrinsics.h:739
__INTPTR_TYPE__ intptr_t
Definition slang-llvm.h:146
__UINTPTR_TYPE__ uintptr_t
Definition slang-llvm.h:153
#define SLANG_PRELUDE_NAMESPACE
Definition slang-torch-prelude.h:52
Definition slang-cpp-scalar-intrinsics.h:671
half & operator*=(half other)
Definition slang-cpp-scalar-intrinsics.h:694
half operator*(half other) const
Definition slang-cpp-scalar-intrinsics.h:682
uint16_t data
Definition slang-cpp-scalar-intrinsics.h:672
half operator+(half other) const
Definition slang-cpp-scalar-intrinsics.h:680
half & operator/=(half other)
Definition slang-cpp-scalar-intrinsics.h:699
bool operator<(half other) const
Definition slang-cpp-scalar-intrinsics.h:705
SLANG_FORCE_INLINE void store(float f)
Definition slang-cpp-scalar-intrinsics.h:677
half & operator-=(half other)
Definition slang-cpp-scalar-intrinsics.h:689
half operator/(half other) const
Definition slang-cpp-scalar-intrinsics.h:683
half(float f)
Definition slang-cpp-scalar-intrinsics.h:675
bool operator>=(half other) const
Definition slang-cpp-scalar-intrinsics.h:708
SLANG_FORCE_INLINE float load() const
Definition slang-cpp-scalar-intrinsics.h:678
bool operator!=(half other) const
Definition slang-cpp-scalar-intrinsics.h:710
bool operator==(half other) const
Definition slang-cpp-scalar-intrinsics.h:709
bool operator<=(half other) const
Definition slang-cpp-scalar-intrinsics.h:707
bool operator>(half other) const
Definition slang-cpp-scalar-intrinsics.h:706
half operator-(half other) const
Definition slang-cpp-scalar-intrinsics.h:681
half & operator+=(half other)
Definition slang-cpp-scalar-intrinsics.h:684
half()=default
Definition slang-cpp-scalar-intrinsics.h:719
half h
Definition slang-cpp-scalar-intrinsics.h:722
int16_t i
Definition slang-cpp-scalar-intrinsics.h:721
uint16_t u
Definition slang-cpp-scalar-intrinsics.h:720
Definition slang-cpp-scalar-intrinsics.h:24
uint32_t u
Definition slang-cpp-scalar-intrinsics.h:25
int32_t i
Definition slang-cpp-scalar-intrinsics.h:26
float f
Definition slang-cpp-scalar-intrinsics.h:27
Definition slang-cpp-scalar-intrinsics.h:31
int64_t i
Definition slang-cpp-scalar-intrinsics.h:33
double d
Definition slang-cpp-scalar-intrinsics.h:34
uint64_t u
Definition slang-cpp-scalar-intrinsics.h:32