909 lines
27 KiB
C++
909 lines
27 KiB
C++
#include "SSProc.h"
|
||
#include "stdlib.h"
|
||
#include <cstdint>
|
||
|
||
void SSProcAndNF(
|
||
hls::stream<SLRMatchOutput> &inMatchPt,
|
||
hls::stream<LRMatchedPoint> &outLRPt,
|
||
ap_uint<1> enable_SS_proc
|
||
)
|
||
{
|
||
#if !(VITIS_HLS)
|
||
#pragma HLS DATA_PACK variable=inMatchPt
|
||
#pragma HLS DATA_PACK variable=outLRPt
|
||
#else
|
||
#pragma HLS aggregate variable=inMatchPt compact=bit
|
||
#pragma HLS aggregate variable=outLRPt compact=bit
|
||
#endif
|
||
#pragma HLS INTERFACE axis register both port=inMatchPt
|
||
#pragma HLS INTERFACE axis register both port=outLRPt
|
||
#pragma HLS INTERFACE mode=ap_none port=enable_SS_proc register
|
||
|
||
static SRowData left_buf[ROW_COUNT]; //size = 4k * 72 = 288kbit, RAM36 * 8
|
||
#pragma HLS BIND_STORAGE variable=left_buf type=ram_2p impl=bram
|
||
#pragma HLS RESET variable=left_buf off
|
||
static SRowData right_buf[ROW_COUNT];
|
||
#pragma HLS BIND_STORAGE variable=right_buf type=ram_2p impl=bram
|
||
#pragma HLS RESET variable=right_buf off
|
||
static SLineMatchInfo matchInfo_buf[ROW_COUNT];
|
||
#pragma HLS BIND_STORAGE variable=matchInfo_buf type=ram_2p impl=bram
|
||
#pragma HLS RESET variable=matchInfo_buf off
|
||
|
||
// No per-frame clear: receive overwrites every row used by either pass.
|
||
// Input protocol: dense rows, valid header bounds, matchNum/ptNum <= 2.
|
||
SLRMatchOutput InData;
|
||
ap_uint<2> VSync;
|
||
while(1) //wait for vSync signal
|
||
{
|
||
#pragma HLS LOOP_TRIPCOUNT min=1 max=1
|
||
InData = inMatchPt.read();
|
||
VSync = InData.syncWord;
|
||
if(0b10 == VSync) //wait for syncFirst
|
||
break;
|
||
}
|
||
|
||
uint32_t frmNo, timeStamp, encInfo;
|
||
uint16_t minY, maxY;
|
||
UintFloat inTmp;
|
||
inTmp.fdata = InData.left_pt1.x;
|
||
frmNo = inTmp.unData;
|
||
inTmp.fdata = InData.left_pt2.x;
|
||
timeStamp = inTmp.unData;
|
||
inTmp.fdata = InData.right_pt1.x;
|
||
encInfo = inTmp.unData;
|
||
inTmp.fdata = InData.right_pt2.x;
|
||
minY = inTmp.unData & 0xffff;
|
||
maxY = inTmp.unData >> 16;
|
||
|
||
const uint16_t header_max_y = maxY;
|
||
const bool valid_range = minY <= maxY && maxY < ROW_COUNT;
|
||
bool received_rows = false;
|
||
uint16_t total_match_size = 0;
|
||
SS_RECEIVE:
|
||
for(uint16_t n = minY; valid_range && n <= header_max_y; n ++)
|
||
{
|
||
#pragma HLS LOOP_TRIPCOUNT min=1 max=3072
|
||
#pragma HLS PIPELINE II=1
|
||
|
||
InData = inMatchPt.read();
|
||
SRowData left_line, right_line;
|
||
left_line.ptNum = InData.left_ptNum;
|
||
left_line.pt1 = InData.left_pt1;
|
||
left_line.pt2 = InData.left_pt2;
|
||
right_line.ptNum = InData.right_ptNum;
|
||
right_line.pt1 = InData.right_pt1;
|
||
right_line.pt2 = InData.right_pt2;
|
||
|
||
SLineMatchInfo line_match;
|
||
line_match = InData.matchInfo;
|
||
left_buf[n] = left_line;
|
||
right_buf[n] = right_line;
|
||
matchInfo_buf[n] = line_match;
|
||
|
||
total_match_size += line_match.matchNum;
|
||
received_rows = true;
|
||
maxY = n; // Only scan rows received in this invocation.
|
||
|
||
if(0b11 == InData.syncWord)
|
||
{
|
||
break;
|
||
}
|
||
}
|
||
|
||
//step 4: single side processing, target II = 2 (top-down + bottom-up)
|
||
//single side processing
|
||
if(enable_SS_proc == 1 && received_rows)
|
||
{
|
||
SPointMatchInfo null_match;
|
||
null_match.match_flag = 0;
|
||
null_match.match_seg_id = 0;
|
||
null_match.pt_idx_L = 0;
|
||
null_match.pt_idx_R = 0;
|
||
null_match.rid_L = 0;
|
||
null_match.rid_R = 0;
|
||
|
||
//top - down
|
||
SPointMatchInfo match1 = null_match;
|
||
SPointMatchInfo match2 = null_match;
|
||
|
||
SS_TOP_DOWN:
|
||
for(uint16_t i = minY; i <= maxY; i ++)
|
||
{
|
||
#pragma HLS LOOP_TRIPCOUNT min=1 max=3072
|
||
#pragma HLS PIPELINE II=2
|
||
|
||
SRowData line_L = left_buf[i];
|
||
SRowData line_R = right_buf[i];
|
||
SLineMatchInfo a_lineMatch = matchInfo_buf[i];
|
||
SLineMatchInfo update_match = a_lineMatch;
|
||
ap_uint<2> flag_L1 = line_L.pt1.matchFlag;
|
||
ap_uint<2> flag_L2 = line_L.pt2.matchFlag;
|
||
ap_uint<2> flag_R1 = line_R.pt1.matchFlag;
|
||
ap_uint<2> flag_R2 = line_R.pt2.matchFlag;
|
||
|
||
SPointMatchInfo pre_m1 = match1;
|
||
SPointMatchInfo pre_m2 = match2;
|
||
|
||
SPointMatchInfo curr_m1 = a_lineMatch.match1;
|
||
SPointMatchInfo curr_m2 = a_lineMatch.match2;
|
||
|
||
ap_uint<2> m1_newMatch = 0;
|
||
ap_uint<2> m2_newMatch = 0;
|
||
SPointMatchInfo new_m1 = null_match;
|
||
SPointMatchInfo new_m2 = null_match;
|
||
|
||
//single side match
|
||
if(pre_m1.match_flag > 0)
|
||
{
|
||
if( (curr_m1.match_flag > 0) && (pre_m1.rid_L == curr_m1.rid_L) && (pre_m1.rid_R == curr_m1.rid_R)) //m1 <-> left_pt1
|
||
{
|
||
new_m1 = curr_m1;
|
||
m1_newMatch = 2; //inherit
|
||
}
|
||
else if ( (curr_m1.match_flag > 0) && (pre_m1.rid_L == curr_m1.rid_L) && (pre_m1.rid_R != curr_m1.rid_R))
|
||
{
|
||
m1_newMatch = 0;
|
||
}
|
||
else if ( (curr_m1.match_flag > 0) && (pre_m1.rid_L != curr_m1.rid_L) && (pre_m1.rid_R == curr_m1.rid_R))
|
||
{
|
||
m1_newMatch = 0;
|
||
}
|
||
else if( (curr_m2.match_flag > 0) && (pre_m1.rid_L == curr_m2.rid_L) && (pre_m1.rid_R == curr_m2.rid_R)) //m1 <-> left_pt1
|
||
{
|
||
new_m1 = curr_m2;
|
||
m1_newMatch = 2; //inherit
|
||
}
|
||
else if( (curr_m2.match_flag > 0) && (pre_m1.rid_L == curr_m2.rid_L) && (pre_m1.rid_R != curr_m2.rid_R)) //m1 <-> left_pt1
|
||
{
|
||
m1_newMatch = 0;
|
||
}
|
||
else if( (curr_m2.match_flag > 0) && (pre_m1.rid_L != curr_m2.rid_L) && (pre_m1.rid_R == curr_m2.rid_R)) //m1 <-> left_pt1
|
||
{
|
||
m1_newMatch = 0;
|
||
}
|
||
//start single side match check
|
||
else if( (line_L.ptNum >= 1) && (pre_m1.rid_L != 0) && (pre_m1.rid_L == line_L.pt1.rid) && (line_L.pt1.matchFlag == 0))
|
||
{
|
||
m1_newMatch = 1; //new single side
|
||
new_m1.match_flag = 2;
|
||
new_m1.match_seg_id = pre_m1.match_seg_id;
|
||
new_m1.pt_idx_L = 1;
|
||
new_m1.pt_idx_R = 0;
|
||
new_m1.rid_L = pre_m1.rid_L;
|
||
new_m1.rid_R = pre_m1.rid_R;
|
||
}
|
||
else if( (line_L.ptNum >= 2) && (pre_m1.rid_L != 0) && (pre_m1.rid_L == line_L.pt2.rid) && (line_L.pt2.matchFlag == 0))
|
||
{
|
||
m1_newMatch = 1; //new single side
|
||
new_m1.match_flag = 2;
|
||
new_m1.match_seg_id = pre_m1.match_seg_id;
|
||
new_m1.pt_idx_L = 2;
|
||
new_m1.pt_idx_R = 0;
|
||
new_m1.rid_L = pre_m1.rid_L;
|
||
new_m1.rid_R = pre_m1.rid_R;
|
||
}
|
||
else if( (line_R.ptNum >= 1) && (pre_m1.rid_R != 0) && (pre_m1.rid_R == line_R.pt1.rid) && (line_R.pt1.matchFlag == 0))
|
||
{
|
||
m1_newMatch = 1; //new single side
|
||
new_m1.match_flag = 3;
|
||
new_m1.match_seg_id = pre_m1.match_seg_id;
|
||
new_m1.pt_idx_L = 0;
|
||
new_m1.pt_idx_R = 1;
|
||
new_m1.rid_L = pre_m1.rid_L;
|
||
new_m1.rid_R = pre_m1.rid_R;
|
||
}
|
||
else if( (line_R.ptNum >= 2) && (pre_m1.rid_R != 0) && (pre_m1.rid_R == line_R.pt2.rid) && (line_R.pt2.matchFlag == 0))
|
||
{
|
||
m1_newMatch = 1; //new single side
|
||
new_m1.match_flag = 3;
|
||
new_m1.match_seg_id = pre_m1.match_seg_id;
|
||
new_m1.pt_idx_L = 0;
|
||
new_m1.pt_idx_R = 2;
|
||
new_m1.rid_L = pre_m1.rid_L;
|
||
new_m1.rid_R = pre_m1.rid_R;
|
||
}
|
||
}
|
||
|
||
//2nd
|
||
if(pre_m2.match_flag > 0)
|
||
{
|
||
if( (curr_m1.match_flag > 0) && (pre_m2.rid_L == curr_m1.rid_L) && (pre_m2.rid_R == curr_m1.rid_R)) //m1 <-> left_pt1
|
||
{
|
||
new_m2 = curr_m1;
|
||
m2_newMatch = 2; //inherit
|
||
}
|
||
else if ( (curr_m1.match_flag > 0) && (pre_m2.rid_L == curr_m1.rid_L) && (pre_m2.rid_R != curr_m1.rid_R))
|
||
{
|
||
m2_newMatch = 0;
|
||
}
|
||
else if ( (curr_m1.match_flag > 0) && (pre_m2.rid_L != curr_m1.rid_L) && (pre_m2.rid_R == curr_m1.rid_R))
|
||
{
|
||
m2_newMatch = 0;
|
||
}
|
||
else if( (curr_m2.match_flag > 0) && (pre_m2.rid_L == curr_m2.rid_L) && (pre_m2.rid_R == curr_m2.rid_R)) //m1 <-> left_pt1
|
||
{
|
||
new_m2 = curr_m2;
|
||
m2_newMatch = 2; //inherit
|
||
}
|
||
else if((curr_m2.match_flag > 0) && (pre_m2.rid_L == curr_m2.rid_L) && (pre_m2.rid_R != curr_m2.rid_R)) //m1 <-> left_pt1
|
||
{
|
||
m2_newMatch = 0;
|
||
}
|
||
else if((curr_m2.match_flag > 0) && (pre_m2.rid_L != curr_m2.rid_L) && (pre_m2.rid_R == curr_m2.rid_R)) //m1 <-> left_pt1
|
||
{
|
||
m2_newMatch = 0;
|
||
}
|
||
//start single side match check
|
||
else if( (line_L.ptNum >= 1) && (pre_m2.rid_L != 0) && (pre_m2.rid_L == line_L.pt1.rid) && (line_L.pt1.matchFlag == 0))
|
||
{
|
||
m2_newMatch = 1; //new single side
|
||
new_m2.match_flag = 2;
|
||
new_m2.match_seg_id = pre_m2.match_seg_id;
|
||
new_m2.pt_idx_L = 1;
|
||
new_m2.pt_idx_R = 0;
|
||
new_m2.rid_L = pre_m2.rid_L;
|
||
new_m2.rid_R = pre_m2.rid_R;
|
||
}
|
||
else if( (line_L.ptNum >= 2) && (pre_m2.rid_L != 0) && (pre_m2.rid_L == line_L.pt2.rid) && (line_L.pt2.matchFlag == 0))
|
||
{
|
||
m2_newMatch = 1; //new single side
|
||
new_m2.match_flag = 2;
|
||
new_m2.match_seg_id = pre_m2.match_seg_id;
|
||
new_m2.pt_idx_L = 2;
|
||
new_m2.pt_idx_R = 0;
|
||
new_m2.rid_L = pre_m2.rid_L;
|
||
new_m2.rid_R = pre_m2.rid_R;
|
||
}
|
||
else if( (line_R.ptNum >= 1) && (pre_m2.rid_R != 0) && (pre_m2.rid_R == line_R.pt1.rid) && (line_R.pt1.matchFlag == 0))
|
||
{
|
||
m2_newMatch = 1; //new single side
|
||
new_m2.match_flag = 3;
|
||
new_m2.match_seg_id = pre_m2.match_seg_id;
|
||
new_m2.pt_idx_L = 0;
|
||
new_m2.pt_idx_R = 1;
|
||
new_m2.rid_L = pre_m2.rid_L;
|
||
new_m2.rid_R = pre_m2.rid_R;
|
||
}
|
||
else if( (line_R.ptNum >= 2) && (pre_m2.rid_R != 0) && (pre_m2.rid_R == line_R.pt2.rid) && (line_R.pt2.matchFlag == 0))
|
||
{
|
||
m2_newMatch = 1; //new single side
|
||
new_m2.match_flag = 3;
|
||
new_m2.match_seg_id = pre_m2.match_seg_id;
|
||
new_m2.pt_idx_L = 0;
|
||
new_m2.pt_idx_R = 2;
|
||
new_m2.rid_L = pre_m2.rid_L;
|
||
new_m2.rid_R = pre_m2.rid_R;
|
||
}
|
||
}
|
||
|
||
match1 = (m1_newMatch != 0) ? new_m1 : null_match;
|
||
match2 = (m2_newMatch != 0) ? new_m2 : null_match;
|
||
//update LR match for next using
|
||
if( (m1_newMatch == 0) && (m2_newMatch == 0))//m1 and m2 have no match
|
||
{
|
||
if( (curr_m1.match_flag == 1) && (curr_m2.match_flag == 1))
|
||
{
|
||
//a_lineMatch.match1 and a_lineMatch.match2 are new L-R match
|
||
match1 = curr_m1;
|
||
match2 = curr_m2;
|
||
}
|
||
else if (curr_m1.match_flag == 1)
|
||
{
|
||
//a_lineMatch.match1 is a new L-R match
|
||
match1 = curr_m1;
|
||
match2 = null_match;
|
||
}
|
||
else if(curr_m2.match_flag == 1)
|
||
{
|
||
//a_lineMatch.match2 is a new L-R match
|
||
match1 = curr_m2;
|
||
match2 = null_match;
|
||
}
|
||
else
|
||
{
|
||
match1 = null_match;
|
||
match2 = null_match;
|
||
}
|
||
}
|
||
else if((m1_newMatch == 0) && (m2_newMatch > 0)) //m1 has no match, but m2 is matched
|
||
{
|
||
if((curr_m1.match_flag == 1) && ((new_m2.rid_L != curr_m1.rid_L)||(new_m2.rid_R != curr_m1.rid_R)))
|
||
{
|
||
//a_lineMatch.match1 is a new L-R match
|
||
match1 = curr_m1;
|
||
}
|
||
else if((curr_m2.match_flag == 1) && ((new_m2.rid_L != curr_m2.rid_L)||(new_m2.rid_R != curr_m2.rid_R)))
|
||
{
|
||
//a_lineMatch.match2 is a new L-R match
|
||
match1 = curr_m2;
|
||
}
|
||
else
|
||
{
|
||
//only one L-R match, move m2 to m1
|
||
match1 = match2;
|
||
match2 = null_match;
|
||
}
|
||
}
|
||
else if((m1_newMatch > 0) && (m2_newMatch == 0))//m2 has no match, but m1 is matched
|
||
{
|
||
if((curr_m1.match_flag == 1) && ((new_m1.rid_L != curr_m1.rid_L)||(new_m1.rid_R != curr_m1.rid_R)))
|
||
{
|
||
//a_lineMatch.match1 is a new L-R match
|
||
match2 = curr_m1;
|
||
}
|
||
else if((curr_m2.match_flag == 1) && ((new_m1.rid_L != curr_m2.rid_L)||(new_m1.rid_R != curr_m2.rid_R)))
|
||
{
|
||
//a_lineMatch.match2 is a new L-R match
|
||
match2 = curr_m2;
|
||
}
|
||
else
|
||
{
|
||
match2 = null_match;
|
||
}
|
||
}
|
||
|
||
//update current new match. Parallel compare
|
||
if(a_lineMatch.matchNum == 0)
|
||
{
|
||
if( (m1_newMatch == 1) && (m2_newMatch == 1))
|
||
{
|
||
update_match.matchNum = 2;
|
||
update_match.match1 = new_m1;
|
||
update_match.match2 = new_m2;
|
||
|
||
if(new_m1.pt_idx_L == 1)
|
||
flag_L1 = 2;//new_m1.match_flag;
|
||
else if(new_m1.pt_idx_L == 2)
|
||
flag_L2 = 2;//new_m1.match_flag;
|
||
else if(new_m1.pt_idx_R == 1)
|
||
flag_R1 = 3;//new_m1.match_flag;
|
||
else if(new_m1.pt_idx_R == 2)
|
||
flag_R2 = 3;//new_m1.match_flag;
|
||
|
||
if(new_m2.pt_idx_L == 1)
|
||
flag_L1 = 2;//new_m2.match_flag;
|
||
else if(new_m2.pt_idx_L == 2)
|
||
flag_L2 = 2;//new_m2.match_flag;
|
||
else if(new_m2.pt_idx_R == 1)
|
||
flag_R1 = 3;//new_m2.match_flag;
|
||
else if(new_m2.pt_idx_R == 2)
|
||
flag_R2 = 3;//new_m2.match_flag;
|
||
}
|
||
else if(m1_newMatch == 1)
|
||
{
|
||
update_match.matchNum = 1;
|
||
update_match.match1 = new_m1;
|
||
update_match.match2 = null_match;
|
||
if(new_m1.pt_idx_L == 1)
|
||
flag_L1 = 2;//new_m1.match_flag;
|
||
else if(new_m1.pt_idx_L == 2)
|
||
flag_L2 = 2;//new_m1.match_flag;
|
||
else if(new_m1.pt_idx_R == 1)
|
||
flag_R1 = 3;//new_m1.match_flag;
|
||
else if(new_m1.pt_idx_R == 2)
|
||
flag_R2 = 3;//new_m1.match_flag;
|
||
}
|
||
else if(m2_newMatch == 1)
|
||
{
|
||
update_match.matchNum = 1;
|
||
update_match.match1 = new_m2;
|
||
update_match.match2 = null_match;
|
||
if(new_m2.pt_idx_L == 1)
|
||
flag_L1 = 2;//new_m2.match_flag;
|
||
else if(new_m2.pt_idx_L == 2)
|
||
flag_L2 = 2;//new_m2.match_flag;
|
||
else if(new_m2.pt_idx_R == 1)
|
||
flag_R1 = 3;//new_m2.match_flag;
|
||
else if(new_m2.pt_idx_R == 2)
|
||
flag_R2 = 3;//new_m2.match_flag;
|
||
}
|
||
}
|
||
else if(a_lineMatch.matchNum == 1)
|
||
{
|
||
if(m1_newMatch == 1)
|
||
{
|
||
update_match.matchNum = 2;
|
||
update_match.match2 = new_m1;
|
||
if(new_m1.pt_idx_L == 1)
|
||
flag_L1 = 2;//new_m1.match_flag;
|
||
else if(new_m1.pt_idx_L == 2)
|
||
flag_L2 = 2;//new_m1.match_flag;
|
||
else if(new_m1.pt_idx_R == 1)
|
||
flag_R1 = 3;//new_m1.match_flag;
|
||
else if(new_m1.pt_idx_R == 2)
|
||
flag_R2 = 3;//new_m1.match_flag;
|
||
}
|
||
else if(m2_newMatch == 1)
|
||
{
|
||
update_match.matchNum = 2;
|
||
update_match.match2 = new_m2;
|
||
if(new_m2.pt_idx_L == 1)
|
||
flag_L1 = 2;//new_m2.match_flag;
|
||
else if(new_m2.pt_idx_L == 2)
|
||
flag_L2 = 2;//new_m2.match_flag;
|
||
else if(new_m2.pt_idx_R == 1)
|
||
flag_R1 = 3;//new_m2.match_flag;
|
||
else if(new_m2.pt_idx_R == 2)
|
||
flag_R2 = 3;//new_m2.match_flag;
|
||
}
|
||
}
|
||
// One write per flag field per row; all branch selection is local.
|
||
left_buf[i].pt1.matchFlag = flag_L1;
|
||
left_buf[i].pt2.matchFlag = flag_L2;
|
||
right_buf[i].pt1.matchFlag = flag_R1;
|
||
right_buf[i].pt2.matchFlag = flag_R2;
|
||
total_match_size += (unsigned int)update_match.matchNum
|
||
- (unsigned int)a_lineMatch.matchNum;
|
||
matchInfo_buf[i] = update_match; //read - modify - write operation
|
||
}
|
||
|
||
// bottoom - up
|
||
match1 = null_match;
|
||
match2 = null_match;
|
||
SS_BOTTOM_UP:
|
||
for(int i = maxY; i >= (int)minY; i --)
|
||
{
|
||
#pragma HLS LOOP_TRIPCOUNT min=1 max=3072
|
||
#pragma HLS PIPELINE II=2
|
||
|
||
SRowData line_L = left_buf[i];
|
||
SRowData line_R = right_buf[i];
|
||
SLineMatchInfo a_lineMatch = matchInfo_buf[i];
|
||
SLineMatchInfo update_match = a_lineMatch;
|
||
ap_uint<2> flag_L1 = line_L.pt1.matchFlag;
|
||
ap_uint<2> flag_L2 = line_L.pt2.matchFlag;
|
||
ap_uint<2> flag_R1 = line_R.pt1.matchFlag;
|
||
ap_uint<2> flag_R2 = line_R.pt2.matchFlag;
|
||
|
||
SPointMatchInfo pre_m1 = match1;
|
||
SPointMatchInfo pre_m2 = match2;
|
||
|
||
SPointMatchInfo curr_m1 = a_lineMatch.match1;
|
||
SPointMatchInfo curr_m2 = a_lineMatch.match2;
|
||
|
||
ap_uint<2> m1_newMatch = 0;
|
||
ap_uint<2> m2_newMatch = 0;
|
||
SPointMatchInfo new_m1 = null_match;
|
||
SPointMatchInfo new_m2 = null_match;
|
||
|
||
//single side match
|
||
if(pre_m1.match_flag > 0)
|
||
{
|
||
if( (curr_m1.match_flag > 0) && (pre_m1.rid_L == curr_m1.rid_L) && (pre_m1.rid_R == curr_m1.rid_R)) //m1 <-> left_pt1
|
||
{
|
||
new_m1 = curr_m1;
|
||
m1_newMatch = 2; //inherit
|
||
}
|
||
else if ( (curr_m1.match_flag > 0) && (pre_m1.rid_L == curr_m1.rid_L) && (pre_m1.rid_R != curr_m1.rid_R))
|
||
{
|
||
m1_newMatch = 0;
|
||
}
|
||
else if ( (curr_m1.match_flag > 0) && (pre_m1.rid_L != curr_m1.rid_L) && (pre_m1.rid_R == curr_m1.rid_R))
|
||
{
|
||
m1_newMatch = 0;
|
||
}
|
||
else if( (curr_m2.match_flag > 0) && (pre_m1.rid_L == curr_m2.rid_L) && (pre_m1.rid_R == curr_m2.rid_R)) //m1 <-> left_pt1
|
||
{
|
||
new_m1 = curr_m2;
|
||
m1_newMatch = 2; //inherit
|
||
}
|
||
else if( (curr_m2.match_flag > 0) && (pre_m1.rid_L == curr_m2.rid_L) && (pre_m1.rid_R != curr_m2.rid_R)) //m1 <-> left_pt1
|
||
{
|
||
m1_newMatch = 0;
|
||
}
|
||
else if( (curr_m2.match_flag > 0) && (pre_m1.rid_L != curr_m2.rid_L) && (pre_m1.rid_R == curr_m2.rid_R)) //m1 <-> left_pt1
|
||
{
|
||
m1_newMatch = 0;
|
||
}
|
||
//start single side match check
|
||
else if( (line_L.ptNum >= 1) && (pre_m1.rid_L != 0) && (pre_m1.rid_L == line_L.pt1.rid) && (line_L.pt1.matchFlag == 0))
|
||
{
|
||
m1_newMatch = 1; //new single side
|
||
new_m1.match_flag = 2;
|
||
new_m1.match_seg_id = pre_m1.match_seg_id;
|
||
new_m1.pt_idx_L = 1;
|
||
new_m1.pt_idx_R = 0;
|
||
new_m1.rid_L = pre_m1.rid_L;
|
||
new_m1.rid_R = pre_m1.rid_R;
|
||
}
|
||
else if( (line_L.ptNum >= 2) && (pre_m1.rid_L != 0) && (pre_m1.rid_L == line_L.pt2.rid) && (line_L.pt2.matchFlag == 0))
|
||
{
|
||
m1_newMatch = 1; //new single side
|
||
new_m1.match_flag = 2;
|
||
new_m1.match_seg_id = pre_m1.match_seg_id;
|
||
new_m1.pt_idx_L = 2;
|
||
new_m1.pt_idx_R = 0;
|
||
new_m1.rid_L = pre_m1.rid_L;
|
||
new_m1.rid_R = pre_m1.rid_R;
|
||
}
|
||
else if( (line_R.ptNum >= 1) && (pre_m1.rid_R != 0) && (pre_m1.rid_R == line_R.pt1.rid) && (line_R.pt1.matchFlag == 0))
|
||
{
|
||
m1_newMatch = 1; //new single side
|
||
new_m1.match_flag = 3;
|
||
new_m1.match_seg_id = pre_m1.match_seg_id;
|
||
new_m1.pt_idx_L = 0;
|
||
new_m1.pt_idx_R = 1;
|
||
new_m1.rid_L = pre_m1.rid_L;
|
||
new_m1.rid_R = pre_m1.rid_R;
|
||
}
|
||
else if( (line_R.ptNum >= 2) && (pre_m1.rid_R != 0) && (pre_m1.rid_R == line_R.pt2.rid) && (line_R.pt2.matchFlag == 0))
|
||
{
|
||
m1_newMatch = 1; //new single side
|
||
new_m1.match_flag = 3;
|
||
new_m1.match_seg_id = pre_m1.match_seg_id;
|
||
new_m1.pt_idx_L = 0;
|
||
new_m1.pt_idx_R = 2;
|
||
new_m1.rid_L = pre_m1.rid_L;
|
||
new_m1.rid_R = pre_m1.rid_R;
|
||
}
|
||
}
|
||
|
||
//2nd
|
||
if(pre_m2.match_flag > 0)
|
||
{
|
||
if( (curr_m1.match_flag > 0) && (pre_m2.rid_L == curr_m1.rid_L) && (pre_m2.rid_R == curr_m1.rid_R)) //m1 <-> left_pt1
|
||
{
|
||
new_m2 = curr_m1;
|
||
m2_newMatch = 2; //inherit
|
||
}
|
||
else if ( (curr_m1.match_flag > 0) && (pre_m2.rid_L == curr_m1.rid_L) && (pre_m2.rid_R != curr_m1.rid_R))
|
||
{
|
||
m2_newMatch = 0;
|
||
}
|
||
else if ( (curr_m1.match_flag > 0) && (pre_m2.rid_L != curr_m1.rid_L) && (pre_m2.rid_R == curr_m1.rid_R))
|
||
{
|
||
m2_newMatch = 0;
|
||
}
|
||
else if( (curr_m2.match_flag > 0) && (pre_m2.rid_L == curr_m2.rid_L) && (pre_m2.rid_R == curr_m2.rid_R)) //m1 <-> left_pt1
|
||
{
|
||
new_m2 = curr_m2;
|
||
m2_newMatch = 2; //inherit
|
||
}
|
||
else if((curr_m2.match_flag > 0) && (pre_m2.rid_L == curr_m2.rid_L) && (pre_m2.rid_R != curr_m2.rid_R)) //m1 <-> left_pt1
|
||
{
|
||
m2_newMatch = 0;
|
||
}
|
||
else if((curr_m2.match_flag > 0) && (pre_m2.rid_L != curr_m2.rid_L) && (pre_m2.rid_R == curr_m2.rid_R)) //m1 <-> left_pt1
|
||
{
|
||
m2_newMatch = 0;
|
||
}
|
||
//start single side match check
|
||
else if( (line_L.ptNum >= 1) && (pre_m2.rid_L != 0) && (pre_m2.rid_L == line_L.pt1.rid) && (line_L.pt1.matchFlag == 0))
|
||
{
|
||
m2_newMatch = 1; //new single side
|
||
new_m2.match_flag = 2;
|
||
new_m2.match_seg_id = pre_m2.match_seg_id;
|
||
new_m2.pt_idx_L = 1;
|
||
new_m2.pt_idx_R = 0;
|
||
new_m2.rid_L = pre_m2.rid_L;
|
||
new_m2.rid_R = pre_m2.rid_R;
|
||
}
|
||
else if( (line_L.ptNum >= 2) && (pre_m2.rid_L != 0) && (pre_m2.rid_L == line_L.pt2.rid) && (line_L.pt2.matchFlag == 0))
|
||
{
|
||
m2_newMatch = 1; //new single side
|
||
new_m2.match_flag = 2;
|
||
new_m2.match_seg_id = pre_m2.match_seg_id;
|
||
new_m2.pt_idx_L = 2;
|
||
new_m2.pt_idx_R = 0;
|
||
new_m2.rid_L = pre_m2.rid_L;
|
||
new_m2.rid_R = pre_m2.rid_R;
|
||
}
|
||
else if( (line_R.ptNum >= 1) && (pre_m2.rid_R != 0) && (pre_m2.rid_R == line_R.pt1.rid) && (line_R.pt1.matchFlag == 0))
|
||
{
|
||
m2_newMatch = 1; //new single side
|
||
new_m2.match_flag = 3;
|
||
new_m2.match_seg_id = pre_m2.match_seg_id;
|
||
new_m2.pt_idx_L = 0;
|
||
new_m2.pt_idx_R = 1;
|
||
new_m2.rid_L = pre_m2.rid_L;
|
||
new_m2.rid_R = pre_m2.rid_R;
|
||
}
|
||
else if( (line_R.ptNum >= 2) && (pre_m2.rid_R != 0) && (pre_m2.rid_R == line_R.pt2.rid) && (line_R.pt2.matchFlag == 0))
|
||
{
|
||
m2_newMatch = 1; //new single side
|
||
new_m2.match_flag = 3;
|
||
new_m2.match_seg_id = pre_m2.match_seg_id;
|
||
new_m2.pt_idx_L = 0;
|
||
new_m2.pt_idx_R = 2;
|
||
new_m2.rid_L = pre_m2.rid_L;
|
||
new_m2.rid_R = pre_m2.rid_R;
|
||
}
|
||
}
|
||
|
||
match1 = (m1_newMatch != 0) ? new_m1 : null_match;
|
||
match2 = (m2_newMatch != 0) ? new_m2 : null_match;
|
||
//update LR match for next using
|
||
if( (m1_newMatch == 0) && (m2_newMatch == 0))//m1 and m2 have no match
|
||
{
|
||
if( (curr_m1.match_flag == 1) && (curr_m2.match_flag == 1))
|
||
{
|
||
//a_lineMatch.match1 and a_lineMatch.match2 are new L-R match
|
||
match1 = curr_m1;
|
||
match2 = curr_m2;
|
||
}
|
||
else if (curr_m1.match_flag == 1)
|
||
{
|
||
//a_lineMatch.match1 is a new L-R match
|
||
match1 = curr_m1;
|
||
match2 = null_match;
|
||
}
|
||
else if(curr_m2.match_flag == 1)
|
||
{
|
||
//a_lineMatch.match2 is a new L-R match
|
||
match1 = curr_m2;
|
||
match2 = null_match;
|
||
}
|
||
else
|
||
{
|
||
match1 = null_match;
|
||
match2 = null_match;
|
||
}
|
||
}
|
||
else if((m1_newMatch == 0) && (m2_newMatch > 0)) //m1 has no match, but m2 is matched
|
||
{
|
||
if((curr_m1.match_flag == 1) && ((new_m2.rid_L != curr_m1.rid_L)||(new_m2.rid_R != curr_m1.rid_R)))
|
||
{
|
||
//a_lineMatch.match1 is a new L-R match
|
||
match1 = curr_m1;
|
||
}
|
||
else if((curr_m2.match_flag == 1) && ((new_m2.rid_L != curr_m2.rid_L)||(new_m2.rid_R != curr_m2.rid_R)))
|
||
{
|
||
//a_lineMatch.match2 is a new L-R match
|
||
match1 = curr_m2;
|
||
}
|
||
else
|
||
{
|
||
//only one L-R match, move m2 to m1
|
||
match1 = match2;
|
||
match2 = null_match;
|
||
}
|
||
}
|
||
else if((m1_newMatch > 0) && (m2_newMatch == 0))//m2 has no match, but m1 is matched
|
||
{
|
||
if((curr_m1.match_flag == 1) && ((new_m1.rid_L != curr_m1.rid_L)||(new_m1.rid_R != curr_m1.rid_R)))
|
||
{
|
||
//a_lineMatch.match1 is a new L-R match
|
||
match2 = curr_m1;
|
||
}
|
||
else if((curr_m2.match_flag == 1) && ((new_m1.rid_L != curr_m2.rid_L)||(new_m1.rid_R != curr_m2.rid_R)))
|
||
{
|
||
//a_lineMatch.match2 is a new L-R match
|
||
match2 = curr_m2;
|
||
}
|
||
else
|
||
{
|
||
match2 = null_match;
|
||
}
|
||
}
|
||
|
||
//update current new match. Parallel compare
|
||
if(a_lineMatch.matchNum == 0)
|
||
{
|
||
if( (m1_newMatch == 1) && (m2_newMatch == 1))
|
||
{
|
||
update_match.matchNum = 2;
|
||
update_match.match1 = new_m1;
|
||
update_match.match2 = new_m2;
|
||
|
||
if(new_m1.pt_idx_L == 1)
|
||
flag_L1 = 2;//new_m1.match_flag;
|
||
else if(new_m1.pt_idx_L == 2)
|
||
flag_L2 = 2;//new_m1.match_flag;
|
||
else if(new_m1.pt_idx_R == 1)
|
||
flag_R1 = 3;//new_m1.match_flag;
|
||
else if(new_m1.pt_idx_R == 2)
|
||
flag_R2 = 3;//new_m1.match_flag;
|
||
|
||
if(new_m2.pt_idx_L == 1)
|
||
flag_L1 = 2;//new_m2.match_flag;
|
||
else if(new_m2.pt_idx_L == 2)
|
||
flag_L2 = 2;//new_m2.match_flag;
|
||
else if(new_m2.pt_idx_R == 1)
|
||
flag_R1 = 3;//new_m2.match_flag;
|
||
else if(new_m2.pt_idx_R == 2)
|
||
flag_R2 = 3;//new_m2.match_flag;
|
||
}
|
||
else if(m1_newMatch == 1)
|
||
{
|
||
update_match.matchNum = 1;
|
||
update_match.match1 = new_m1;
|
||
update_match.match2 = null_match;
|
||
if(new_m1.pt_idx_L == 1)
|
||
flag_L1 = 2;//new_m1.match_flag;
|
||
else if(new_m1.pt_idx_L == 2)
|
||
flag_L2 = 2;//new_m1.match_flag;
|
||
else if(new_m1.pt_idx_R == 1)
|
||
flag_R1 = 3;//new_m1.match_flag;
|
||
else if(new_m1.pt_idx_R == 2)
|
||
flag_R2 = 3;//new_m1.match_flag;
|
||
}
|
||
else if(m2_newMatch == 1)
|
||
{
|
||
update_match.matchNum = 1;
|
||
update_match.match1 = new_m2;
|
||
update_match.match2 = null_match;
|
||
if(new_m2.pt_idx_L == 1)
|
||
flag_L1 = 2;//new_m2.match_flag;
|
||
else if(new_m2.pt_idx_L == 2)
|
||
flag_L2 = 2;//new_m2.match_flag;
|
||
else if(new_m2.pt_idx_R == 1)
|
||
flag_R1 = 3;//new_m2.match_flag;
|
||
else if(new_m2.pt_idx_R == 2)
|
||
flag_R2 = 3;//new_m2.match_flag;
|
||
}
|
||
}
|
||
else if(a_lineMatch.matchNum == 1)
|
||
{
|
||
if(m1_newMatch == 1)
|
||
{
|
||
update_match.matchNum = 2;
|
||
update_match.match2 = new_m1;
|
||
if(new_m1.pt_idx_L == 1)
|
||
flag_L1 = 2;//new_m1.match_flag;
|
||
else if(new_m1.pt_idx_L == 2)
|
||
flag_L2 = 2;//new_m1.match_flag;
|
||
else if(new_m1.pt_idx_R == 1)
|
||
flag_R1 = 3;//new_m1.match_flag;
|
||
else if(new_m1.pt_idx_R == 2)
|
||
flag_R2 = 3;//new_m1.match_flag;
|
||
}
|
||
else if(m2_newMatch == 1)
|
||
{
|
||
update_match.matchNum = 2;
|
||
update_match.match2 = new_m2;
|
||
if(new_m2.pt_idx_L == 1)
|
||
flag_L1 = 2;//new_m2.match_flag;
|
||
else if(new_m2.pt_idx_L == 2)
|
||
flag_L2 = 2;//new_m2.match_flag;
|
||
else if(new_m2.pt_idx_R == 1)
|
||
flag_R1 = 3;//new_m2.match_flag;
|
||
else if(new_m2.pt_idx_R == 2)
|
||
flag_R2 = 3;//new_m2.match_flag;
|
||
}
|
||
}
|
||
// One write per flag field per row; all branch selection is local.
|
||
left_buf[i].pt1.matchFlag = flag_L1;
|
||
left_buf[i].pt2.matchFlag = flag_L2;
|
||
right_buf[i].pt1.matchFlag = flag_R1;
|
||
right_buf[i].pt2.matchFlag = flag_R2;
|
||
total_match_size += (unsigned int)update_match.matchNum
|
||
- (unsigned int)a_lineMatch.matchNum;
|
||
matchInfo_buf[i] = update_match; //read - modify - write operation
|
||
}
|
||
}
|
||
|
||
LRMatchedPoint outWord = { 0.0f, 0.0f, 0, 0, 0, 0, 0, 0 };
|
||
UintFloat outTmp;
|
||
//first
|
||
outTmp.unData = frmNo;
|
||
outWord.xL = outTmp.fdata;
|
||
outTmp.unData = timeStamp;
|
||
outWord.xR = outTmp.fdata;
|
||
outWord.Sync = 0b10;
|
||
outLRPt.write(outWord);
|
||
//second
|
||
outTmp.unData = encInfo;
|
||
outWord.xL = outTmp.fdata;
|
||
outTmp.unData = (uint32_t)minY | ((uint32_t)maxY << 16);
|
||
outWord.xR = outTmp.fdata;
|
||
outWord.Sync = 0b00;
|
||
outLRPt.write(outWord);
|
||
//3rd
|
||
outTmp.unData = total_match_size;
|
||
outWord.xL = outTmp.fdata;
|
||
outWord.xR = 0.0f;
|
||
if(total_match_size == 0)
|
||
outWord.Sync = 0b11;
|
||
else
|
||
outWord.Sync = 0b00;
|
||
outLRPt.write(outWord);
|
||
|
||
if(total_match_size > 0)
|
||
{
|
||
//output
|
||
uint16_t counter = 0;
|
||
SS_OUTPUT:
|
||
for(uint16_t i = minY; i<= maxY; i ++)
|
||
{
|
||
#pragma HLS LOOP_TRIPCOUNT min=1 max=3072
|
||
#pragma HLS PIPELINE II=2
|
||
SLineMatchInfo a_lineMatch = matchInfo_buf[i];
|
||
SRowData line_L = left_buf[i];
|
||
SRowData line_R = right_buf[i];
|
||
if(a_lineMatch.matchNum > 0)
|
||
{
|
||
//first
|
||
outWord.matchFlag = a_lineMatch.match1.match_flag;
|
||
outWord.match_seg_id = a_lineMatch.match1.match_seg_id;
|
||
outWord.y = i;
|
||
if(a_lineMatch.match1.pt_idx_L == 1)
|
||
{
|
||
outWord.xL = line_L.pt1.x;
|
||
outWord.valueL = line_L.pt1.value;
|
||
}
|
||
else if(a_lineMatch.match1.pt_idx_L == 2)
|
||
{
|
||
outWord.xL = line_L.pt2.x;
|
||
outWord.valueL = line_L.pt2.value;
|
||
}
|
||
else
|
||
{
|
||
outWord.xL = 0.0f;
|
||
outWord.valueL = 0;
|
||
}
|
||
|
||
//right
|
||
if(a_lineMatch.match1.pt_idx_R == 1)
|
||
{
|
||
outWord.xR = line_R.pt1.x;
|
||
outWord.valueR = line_R.pt1.value;
|
||
}
|
||
else if(a_lineMatch.match1.pt_idx_R == 2)
|
||
{
|
||
outWord.xR = line_R.pt2.x;
|
||
outWord.valueR = line_R.pt2.value;
|
||
}
|
||
else
|
||
{
|
||
outWord.xR = 0.0f;
|
||
outWord.valueR = 0;
|
||
}
|
||
counter ++;
|
||
if(counter == total_match_size)
|
||
outWord.Sync = 0b11;
|
||
else
|
||
outWord.Sync = 0b00;
|
||
//output
|
||
outLRPt.write(outWord);
|
||
}
|
||
|
||
if(a_lineMatch.matchNum == 2)
|
||
{
|
||
//second
|
||
outWord.matchFlag = a_lineMatch.match2.match_flag;
|
||
outWord.match_seg_id = a_lineMatch.match2.match_seg_id;
|
||
outWord.y = i;
|
||
if(a_lineMatch.match2.pt_idx_L == 1)
|
||
{
|
||
outWord.xL = line_L.pt1.x;
|
||
outWord.valueL = line_L.pt1.value;
|
||
}
|
||
else if(a_lineMatch.match2.pt_idx_L == 2)
|
||
{
|
||
outWord.xL = line_L.pt2.x;
|
||
outWord.valueL = line_L.pt2.value;
|
||
}
|
||
else
|
||
{
|
||
outWord.xL = 0.0f;
|
||
outWord.valueL = 0;
|
||
}
|
||
|
||
//right
|
||
if(a_lineMatch.match2.pt_idx_R == 1)
|
||
{
|
||
outWord.xR = line_R.pt1.x;
|
||
outWord.valueR = line_R.pt1.value;
|
||
}
|
||
else if(a_lineMatch.match2.pt_idx_R == 2)
|
||
{
|
||
outWord.xR = line_R.pt2.x;
|
||
outWord.valueR = line_R.pt2.value;
|
||
}
|
||
else
|
||
{
|
||
outWord.xR = 0.0f;
|
||
outWord.valueR = 0;
|
||
}
|
||
counter ++;
|
||
if(counter == total_match_size)
|
||
outWord.Sync = 0b11;
|
||
else
|
||
outWord.Sync = 0b00;
|
||
//output
|
||
outLRPt.write(outWord);
|
||
}
|
||
}
|
||
}
|
||
}
|