pqc-accelerate/HLS_Codes_Dilithium/pm_test.cpp

78 lines
2.6 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// pm_test.cpp
#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];
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
local_stream1.strb = -1;
local_stream1.last = (i == Nt - 1) ? 1 : 0;
in_data.write(local_stream1);
}
// -------------------------------------------------------------------------
// Call DUT
// -------------------------------------------------------------------------
poly_mult_dil(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;
// local_stream2.last could be checked here if you want
}
// -------------------------------------------------------------------------
// Compute golden result (software negacyclic product)
// -------------------------------------------------------------------------
golden_poly_mult_dil(golden_outputs, input1_vals, input2_vals);
// -------------------------------------------------------------------------
// Compare against golden output
// -------------------------------------------------------------------------
int ret_val = 0;
for (i = 0; i < Nt; i++)
{
if (golden_outputs[i] != actual_outputs[i])
{
ret_val++;
std::cout << "Mismatch at i = " << i
<< " golden = " << golden_outputs[i]
<< " hw = " << actual_outputs[i]
<< std::endl;
break;
}
}
return ret_val;
}