2025-12-12 18:37:56 +00:00
|
|
|
|
// pm_test.cpp
|
|
|
|
|
|
|
2025-12-09 09:08:18 +00:00
|
|
|
|
#include "test_case.h"
|
|
|
|
|
|
|
2025-12-12 18:37:56 +00:00
|
|
|
|
int main()
|
|
|
|
|
|
{
|
2025-12-09 09:08:18 +00:00
|
|
|
|
// Top-level AXI4-Stream ports for the DUT
|
2025-12-09 11:18:13 +00:00
|
|
|
|
hls::stream<coeff_axis_big_t> in_data;
|
|
|
|
|
|
hls::stream<coeff_axis_t> out_data;
|
2025-12-12 18:37:56 +00:00
|
|
|
|
|
2025-12-09 11:18:13 +00:00
|
|
|
|
coeff_axis_big_t local_stream1;
|
|
|
|
|
|
coeff_axis_t local_stream2;
|
2025-12-12 18:37:56 +00:00
|
|
|
|
|
2025-12-09 09:08:18 +00:00
|
|
|
|
int i;
|
|
|
|
|
|
|
2025-12-12 18:37:56 +00:00
|
|
|
|
coeff_t actual_outputs[Nt];
|
|
|
|
|
|
coeff_t golden_outputs[Nt]; // NEW: buffer for golden result
|
|
|
|
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
// Write stimulus into input AXI4-Stream
|
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
for (i = 0; i < Nt; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
coeff_t val1 = input1_vals[i];
|
|
|
|
|
|
coeff_t val2 = input2_vals[i];
|
|
|
|
|
|
|
|
|
|
|
|
// Packing: 2×32-bit coeffs into one 64-bit word
|
|
|
|
|
|
ap_uint<64> word = 0;
|
|
|
|
|
|
word |= (ap_uint<32>)val1; // low 32 bits
|
|
|
|
|
|
word |= (ap_uint<64>)(ap_uint<32>)val2 << 32; // high 32 bits
|
|
|
|
|
|
|
|
|
|
|
|
local_stream1.data = word;
|
|
|
|
|
|
local_stream1.keep = -1; // 0xFF for 64-bit TDATA
|
2025-12-09 11:18:13 +00:00
|
|
|
|
local_stream1.strb = -1;
|
|
|
|
|
|
local_stream1.last = (i == Nt - 1) ? 1 : 0;
|
2025-12-12 18:37:56 +00:00
|
|
|
|
|
2025-12-09 11:18:13 +00:00
|
|
|
|
in_data.write(local_stream1);
|
2025-12-09 09:08:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-12 18:37:56 +00:00
|
|
|
|
// -------------------------------------------------------------------------
|
2025-12-09 09:08:18 +00:00
|
|
|
|
// Call DUT
|
2025-12-12 18:37:56 +00:00
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
poly_mult_dil(in_data, out_data);
|
2025-12-09 09:08:18 +00:00
|
|
|
|
|
2025-12-12 18:37:56 +00:00
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
// Read result from output AXI4-Stream
|
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
for (i = 0; i < Nt; i++)
|
|
|
|
|
|
{
|
2025-12-09 11:18:13 +00:00
|
|
|
|
local_stream2 = out_data.read();
|
2025-12-12 18:37:56 +00:00
|
|
|
|
actual_outputs[i] = (coeff_t)local_stream2.data;
|
|
|
|
|
|
// local_stream2.last could be checked here if you want
|
2025-12-09 09:08:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-12 18:37:56 +00:00
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
// Compute golden result (software negacyclic product)
|
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
golden_poly_mult_dil(golden_outputs, input1_vals, input2_vals);
|
|
|
|
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------
|
2025-12-09 09:08:18 +00:00
|
|
|
|
// Compare against golden output
|
2025-12-12 18:37:56 +00:00
|
|
|
|
// -------------------------------------------------------------------------
|
2025-12-09 09:08:18 +00:00
|
|
|
|
int ret_val = 0;
|
2025-12-12 18:37:56 +00:00
|
|
|
|
for (i = 0; i < Nt; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (golden_outputs[i] != actual_outputs[i])
|
|
|
|
|
|
{
|
2025-12-09 09:08:18 +00:00
|
|
|
|
ret_val++;
|
2025-12-12 18:37:56 +00:00
|
|
|
|
std::cout << "Mismatch at i = " << i
|
|
|
|
|
|
<< " golden = " << golden_outputs[i]
|
|
|
|
|
|
<< " hw = " << actual_outputs[i]
|
|
|
|
|
|
<< std::endl;
|
2025-12-09 11:18:13 +00:00
|
|
|
|
break;
|
2025-12-09 09:08:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-12-12 18:37:56 +00:00
|
|
|
|
|
2025-12-09 09:08:18 +00:00
|
|
|
|
return ret_val;
|
|
|
|
|
|
}
|