-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathfloat_e_m_t_helper.h
134 lines (129 loc) · 3.82 KB
/
float_e_m_t_helper.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
// Configure FP type to use
#ifdef __PIPELINEC__
#include "float_e_m_t.h"
/*
#define float float_8_23_t
#define uint_to_float float_8_23_t_uint32
#define float_to_uint float_8_23_t_31_0
#define fabs(x) float_8_23_t_abs(x)
#define is_negative float_8_23_t_sign
#define RSQRT_MAGIC 0x5f3759df
*/
/*
// Working with worse pixel line errors? (no, prob compile err?)
#define float float_8_22_t
#define uint_to_float float_8_22_t_uint31
#define float_to_uint float_8_22_t_30_0
#define CHECKER_SHIFT 17 // Amount to shift in checker pattern calc
#define FP_ABS_MASK 0x3FFFFFFF
#define RSQRT_MAGIC 0x2F9BACEF
*/
/*
// Looks great
#define float float_8_21_t
#define uint_to_float float_8_21_t_uint30
#define float_to_uint float_8_21_t_29_0
#define CHECKER_SHIFT 16 // Amount to shift in checker pattern calc
#define FP_ABS_MASK 0x1FFFFFFF
#define RSQRT_MAGIC 0x17CDD677
*/
/*
// Completely broken in verilator? (prob not, compile err?)
#define float float_8_20_t
#define uint_to_float float_8_20_t_uint29
#define float_to_uint float_8_20_t_28_0
#define CHECKER_SHIFT 15 // Amount to shift in checker pattern calc
#define FP_ABS_MASK 0xFFFFFFF
#define RSQRT_MAGIC 0xBE6EB3B
*/
/*
// Looks great
#define float float_8_19_t
#define uint_to_float float_8_19_t_uint28
#define float_to_uint float_8_19_t_27_0
#define CHECKER_SHIFT 14 // Amount to shift in checker pattern calc
#define FP_ABS_MASK 0x7FFFFFF
#define RSQRT_MAGIC 0x5F3759D
*/
/*
// Looks great
#define float float_8_18_t
#define uint_to_float float_8_18_t_uint27
#define float_to_uint float_8_18_t_26_0
//#define CHECKER_SHIFT 13 // Amount to shift in checker pattern calc
#define FP_ABS_MASK 0x3FFFFFF
#define RSQRT_MAGIC 0x2F9BACE
*/
/*
// RAN OUT RAM SYNTHESIZING. Confirmed occurs again.
// Looks great in verilator
#define float float_8_17_t
#define uint_to_float float_8_17_t_uint26
#define float_to_uint float_8_17_t_25_0
#define FP_ABS_MASK 0x1FFFFFF
#define RSQRT_MAGIC 0x17CDD67
*/
/*
// Looks fine.
#define float float_8_16_t
#define uint_to_float float_8_16_t_uint25
#define float_to_uint float_8_16_t_24_0
//#define CHECKER_SHIFT 11 // Amount to shift in checker pattern calc
#define FP_ABS_MASK 0xFFFFFF
#define RSQRT_MAGIC 0xBE6EB3
*/
/*
// Completely broken in verilator? Confirmed again.
#define float float_8_15_t
#define uint_to_float float_8_15_t_uint24
#define float_to_uint float_8_15_t_23_0
#define CHECKER_SHIFT 10 // Amount to shift in checker pattern calc
#define FP_ABS_MASK 0x7FFFFF
#define RSQRT_MAGIC 0x5F3759
*/
#define float float_8_14_t
#define uint_to_float float_8_14_t_uint23
#define float_to_uint float_8_14_t_22_0
#define fabs(x) float_8_14_t_abs(x)
#define is_negative float_8_14_t_sign
#define RSQRT_MAGIC 0x2F9BAC
/*
#define float float_8_13_t
#define uint_to_float float_8_13_t_uint22
#define float_to_uint float_8_13_t_21_0
#define fabs(x) float_8_13_t_abs(x)
#define RSQRT_MAGIC 0x17CDD6
*/
/*
#define float float_8_12_t
#define uint_to_float float_8_12_t_uint21
#define float_to_uint float_8_12_t_20_0
#define fabs(x) float_8_12_t_abs(x)
#define RSQRT_MAGIC 0xBE6EB
*/
/*
// RAN OUT OF RAM SYNTHESIZING?
#define float float_8_11_t
#define uint_to_float float_8_11_t_uint20
#define float_to_uint float_8_11_t_19_0
#define CHECKER_SHIFT 6 // Amount to shift in checker pattern calc
#define FP_ABS_MASK 0x7FFFF
#define RSQRT_MAGIC 0x5F375
*/
/*
// Noticably too jagged
#define float float_8_10_t
#define uint_to_float float_8_10_t_uint19
#define float_to_uint float_8_10_t_18_0
#define CHECKER_SHIFT 5 // Amount to shift in checker pattern calc
#define FP_ABS_MASK 0x3FFFF
#define RSQRT_MAGIC 0x2F9BA
*/
inline float float_rsqrt( float number ) //should one more newton iteration
{
// https://en.wikipedia.org/wiki/Fast_inverse_square_root
float x2 = number << -1; // number*.5;
float conv_f = uint_to_float(RSQRT_MAGIC - (float_to_uint(number) >> 1));
return conv_f*(1.5 - conv_f*conv_f*x2);
}
#endif