Skip to content

Commit

Permalink
Using static cons classes
Browse files Browse the repository at this point in the history
  • Loading branch information
bryates committed Dec 9, 2024
1 parent 701111f commit 4faf3ca
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
8 changes: 4 additions & 4 deletions TrackletAlgorithm/MatchEngineUnit.h
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,8 @@ inline void step(const VMStub<VMSType> stubmem[4][1<<(kNbitsrzbinMP+kNbitsphibin
#endif

inline void set_empty() {
empty_ = EmptyUnit[(readindex_,writeindex_)];
static const emptyUnitClass<MatchEngineUnitBase<VMProjType>::kNBitsBuffer> EmptyUnitClass;
empty_ = EmptyUnitClass.lut[(readindex_,writeindex_)];
//empty_ = emptyUnit<MatchEngineUnitBase<VMProjType>::kNBitsBuffer>()[(readindex_,writeindex_)];
}

Expand All @@ -292,7 +293,8 @@ inline void step(const VMStub<VMSType> stubmem[4][1<<(kNbitsrzbinMP+kNbitsphibin
}

inline bool nearFull() {
return NearFull[(readindex_,writeindex_)];
static const nearFull3Class<MatchEngineUnitBase<VMProjType>::kNBitsBuffer> NearFull3Class;
return NearFull3Class.lut[(readindex_,writeindex_)];
//return nearFull3Unit<MatchEngineUnitBase<VMProjType>::kNBitsBuffer>()[(readindex_,writeindex_)];
}

Expand Down Expand Up @@ -428,8 +430,6 @@ inline void advance() {
static constexpr int projfinezbits = VMProjectionBase<VMProjType>::kVMProjFineZSize;
static constexpr int stubfinephibits = VMStubBase<VMSType>::kVMSFinePhiSize;
static constexpr int stubfinezbits = VMStubBase<VMSType>::kVMSFineZSize;
const ap_uint<(1 << (2 * MatchEngineUnitBase<VMProjType>::kNBitsBuffer))> EmptyUnit = emptyUnit<MatchEngineUnitBase<VMProjType>::kNBitsBuffer>();
const ap_uint<(1 << (2 * MatchEngineUnitBase<VMProjType>::kNBitsBuffer))> NearFull = nearFull3Unit<MatchEngineUnitBase<VMProjType>::kNBitsBuffer>();


#ifndef __SYNTHESIS__
Expand Down
37 changes: 36 additions & 1 deletion TrackletAlgorithm/MatchEngineUnit_parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,28 @@ static bool nearFullUnitBool(ap_uint<kNBitsBuffer> rptr, ap_uint<kNBitsBuffer> w
return wptr1==rptr || wptr2==rptr;
}

template<int kNBitsBuffer>
class nearFull3Class {
public:
ap_uint<(1 << (2 * kNBitsBuffer))> lut;
nearFull3Class() {
for (unsigned int i = 0; i < (1 << (2 * kNBitsBuffer)); i++) {
// Store complicated calculation in LUT array
ap_uint<kNBitsBuffer> wptr, rptr;
ap_uint<2 * kNBitsBuffer> address(i);
(rptr,wptr) = address;
ap_uint<kNBitsBuffer> wptr1 = wptr+1;
ap_uint<kNBitsBuffer> wptr2 = wptr+2;
ap_uint<kNBitsBuffer> wptr3 = wptr+3;
bool result = wptr1==rptr || wptr2==rptr || wptr3==rptr;
lut[i] = result;
}
}
};

template<int kNBitsBuffer>
static const ap_uint<(1 << (2 * kNBitsBuffer))> nearFull3Unit() {
ap_uint<(1 << (2 * kNBitsBuffer))> lut;
static ap_uint<(1 << (2 * kNBitsBuffer))> lut;
for(int i = 0; i < (1 << (2 * kNBitsBuffer)); ++i) {
#pragma HLS unroll
ap_uint<kNBitsBuffer> wptr, rptr;
Expand Down Expand Up @@ -80,6 +99,22 @@ static bool nearFull4UnitBool(ap_uint<kNBitsBuffer> rptr, ap_uint<kNBitsBuffer>
return wptr1==rptr || wptr2==rptr || wptr3==rptr || wptr4==rptr;
}

template<int kNBitsBuffer>
class emptyUnitClass {
public:
ap_uint<(1 << (2 * kNBitsBuffer))> lut;
emptyUnitClass() {
for (unsigned int i = 0; i < (1 << (2 * kNBitsBuffer)); i++) {
// Store complicated calculation in LUT array
ap_uint<kNBitsBuffer> wptr, rptr;
ap_uint<2 * kNBitsBuffer> address(i);
(rptr,wptr) = address;
bool result = wptr==rptr;
lut[i] = result;
}
}
};

template<int kNBitsBuffer>
static const ap_uint<(1 << (2 * kNBitsBuffer))> emptyUnit() {
ap_uint<(1 << (2 * kNBitsBuffer))> lut;
Expand Down

0 comments on commit 4faf3ca

Please sign in to comment.