#include #include #include #include #include "hls_math.h" #define consta 16807 struct data_type{ float data; bool last; }; static float hist[5] = { 1, 2, 3, 4, 5 }; static float p[5] = { 0.2, 0.2, 0.2, 0.2, 0.2 }; typedef unsigned long long int llint; typedef unsigned long lint; static llint seed31 = 10; void randn(float* randno){ #pragma HLS INLINE off lint hi, lo; lo = consta * (seed31 & 0xFFFF); hi = consta * (seed31 >> 16); lo += (hi & 0x7FFF) << 16; lo += hi >> 15; if (lo > 0x7FFFFFFF) lo -= 0x7FFFFFFF; seed31 = (long)lo; *randno = seed31 / 2147483647.0f; } void las(data_type A[5], data_type B[5], int s, int* index, float* randno) { float minm, maxm, sum; float beata, rate, rno; #pragma HLS INTERFACE axis port=A #pragma HLS INTERFACE axis port=B #pragma HLS INTERFACE ap_ctrl_none port=return #pragma HLS INTERFACE s_axilite port=index #pragma HLS INTERFACE s_axilite port=s #pragma HLS INTERFACE s_axilite port=randno int i; float alpha = 0.9; const float a = 0.078; const float b = 0.006; float cum_p[5] = { 0.2, 0.4, 0.6, 0.8, 1.0 }; minm = hist[0]; maxm = hist[4]; for (i = 0; i<5; i++){ hist[i] = A[i].data*alpha + hist[i] * (1 - alpha); B[i].data = hist[i]; B[i].last = A[i].last; if (hist[i]maxm){ maxm = hist[i]; } } { beata = (hist[s] - minm) / (maxm - minm); rate = 1.0f - beata; for (i = 0; i<5; i++) { if (i == s) p[i] = p[i] + rate*a*(1 - p[i]) - b*beata*p[i]; else p[i] = p[i] - rate*a*p[i] + b*beata*((1.0 / 4.0f) - p[i]); } sum = 0.0; for (i = 0; i<5; i++) { sum = sum + p[i]; cum_p[i] = sum; } } randn(randno); for (i = 0; i<5; i++) { if (*(randno)