integrated support for binary16 = 16bit floating point numbers via half.hpp, IEEE 754-based half-precision floating-point library
This commit is contained in:
parent
899582b0c1
commit
24c7aa4846
@ -1,599 +0,0 @@
|
||||
5.93
|
||||
5.92
|
||||
5.9
|
||||
5.9
|
||||
5.89
|
||||
5.89
|
||||
5.87
|
||||
5.84
|
||||
5.83
|
||||
5.81
|
||||
5.79
|
||||
5.78
|
||||
5.76
|
||||
5.75
|
||||
5.74
|
||||
5.74
|
||||
5.73
|
||||
5.73
|
||||
5.72
|
||||
5.71
|
||||
5.71
|
||||
5.69
|
||||
5.69
|
||||
5.68
|
||||
5.66
|
||||
5.63
|
||||
5.62
|
||||
5.6
|
||||
5.58
|
||||
5.57
|
||||
5.55
|
||||
5.53
|
||||
5.51
|
||||
5.5
|
||||
5.47
|
||||
5.45
|
||||
5.42
|
||||
5.4
|
||||
5.38
|
||||
5.35
|
||||
5.31
|
||||
5.28
|
||||
5.27
|
||||
5.24
|
||||
5.19
|
||||
5.16
|
||||
5.14
|
||||
7.67
|
||||
5.06
|
||||
5.02
|
||||
5
|
||||
4.97
|
||||
4.92
|
||||
4.88
|
||||
4.86
|
||||
4.82
|
||||
4.77
|
||||
4.74
|
||||
4.7
|
||||
4.66
|
||||
4.62
|
||||
4.58
|
||||
4.54
|
||||
4.48
|
||||
4.43
|
||||
4.37
|
||||
4.31
|
||||
4.24
|
||||
4.18
|
||||
4.13
|
||||
4.06
|
||||
3.98
|
||||
3.91
|
||||
3.83
|
||||
3.77
|
||||
3.72
|
||||
3.64
|
||||
3.57
|
||||
3.51
|
||||
3.44
|
||||
3.39
|
||||
3.33
|
||||
3.28
|
||||
3.24
|
||||
3.17
|
||||
3.11
|
||||
3.06
|
||||
3.01
|
||||
2.96
|
||||
2.92
|
||||
2.88
|
||||
2.83
|
||||
2.79
|
||||
2.75
|
||||
2.71
|
||||
2.68
|
||||
2.64
|
||||
2.61
|
||||
2.59
|
||||
2.56
|
||||
5.11
|
||||
2.52
|
||||
2.51
|
||||
2.49
|
||||
2.48
|
||||
2.46
|
||||
2.46
|
||||
2.45
|
||||
2.44
|
||||
2.43
|
||||
2.42
|
||||
2.41
|
||||
2.4
|
||||
2.41
|
||||
2.39
|
||||
2.38
|
||||
2.35
|
||||
2.31
|
||||
2.26
|
||||
2.21
|
||||
2.16
|
||||
2.1
|
||||
2.05
|
||||
2.01
|
||||
1.94
|
||||
1.91
|
||||
1.84
|
||||
1.77
|
||||
1.73
|
||||
1.65
|
||||
1.59
|
||||
1.58
|
||||
1.55
|
||||
1.52
|
||||
1.53
|
||||
1.52
|
||||
1.5
|
||||
1.49
|
||||
1.47
|
||||
1.47
|
||||
1.47
|
||||
1.47
|
||||
1.48
|
||||
1.48
|
||||
1.48
|
||||
1.48
|
||||
1.48
|
||||
1.46
|
||||
1.44
|
||||
1.44
|
||||
1.43
|
||||
1.41
|
||||
1.41
|
||||
1.4
|
||||
1.38
|
||||
1.37
|
||||
1.36
|
||||
1.35
|
||||
1.33
|
||||
1.32
|
||||
1.31
|
||||
1.28
|
||||
1.27
|
||||
1.26
|
||||
1.24
|
||||
1.22
|
||||
1.21
|
||||
1.21
|
||||
1.19
|
||||
1.17
|
||||
1.16
|
||||
1.16
|
||||
1.13
|
||||
1.12
|
||||
1.12
|
||||
1.11
|
||||
1.09
|
||||
1.08
|
||||
1.07
|
||||
1.07
|
||||
1.05
|
||||
1.04
|
||||
1.03
|
||||
1.02
|
||||
1.01
|
||||
0.99
|
||||
0.98
|
||||
0.96
|
||||
0.95
|
||||
0.94
|
||||
0.9
|
||||
0.87
|
||||
0.84
|
||||
0.8
|
||||
0.79
|
||||
0.78
|
||||
0.75
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
|
Binary file not shown.
4
makefile
4
makefile
@ -4,8 +4,8 @@ RAW = ../raw/
|
||||
SRC = src/
|
||||
EXE = eatit
|
||||
|
||||
CCC = g++
|
||||
OPT = -O3 -Wall
|
||||
CCC = g++ -std=c++11
|
||||
OPT = -O3 -Wall -mavx -mno-tbm -mf16c -mno-f16c
|
||||
|
||||
$(EXE) : $(SRC)main.cpp $(SRC)raweat.hpp $(SRC)half_precision_floating_point.hpp
|
||||
$(CCC) $(OPT) $< -o $@
|
||||
|
4575
src/half.hpp
Normal file
4575
src/half.hpp
Normal file
File diff suppressed because it is too large
Load Diff
18
src/main.cpp
18
src/main.cpp
@ -43,8 +43,8 @@ int main(int argc, char* argv[])
|
||||
}
|
||||
|
||||
// convert unsigned char data in buffer to desired data type
|
||||
//eatraw.convert_data();
|
||||
eatraw.convert_data_16_bit_float();
|
||||
//eatraw.convert_data_32_bit_float();
|
||||
|
||||
// get array of encoded data
|
||||
std::vector<double> maindata = eatraw.get_data();
|
||||
@ -67,7 +67,21 @@ int main(int argc, char* argv[])
|
||||
std::cout<<std::hex<<bssc.to_ulong()<<"\n\n";
|
||||
|
||||
endian endi;
|
||||
std::cout<<(endi.little_endian()?"little endian":"big endian")<<"\n";
|
||||
std::cout<<(endi.little_endian()?"little endian":"big endian")<<"\n\n";
|
||||
|
||||
std::cout<<sizeof(long int)<<"\n";
|
||||
std::cout<<sizeof(int)<<"\n";
|
||||
std::cout<<sizeof(short int)<<"\n";
|
||||
std::cout<<sizeof(unsigned int)<<"\n";
|
||||
std::cout<<sizeof(unsigned short int)<<"\n";
|
||||
std::cout<<sizeof(half_float::half)<<"\n";
|
||||
|
||||
// short int myi = 34;
|
||||
// std::cout<<myi<<"\n";
|
||||
// float myfl = 0.0;
|
||||
// myfl = _cvtsh_ss(myi);
|
||||
////float _cvtsh_ss(unsigned short x);
|
||||
// std::cout<<myfl<<"\n";
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -6,12 +6,19 @@
|
||||
#include <assert.h>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
#include <vector>
|
||||
#include <iterator>
|
||||
#include <map>
|
||||
#include <cmath>
|
||||
|
||||
#include "half_precision_floating_point.hpp"
|
||||
// support for 16bit floats
|
||||
#include <emmintrin.h>
|
||||
#include <immintrin.h>
|
||||
//#include <f16cintrin.h>
|
||||
#include "half.hpp"
|
||||
//#include "half_precision_floating_point.hpp"
|
||||
#include "endian.hpp"
|
||||
|
||||
//---------------------------------------------------------------------------//
|
||||
@ -213,14 +220,14 @@ public:
|
||||
}
|
||||
|
||||
// convert actual measurement data
|
||||
void convert_data()
|
||||
void convert_data_32_bit_float()
|
||||
{
|
||||
assert ( (datsize_-28)%4 == 0 && "length of buffer is not a multiple of 4" );
|
||||
|
||||
unsigned long int totnumfl = (datsize_-28)/(int)sizeof(float);
|
||||
for ( unsigned long int numfl = 0; numfl < totnumfl; numfl++ )
|
||||
{
|
||||
// assuming 4 byte float
|
||||
// assuming 4 byte (32bit) float
|
||||
float num = 0.0;
|
||||
uint8_t* pnum = reinterpret_cast<uint8_t*>(&num);
|
||||
for ( int byi = 0; byi < (int)sizeof(float); byi++ )
|
||||
@ -238,39 +245,23 @@ public:
|
||||
// convert half-precision (16bit) floating point numbers
|
||||
void convert_data_16_bit_float()
|
||||
{
|
||||
// single (32bit) floating point number
|
||||
float fl = 0.0;
|
||||
assert ( (datsize_-28)%2 == 0 && "length of buffer is not a multiple of 2" );
|
||||
|
||||
unsigned long int totnumby = (datsize_-28)/2;
|
||||
for ( unsigned long int by = 0; by < totnumby; by++ )
|
||||
{
|
||||
// retrieve two bytes of floating point number
|
||||
std::vector<uint8_t> pnum;
|
||||
for ( int i = 0; i < 2; i++ ) pnum.push_back(datasec_["datas marker"][(unsigned long int)(28+by*2+i)]);
|
||||
|
||||
// obtain bitset
|
||||
std::bitset<8> byA(pnum[0]), byB(pnum[1]);
|
||||
|
||||
// TODO all following code only works for little endian!!
|
||||
|
||||
// sign
|
||||
float sign = byB[0];
|
||||
|
||||
// exponent of 16bit float
|
||||
long int expo = 0;
|
||||
for ( int i = 0; i < 5; i++ ) if ( byB[1+i] ) expo += pow(2.0,4-i);
|
||||
expo -= 15;
|
||||
|
||||
// convert to exponent of 32bit float
|
||||
|
||||
|
||||
// mantissa
|
||||
|
||||
|
||||
// declare bitset of float
|
||||
std::bitset<8> flA(0x00), flB(0x00), flC(0x00), flD(0x00);
|
||||
// declare single (16bit) floating point number
|
||||
half_float::half hfl;
|
||||
|
||||
// reinterpret bytes in buffer as memory of floating point number
|
||||
uint8_t* pnum = reinterpret_cast<uint8_t*>(&hfl);
|
||||
for ( int i = 0; i < (int)sizeof(half_float::half); i++ )
|
||||
{
|
||||
pnum[i] = (int)datasec_["datas marker"][(unsigned long int)(28+by*sizeof(half_float::half)+i)];
|
||||
}
|
||||
|
||||
// add number to array
|
||||
datmes_.push_back((double)hfl);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user