This repository was archived by the owner on Aug 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsimdposit8.cpp
More file actions
84 lines (76 loc) · 1.54 KB
/
Copy pathsimdposit8.cpp
File metadata and controls
84 lines (76 loc) · 1.54 KB
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
/**
* ZPosit8 library
*
* Emanuele Ruffaldi 2017
*/
#include "simdposit8.hpp"
std::ostream & operator << (std::ostream & ons, const simd_posit8_32 & p)
{
ons << (std::array<float,32>)p;
return ons;
}
simd_posit8_32::simd_posit8_32(int a)
{
auto q = FPT(a).v;
std::cout << "initing from integer " << a << " back as " << (float)(FPT(FPT::DeepInit(),q)) << " as dec " << std::dec << (int)q << std::dec <<std::endl;
v = _mm256_set1_epi8(q);
}
simd_posit8_32::simd_posit8_32(float a)
{
auto q = FPT(a).v;
std::cout << "initing from float " << a << " back as " << (float)(FPT(FPT::DeepInit(),q)) << " as dec " << std::dec << (int)q << std::dec <<std::endl;
v = _mm256_set1_epi8(q);
}
/**
Positive NUmber families
00000000
..
00001100 = .1875
..
00010000 = .25
..
00011000 = 0.375
..
00100001 = 0.5
..
00110000 = 0.75
..
01000000 = 1
..
01010000 = 1.5
..
01100000 = 2
...
01110000 = 4
...
01111111 = max
10000000 = infinity
*/
simd_posit8_32::operator std::array<float,32>() const
{
std::array<float,32> r;
#if 0
union Q {
float f;
uint32_t i;
};
alignas(__m256i) int8_t idata[32]; // uint8 if using table
_mm256_store_si256((__m256i*)idata,v);
uint32_t * pp = (uint32_t*)&r[0];
for(int i = 0; i < 32; i++)
{
Q xyz;
xyz.f = (float)FPT(FPT::DeepInit(),idata[i]);
pp[i] = xyz.i;
}
#else
alignas(__m256i) uint8_t idata[32]; // uint8 if using table
_mm256_store_si256((__m256i*)idata,v);
uint32_t * pp = (uint32_t*)&r[0];
for(int i = 0; i < 32; i++)
{
pp[i] = posit8ns::op2float[idata[i]];
}
#endif
return r;
}