#include"addp_upool.h"
#include "string.h"
Dtype_16f maxfour(Dtype_16f a,Dtype_16f b,Dtype_16f c,Dtype_16f d){
return max(max(a,b),max(c,d));
}
void cpy_poolbuf(Dtype_16f* In_ddr,Dtype_16f pool_bus1[Tww],INT8 Tw,int of){
memcpy(pool_bus1, (Dtype_16f *)(In_ddr + of), Tw*sizeof(Dtype_16f));
}
void addcpdr2_lin(Dtype_16f* In_ddr,Dtype_16f* In_ddr2,Dtype_16f pool_bus1[Tww],Dtype_16f pool_bus2[Tww],Dtype_11f hz,Dtype_11f wz,Dtype_11f cz,Dtype_11f win,
Dtype_19f winxhin,Dtype_16f t,Dtype_11f inchan,INT8 Tw,Dtype_16f inxTh){
if(t>=inxTh)
return;
Dtype_11f t1=t%inchan;
Dtype_11f t2=t/inchan;
Dtype_11f c=t1+cz;
Dtype_11f h=t2+hz;
int of=c*winxhin+h*win+wz;
cpy_poolbuf(In_ddr, pool_bus1, Tw, of);
cpy_poolbuf(In_ddr2, pool_bus2, Tw, of);
}
void addcplin2_buf(Dtype_16f pool_in[inchannel][Thh][Tww],Dtype_16f pool_bus1[Tww],Dtype_16f pool_bus2[Tww],
Dtype_16f t,Dtype_11f inchan,INT8 Tw){
if(t<0)
return;
INT8 t3;
Dtype_11f t1=t%inchan;
Dtype_11f t2=t/inchan;
for(t3=0;t3<Tw;t3++){
#pragma HLS PIPELINE II=1
pool_in[t1][t2][t3]=pool_bus1[t3]+pool_bus2[t3];
}
}
void Add(Dtype_16f* In_ddr,Dtype_16f* In_ddr2,Dtype_16f pool_in[inchannel][Thh][Tww],
INT8 Th,INT8 Tw, Dtype_11f hz,
Dtype_11f wz,Dtype_11f cz,Dtype_11f win,Dtype_11f chin, Dtype_19f winxhin){
if(cz>=chin)
return;
INT8 cc,hh,ww;
Dtype_11f inchan=inchannel;
// int of;
Dtype_16f t;
static Dtype_16f pool_bus1[Tww];
static Dtype_16f pool_bus2[Tww];
static Dtype_16f pool_busb1[Tww];
static Dtype_16f pool_busb2[Tww];
if(cz+inchannel>chin)
inchan=chin-cz;
Dtype_16f inxTh=inchan*Th;
bool pp=true;
for(t=0;t<inxTh+1;t++){
if(pp)
{
addcpdr2_lin( In_ddr, In_ddr2, pool_bus1, pool_bus2, hz, wz, cz, win,
winxhin, t, inchan, Tw,inxTh);
addcplin2_buf( pool_in, pool_busb1, pool_busb2,
t-1, inchan, Tw);
pp=false;
}
else