Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
benjmarshall committed Jul 16, 2017
2 parents e3c6c62 + 5242cca commit 4597d71
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 1 deletion.
2 changes: 1 addition & 1 deletion hlsclt/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.0.0.a2'
__version__ = '1.0.0.a3'
8 changes: 8 additions & 0 deletions hlsclt/examples/sin_taylor_series/hls_config.py
Original file line number Diff line number Diff line change
@@ -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"
37 changes: 37 additions & 0 deletions hlsclt/examples/sin_taylor_series/src/dut.cpp
Original file line number Diff line number Diff line change
@@ -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);
}
1 change: 1 addition & 0 deletions hlsclt/examples/sin_taylor_series/src/dut.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
double sin_taylor_series (double x);
31 changes: 31 additions & 0 deletions hlsclt/examples/sin_taylor_series/tb/testbench.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <fstream>
#include <math.h>
#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;

}

0 comments on commit 4597d71

Please sign in to comment.