DataFormats
Math
src
libminifloat.cc
Go to the documentation of this file.
1
#include "
DataFormats/Math/interface/libminifloat.h
"
2
3
namespace
{
4
MiniFloatConverter
dummy
;
// so the constructor is called
5
}
6
uint32_t
MiniFloatConverter::mantissatable
[2048];
7
uint32_t
MiniFloatConverter::exponenttable
[64];
8
uint16_t
MiniFloatConverter::offsettable
[64];
9
uint16_t
MiniFloatConverter::basetable
[512];
10
uint8_t
MiniFloatConverter::shifttable
[512];
11
12
MiniFloatConverter::MiniFloatConverter
() {
13
static
bool
once =
false
;
14
if
(!once) {
15
filltables
();
16
once =
true
;
17
}
18
}
19
20
void
MiniFloatConverter::filltables
() {
21
// ==== mantissatable ===
22
// -- zero --
23
mantissatable
[0] = 0;
24
// -- denorm --
25
for
(
unsigned
int
i
= 1;
i
<= 1023; ++
i
) {
26
unsigned
int
m
= (
i
<< 13),
e
= 0;
27
while
(!(
m
& 0x00800000)) {
// While not normalized
28
e
-= 0x00800000;
// Decrement exponent (1<<23)
29
m
<<= 1;
// Shift mantissa
30
}
31
m
&= ~0x00800000;
// Clear leading 1 bit
32
e
+= 0x38800000;
// Adjust bias ((127-14)<<23)
33
mantissatable
[
i
] =
m
|
e
;
34
}
35
// -- norm --
36
for
(
unsigned
int
i
= 1024;
i
<= 2047; ++
i
) {
37
mantissatable
[
i
] = 0x38000000 + ((
i
- 1024) << 13);
38
}
39
// ==== exponenttable ===
40
exponenttable
[0] = 0;
41
for
(
unsigned
int
i
= 1;
i
<= 30; ++
i
)
42
exponenttable
[
i
] =
i
<< 23;
43
exponenttable
[31] = 0x47800000;
44
exponenttable
[32] = 0x80000000u;
45
for
(
unsigned
int
i
= 33;
i
<= 62; ++
i
)
46
exponenttable
[
i
] = 0x80000000u | ((
i
- 32) << 23);
47
exponenttable
[63] = 0xC7800000;
48
49
// ==== offsettable ====
50
for
(
unsigned
int
i
= 0;
i
<= 63; ++
i
)
51
offsettable
[
i
] = ((
i
== 0 ||
i
== 32) ? 0 : 1024);
52
53
// ==== basetable, shifttable ===
54
for
(
unsigned
i
= 0;
i
< 256; ++
i
) {
55
int
e
=
int
(
i
) - 127;
56
if
(
e
< -24) {
// Very small numbers map to zero
57
basetable
[
i
| 0x000] = 0x0000;
58
basetable
[
i
| 0x100] = 0x8000;
59
shifttable
[
i
| 0x000] = 24;
60
shifttable
[
i
| 0x100] = 24;
61
}
else
if
(
e
< -14) {
// Small numbers map to denorms
62
basetable
[
i
| 0x000] = (0x0400 >> (-
e
- 14));
63
basetable
[
i
| 0x100] = (0x0400 >> (-
e
- 14)) | 0x8000;
64
shifttable
[
i
| 0x000] = -
e
- 1;
65
shifttable
[
i
| 0x100] = -
e
- 1;
66
}
else
if
(
e
<= 15) {
// Normal numbers just lose precision
67
basetable
[
i
| 0x000] = ((
e
+ 15) << 10);
68
basetable
[
i
| 0x100] = ((
e
+ 15) << 10) | 0x8000;
69
shifttable
[
i
| 0x000] = 13;
70
shifttable
[
i
| 0x100] = 13;
71
}
else
if
(
e
< 128) {
// Large numbers map to Infinity
72
basetable
[
i
| 0x000] = 0x7C00;
73
basetable
[
i
| 0x100] = 0xFC00;
74
shifttable
[
i
| 0x000] = 24;
75
shifttable
[
i
| 0x100] = 24;
76
}
else
{
// Infinity and NaN's stay Infinity and NaN's
77
basetable
[
i
| 0x000] = 0x7C00;
78
basetable
[
i
| 0x100] = 0xFC00;
79
shifttable
[
i
| 0x000] = 13;
80
shifttable
[
i
| 0x100] = 13;
81
}
82
}
83
}
mps_fire.i
i
Definition:
mps_fire.py:355
MiniFloatConverter::shifttable
static uint8_t shifttable[512]
Definition:
libminifloat.h:177
MiniFloatConverter::mantissatable
static uint32_t mantissatable[2048]
Definition:
libminifloat.h:173
MiniFloatConverter::MiniFloatConverter
MiniFloatConverter()
Definition:
libminifloat.cc:12
libminifloat.h
MiniFloatConverter::basetable
static uint16_t basetable[512]
Definition:
libminifloat.h:176
visualization-live-secondInstance_cfg.m
m
Definition:
visualization-live-secondInstance_cfg.py:72
MiniFloatConverter
Definition:
libminifloat.h:9
MiniFloatConverter::offsettable
static uint16_t offsettable[64]
Definition:
libminifloat.h:175
createfilelist.int
int
Definition:
createfilelist.py:10
MiniFloatConverter::exponenttable
static uint32_t exponenttable[64]
Definition:
libminifloat.h:174
dummy
Definition:
DummySelector.h:38
MiniFloatConverter::filltables
static void filltables()
Definition:
libminifloat.cc:20
MillePedeFileConverter_cfg.e
e
Definition:
MillePedeFileConverter_cfg.py:37
Generated for CMSSW Reference Manual by
1.8.16