1
1
/* *************************** vectorfp16.h *******************************
2
2
* Author: Agner Fog
3
3
* Date created: 2022-05-03
4
- * Last modified: 2022-07-20
5
- * Version: 2.02.00
4
+ * Last modified: 2023-06-03
5
+ * Version: 2.02.01
6
6
* Project: vector class library
7
7
* Description:
8
8
* Header file defining half precision floating point vector classes
23
23
* g++ version 12.1 with binutils version 2.34
24
24
* Intel c++ compiler version 2022.0
25
25
*
26
- * (c) Copyright 2012-2022 Agner Fog.
26
+ * (c) Copyright 2012-2023 Agner Fog.
27
27
* Apache License version 2.0 or later.
28
28
*****************************************************************************/
29
29
@@ -687,24 +687,24 @@ static inline Vec8h change_sign(Vec8h const a) {
687
687
688
688
// conversions Vec8h <-> Vec4f
689
689
// extend precision: Vec8h -> Vec4f. upper half ignored
690
- Vec4f convert8h_4f (Vec8h h) {
690
+ static inline Vec4f convert8h_4f (Vec8h h) {
691
691
return _mm_cvtph_ps (_mm_castph_si128 (h));
692
692
}
693
693
694
694
// reduce precision: Vec4f -> Vec8h. upper half zero
695
- Vec8h convert4f_8h (Vec4f f) {
695
+ static inline Vec8h convert4f_8h (Vec4f f) {
696
696
return _mm_castsi128_ph (_mm_cvtps_ph (f, 0 ));
697
697
}
698
698
699
699
#if MAX_VECTOR_SIZE >= 256
700
700
// conversions Vec8h <-> Vec8f
701
701
// extend precision: Vec8h -> Vec8f
702
- Vec8f to_float (Vec8h h) {
702
+ static inline Vec8f to_float (Vec8h h) {
703
703
return _mm256_cvtph_ps (_mm_castph_si128 (h));
704
704
}
705
705
706
706
// reduce precision: Vec8f -> Vec8h
707
- Vec8h to_float16 (Vec8f f) {
707
+ static inline Vec8h to_float16 (Vec8f f) {
708
708
return _mm_castsi128_ph (_mm256_cvtps_ph (f, 0 ));
709
709
}
710
710
#endif
@@ -1308,7 +1308,7 @@ inline Vec16h pow<uint32_t>(Vec16h const x0, uint32_t const n) {
1308
1308
1309
1309
// implement as function pow(vector, const_int)
1310
1310
template <int n>
1311
- static inline Vec16h pow (Vec16h const a, Const_int_t<n>) {
1311
+ Vec16h pow (Vec16h const a, Const_int_t<n>) {
1312
1312
return pow_n<Vec16h, n>(a);
1313
1313
}
1314
1314
@@ -1422,7 +1422,7 @@ static inline Vec16h exp2(Vec16s const n) {
1422
1422
// Each index i0 - i15 is 1 for changing sign on the corresponding element, 0 for no change
1423
1423
template <int i0, int i1, int i2, int i3, int i4, int i5, int i6, int i7,
1424
1424
int i8, int i9, int i10, int i11, int i12, int i13, int i14, int i15>
1425
- static inline Vec16h change_sign (Vec16h const a) {
1425
+ Vec16h change_sign (Vec16h const a) {
1426
1426
if constexpr ((i0 | i1 | i2 | i3 | i4 | i5 | i6 | i7 | i8 | i9 | i10 | i11 | i12 | i13 | i14 | i15) == 0 ) return a;
1427
1427
__m256i mask = constant8ui<
1428
1428
(i0 ? 0x8000 : 0 ) | (i1 ? 0x80000000 : 0 ),
@@ -1443,12 +1443,12 @@ static inline Vec16h change_sign(Vec16h const a) {
1443
1443
*****************************************************************************/
1444
1444
#if MAX_VECTOR_SIZE >= 512
1445
1445
// extend precision: Vec8h -> Vec8f
1446
- Vec16f to_float (Vec16h h) {
1446
+ static inline Vec16f to_float (Vec16h h) {
1447
1447
return _mm512_cvtph_ps (_mm256_castph_si256 (h));
1448
1448
}
1449
1449
1450
1450
// reduce precision: Vec8f -> Vec8h
1451
- Vec16h to_float16 (Vec16f f) {
1451
+ static inline Vec16h to_float16 (Vec16f f) {
1452
1452
return _mm256_castsi256_ph (_mm512_cvtps_ph (f, 0 ));
1453
1453
}
1454
1454
#endif
@@ -1496,7 +1496,7 @@ static inline Vec16h extend_z(Vec8h a) {
1496
1496
// permute vector Vec16h
1497
1497
template <int i0, int i1, int i2, int i3, int i4, int i5, int i6, int i7,
1498
1498
int i8, int i9, int i10, int i11, int i12, int i13, int i14, int i15>
1499
- static inline Vec16h permute16 (Vec16h const a) {
1499
+ Vec16h permute16 (Vec16h const a) {
1500
1500
return _mm256_castsi256_ph (
1501
1501
permute16<i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12, i13, i14, i15> (
1502
1502
Vec16s (_mm256_castph_si256 (a))));
@@ -1512,7 +1512,7 @@ static inline Vec16h permute16(Vec16h const a) {
1512
1512
// permute and blend Vec16h
1513
1513
template <int i0, int i1, int i2, int i3, int i4, int i5, int i6, int i7,
1514
1514
int i8, int i9, int i10, int i11, int i12, int i13, int i14, int i15>
1515
- static inline Vec16h blend16 (Vec16h const a, Vec16h const b) {
1515
+ Vec16h blend16 (Vec16h const a, Vec16h const b) {
1516
1516
return _mm256_castsi256_ph (
1517
1517
blend16<i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12, i13, i14, i15> (
1518
1518
Vec16s (_mm256_castph_si256 (a)), Vec16s (_mm256_castph_si256 (b))));
@@ -1535,7 +1535,7 @@ static inline Vec16h lookup16 (Vec16s const index, Vec16h const table) {
1535
1535
}
1536
1536
1537
1537
template <int n>
1538
- static inline Vec16h lookup (Vec16s const index, void const * table) {
1538
+ Vec16h lookup (Vec16s const index, void const * table) {
1539
1539
return _mm256_castsi256_ph (lookup<n>(index , (void const *)(table)));
1540
1540
}
1541
1541
@@ -2063,7 +2063,7 @@ inline Vec32h pow<uint32_t>(Vec32h const x0, uint32_t const n) {
2063
2063
2064
2064
// implement as function pow(vector, const_int)
2065
2065
template <int n>
2066
- static inline Vec32h pow (Vec32h const a, Const_int_t<n>) {
2066
+ Vec32h pow (Vec32h const a, Const_int_t<n>) {
2067
2067
return pow_n<Vec32h, n>(a);
2068
2068
}
2069
2069
@@ -2178,7 +2178,7 @@ template <int i0, int i1, int i2, int i3, int i4, int i5, int i6, int i7,
2178
2178
int i8, int i9, int i10, int i11, int i12, int i13, int i14, int i15,
2179
2179
int i16, int i17, int i18, int i19, int i20, int i21, int i22, int i23,
2180
2180
int i24, int i25, int i26, int i27, int i28, int i29, int i30, int i31 >
2181
- static inline Vec32h change_sign (Vec32h const a) {
2181
+ Vec32h change_sign (Vec32h const a) {
2182
2182
if constexpr ((i0 | i1 | i2 | i3 | i4 | i5 | i6 | i7 | i8 | i9 | i10 | i11 | i12 | i13 | i14 | i15 |
2183
2183
i16 | i17 | i18 | i19 | i20 | i21 | i22 | i23 | i24 | i25 | i26 | i27 | i28 | i29 | i30 | i31)
2184
2184
== 0 ) return a;
@@ -2247,7 +2247,7 @@ template <int i0, int i1, int i2, int i3, int i4, int i5, int i6, int i7,
2247
2247
int i8, int i9, int i10, int i11, int i12, int i13, int i14, int i15,
2248
2248
int i16, int i17, int i18, int i19, int i20, int i21, int i22, int i23,
2249
2249
int i24, int i25, int i26, int i27, int i28, int i29, int i30, int i31 >
2250
- static inline Vec32h permute32 (Vec32h const a) {
2250
+ Vec32h permute32 (Vec32h const a) {
2251
2251
return _mm512_castsi512_ph (
2252
2252
permute32<i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12, i13, i14, i15,
2253
2253
i16, i17, i18, i19, i20, i21, i22, i23, i24, i25, i26, i27, i28, i29, i30, i31 > (
@@ -2266,7 +2266,7 @@ template <int i0, int i1, int i2, int i3, int i4, int i5, int i6, int i7,
2266
2266
int i8, int i9, int i10, int i11, int i12, int i13, int i14, int i15,
2267
2267
int i16, int i17, int i18, int i19, int i20, int i21, int i22, int i23,
2268
2268
int i24, int i25, int i26, int i27, int i28, int i29, int i30, int i31 >
2269
- static inline Vec32h blend32 (Vec32h const a, Vec32h const b) {
2269
+ Vec32h blend32 (Vec32h const a, Vec32h const b) {
2270
2270
return _mm512_castsi512_ph (
2271
2271
blend32<i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12, i13, i14, i15,
2272
2272
i16, i17, i18, i19, i20, i21, i22, i23, i24, i25, i26, i27, i28, i29, i30, i31 > (
@@ -2307,7 +2307,7 @@ static inline Vec32h lookup(Vec32s const index, void const * table) {
2307
2307
2308
2308
// pow(2,n)
2309
2309
template <typename V>
2310
- static inline V vh_pow2n (V const n) {
2310
+ V vh_pow2n (V const n) {
2311
2311
typedef decltype (roundi (n)) VI; // corresponding integer vector type
2312
2312
const _Float16 pow2_10 = 1024 .; // 2^10
2313
2313
const _Float16 bias = 15 .; // bias in exponent
@@ -2355,7 +2355,7 @@ inline Vec32h infinite_vech<Vec32h>() {
2355
2355
// BA: 0 for exp, 1 for 0.5*exp, 2 for pow(2,x), 10 for pow(10,x)
2356
2356
2357
2357
template <typename VTYPE, int M1, int BA>
2358
- static inline VTYPE exp_h (VTYPE const initial_x) {
2358
+ VTYPE exp_h (VTYPE const initial_x) {
2359
2359
2360
2360
// Taylor coefficients
2361
2361
const _Float16 P0expf = 1 .f /2 .f ;
@@ -2444,7 +2444,7 @@ static inline Vec32us unsigned_int_type(Vec32h) { return 0; }
2444
2444
// xx = input x (radians)
2445
2445
// cosret = return pointer (only if SC = 3)
2446
2446
template <typename VTYPE, int SC>
2447
- static inline VTYPE sincos_h (VTYPE * cosret, VTYPE const xx) {
2447
+ VTYPE sincos_h (VTYPE * cosret, VTYPE const xx) {
2448
2448
2449
2449
// define constants
2450
2450
const _Float16 dp1h = 1 .57031250f ; // pi/2 with lower bits of mantissa removed
0 commit comments