diff --git a/hlsclt/_version.py b/hlsclt/_version.py index b32d6f1..26d7acc 100644 --- a/hlsclt/_version.py +++ b/hlsclt/_version.py @@ -1 +1 @@ -__version__ = '1.0.0.a2' +__version__ = '1.0.0.a3' diff --git a/hlsclt/examples/sin_taylor_series/hls_config.py b/hlsclt/examples/sin_taylor_series/hls_config.py new file mode 100644 index 0000000..4365c7f --- /dev/null +++ b/hlsclt/examples/sin_taylor_series/hls_config.py @@ -0,0 +1,8 @@ +# Config file for Sine Taylor Series HLS Project + +top_level_function_name = "sin_taylor_series" +src_files = ["dut.h","dut.cpp"] +tb_files = ["testbench.cpp"] +part_name = "xc7z020clg484-1" +clock_period = "4" +language = "vhdl" diff --git a/hlsclt/examples/sin_taylor_series/src/dut.cpp b/hlsclt/examples/sin_taylor_series/src/dut.cpp new file mode 100644 index 0000000..054cdea --- /dev/null +++ b/hlsclt/examples/sin_taylor_series/src/dut.cpp @@ -0,0 +1,37 @@ +double fact(int x) { + // Comment out the pragma below this line to revert to 'partially optimised'. + #pragma HLS inline off + double result_int = 1.0; + fact_loop: for (int i=1; i<=x; i++) { + #pragma HLS PIPELINE + result_int=result_int*i; + } + return result_int; +} + +double power (double x, int y) { + // Comment out the pragma below this line to revert to 'partially optimised'. + #pragma HLS INLINE OFF + double result_int = 1.0; + power_loop: for (int i=1; i<=y; i++) { + #pragma HLS PIPELINE + result_int=result_int*x; + } + return result_int; +} + +double sin_taylor_series (double x){ + + #pragma HLS DATAFLOW + + int n = 20; + double sum_positive = 0.0; + double sum_negative= 0.0; + + sum_loop: for (int i=1; i<=n; i+=4) { + sum_positive = sum_positive + (power (x,i) / fact (i)); + sum_negative = sum_negative + (power (x,i+2) / fact (i+2)); + } + + return (sum_positive - sum_negative); +} diff --git a/hlsclt/examples/sin_taylor_series/src/dut.h b/hlsclt/examples/sin_taylor_series/src/dut.h new file mode 100644 index 0000000..a0db4ae --- /dev/null +++ b/hlsclt/examples/sin_taylor_series/src/dut.h @@ -0,0 +1 @@ +double sin_taylor_series (double x); diff --git a/hlsclt/examples/sin_taylor_series/tb/testbench.cpp b/hlsclt/examples/sin_taylor_series/tb/testbench.cpp new file mode 100644 index 0000000..a3c1886 --- /dev/null +++ b/hlsclt/examples/sin_taylor_series/tb/testbench.cpp @@ -0,0 +1,31 @@ +#include +#include +#include "../src/dut.h" + +int main(void) { + + // Setup some required variables + const double pi = 3.1415; + const double rad2deg = 180/pi; + const double deg2rad = pi/180; + double x = 0.0; + double result, expected_result; + int error_count = 0; + + // Test Loop + while (x < 90*deg2rad) { + // Call dut + result = sin_taylor_series(x); + // Generate expected_result + expected_result = sin(x); + // Check result and output some visual check + if (fabs(result - expected_result) > expected_result*0.001) { + error_count++; + } + printf("Sin(%d) - Expected result: %f, Got Result: %f\n", int(round(x*rad2deg)), expected_result, result); + x = x + (5*deg2rad); + } + + return error_count; + +}