11 #ifndef L1TopoSimulationUtils_L1TOPODATATYPES_H
12 #define L1TopoSimulationUtils_L1TOPODATATYPES_H
28 if (
n >=
sizeof(
T) * 8)
29 return ~static_cast<T>(0);
30 return (
static_cast<T>(1) <<
n) - 1
ull;
35 typedef unsigned long long T;
36 T convert(
const unsigned long long&
v,
const unsigned& in_p,
const unsigned int& in_f,
37 const unsigned int& out_p,
const unsigned int& out_f);
57 for(
auto in =
b.rbegin(); in!=
b.rend(); ++in){
96 operator unsigned long long(){
114 for(
unsigned j=0;j<PREC;++j){
149 template<
unsigned P,
unsigned FF>
friend L1TopoDataTypes<P,FF>
operator*(
const int& factor, L1TopoDataTypes<P,FF>
d);
150 template<
unsigned P,
unsigned FF>
friend L1TopoDataTypes<P,FF>
operator*(L1TopoDataTypes<P,FF>
d,
const int& factor);
153 template<
unsigned P1,
unsigned F1,
unsigned P2,
unsigned F2>
friend L1TopoDataTypes<((P1-F1) > (P2-F2) ? (P1-F1) : (P2-F2)) + ((F1 > F2) ? F1 : F2), (F1 > F2) ? F1 : F2>
operator+(
const L1TopoDataTypes<P1,F1>& lhs,
const L1TopoDataTypes<P2,F2>& rhs);
156 template<
unsigned P1,
unsigned F1,
unsigned P2,
unsigned F2>
friend L1TopoDataTypes<((P1-F1) > (P2-F2) ? (P1-F1) : (P2-F2)) + ((F1 > F2) ? F1 : F2), (F1 > F2) ? F1 : F2>
operator-(
const L1TopoDataTypes<P1,F1> lhs,
const L1TopoDataTypes<P2,F2> rhs);
159 template<
unsigned P1,
unsigned F1> L1TopoDataTypes<P1+1,F1>
friend operator-(
const double& lhs,
const L1TopoDataTypes<P1,F1>& rhs);
161 template<
unsigned P1,
unsigned F1> L1TopoDataTypes<P1+1,F1>
friend operator-(
const L1TopoDataTypes<P1,F1>& lhs,
const double& rhs);
164 template<
unsigned P1,
unsigned F1> L1TopoDataTypes<P1+1,F1>
friend operator-(
const int& lhs,
const L1TopoDataTypes<P1,F1>& rhs);
166 template<
unsigned P1,
unsigned F1> L1TopoDataTypes<P1+1,F1>
friend operator-(
const L1TopoDataTypes<P1,F1>& lhs,
const int& rhs);
185 for(
int j=PREC-1;j>=0;--j){
188 os <<
"integer value " <<
d.m_tvalue <<
" binary " <<
out <<
" float " <<
d.to_float();
206 unsigned int prec()
const {
return PREC; }
207 unsigned int frac()
const {
return F; }
224 float to_float(
const T& va,
const unsigned int&
p,
const unsigned int&
f);
228 const unsigned int frac = (F1 > F2) ? F1 : F2;
229 const unsigned int digit = ((P1-F1) > (P2-F2)) ? (P1-F1) - 1 : (P2-F2) - 1;
240 const unsigned int frac = (F1 > F2) ? F1 : F2;
241 const unsigned int digit = ((P1-F1) > (P2-F2)) ? (P1-F1) - 1 : (P2-F2) - 1;
285 const unsigned int frac = (P1+P2-1 >
MAXBITS) ? (F2>F1 ? F2 - ((P1+P2-1) -
MAXBITS) : F1 - ((P1+P2-1) -
MAXBITS)) : ((F1 > F2) ? F1 : F2);
288 T lhsconvert = lhs.m_tvalue;
289 T rhsconvert = rhs.m_tvalue;
291 if((lhs.m_tvalue >> (P1-1
ull)) & 1
ull){
294 if((rhs.m_tvalue >> (P2-1
ull)) & 1
ull){
298 T lhsconvint =
convert(lhsconvert,P1,F1,P1-F1,0);
299 T rhsconvint =
convert(rhsconvert,P2,F2,P2-F2,0);
300 T lhsconvfrac =
convert(lhsconvert,P1,F1,F1+1,F1);
301 T rhsconvfrac =
convert(rhsconvert,P2,F2,F2+1,F2);
302 T prod_int = lhsconvint*rhsconvint;
303 T prod_frac = lhsconvfrac*rhsconvfrac;
304 T prod_mix1 = lhsconvint*rhsconvfrac;
305 T prod_mix2 = lhsconvfrac*rhsconvint;
310 if(!(((lhs.m_tvalue >> (P1-1
ull)) & 1
ull) ^ ((rhs.m_tvalue >> (P2-1
ull)) & 1
ull))){