-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
78 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = '1.0.0.a2' | ||
__version__ = '1.0.0.a3' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
double sin_taylor_series (double x); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
} |