pqc-accelerate/HLS_Codes/pm_test.cpp

69 lines
2.1 KiB
C++

// pm_test.cpp (works with Set A and Set B)
#include "test_case.h"
int main()
{
// Top-level AXI4-Stream ports for the DUT
hls::stream<coeff_axis_big_t> in_data;
hls::stream<coeff_axis_t> out_data;
coeff_axis_big_t local_stream1;
coeff_axis_t local_stream2;
int i;
coeff_t actual_outputs[Nt];
// -------------------------------------------------------------------------
// Write stimulus into input AXI4-Stream
// -------------------------------------------------------------------------
for (i = 0; i < Nt; i++)
{
coeff_t val1 = input1_vals[i];
double_coeff_t val2 = (double_coeff_t)(input2_vals[i] * 65536);
// Pack into 32-bit AXI data word
local_stream1.data = (ap_uint<32>)(val1 + val2);
// Mark all bytes valid; side channels are disabled here
local_stream1.keep = -1;
local_stream1.strb = -1;
// TLAST on final sample
local_stream1.last = (i == Nt - 1) ? 1 : 0;
in_data.write(local_stream1);
}
// -------------------------------------------------------------------------
// Call DUT
// -------------------------------------------------------------------------
poly_mult(in_data, out_data);
// -------------------------------------------------------------------------
// Read result from output AXI4-Stream
// -------------------------------------------------------------------------
for (i = 0; i < Nt; i++)
{
local_stream2 = out_data.read();
actual_outputs[i] = (coeff_t)local_stream2.data;
// Optionally check local_stream2.last here
}
// -------------------------------------------------------------------------
// Compare against golden output
// -------------------------------------------------------------------------
int ret_val = 0;
for (i = 0; i < Nt; i++)
{
if (output_vals[i] != actual_outputs[i])
{
ret_val++;
std::cout << actual_outputs[i];
break;
}
}
return ret_val;
}