CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
MiniFloatConverter::ReduceMantissaToNbitsRounding Class Reference

#include <libminifloat.h>

Public Member Functions

float operator() (float f) const
 
 ReduceMantissaToNbitsRounding (int bits)
 

Private Attributes

const uint32_t mask
 
const uint32_t maxn
 
const int shift
 
const uint32_t test
 

Detailed Description

Definition at line 71 of file libminifloat.h.

Constructor & Destructor Documentation

◆ ReduceMantissaToNbitsRounding()

MiniFloatConverter::ReduceMantissaToNbitsRounding::ReduceMantissaToNbitsRounding ( int  bits)
inline

Definition at line 73 of file libminifloat.h.

74  : shift(23 - bits), mask((0xFFFFFFFF >> (shift)) << (shift)), test(1 << (shift - 1)), maxn((1 << bits) - 2) {
75  assert(bits <= 23); // "max mantissa size is 23 bits"
76  }

References cms::cuda::assert().

Member Function Documentation

◆ operator()()

float MiniFloatConverter::ReduceMantissaToNbitsRounding::operator() ( float  f) const
inline

Definition at line 77 of file libminifloat.h.

77  {
78  constexpr uint32_t low23 = (0x007FFFFF); // mask to keep lowest 23 bits = mantissa
79  constexpr uint32_t hi9 = (0xFF800000); // mask to keep highest 9 bits = the rest
80  union {
81  float flt;
82  uint32_t i32;
83  } conv;
84  conv.flt = f;
85  if (conv.i32 & test) { // need to round
86  uint32_t mantissa = (conv.i32 & low23) >> shift;
87  if (mantissa < maxn)
88  mantissa++;
89  conv.i32 = (conv.i32 & hi9) | (mantissa << shift);
90  } else {
91  conv.i32 &= mask;
92  }
93  return conv.flt;
94  }

References conv, f, mask, maxn, and shift.

Member Data Documentation

◆ mask

const uint32_t MiniFloatConverter::ReduceMantissaToNbitsRounding::mask
private

Definition at line 98 of file libminifloat.h.

Referenced by operator()().

◆ maxn

const uint32_t MiniFloatConverter::ReduceMantissaToNbitsRounding::maxn
private

Definition at line 98 of file libminifloat.h.

Referenced by operator()().

◆ shift

const int MiniFloatConverter::ReduceMantissaToNbitsRounding::shift
private

Definition at line 97 of file libminifloat.h.

Referenced by operator()().

◆ test

const uint32_t MiniFloatConverter::ReduceMantissaToNbitsRounding::test
private
MiniFloatConverter::ReduceMantissaToNbitsRounding::mask
const uint32_t mask
Definition: libminifloat.h:98
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
conv
static HepMC::IO_HEPEVT conv
Definition: BeamHaloProducer.cc:48
cms::cuda::assert
assert(be >=bs)
test
Definition: SmallWORMDict.h:13
MiniFloatConverter::ReduceMantissaToNbitsRounding::shift
const int shift
Definition: libminifloat.h:97
MiniFloatConverter::ReduceMantissaToNbitsRounding::test
const uint32_t test
Definition: libminifloat.h:98
MiniFloatConverter::ReduceMantissaToNbitsRounding::maxn
const uint32_t maxn
Definition: libminifloat.h:98