From 0d857f63a925787b55ae8c55534734e488b22543 Mon Sep 17 00:00:00 2001 From: Yuanjie Huang Date: Mon, 25 Feb 2019 14:46:40 +0800 Subject: [PATCH] Add examples and update readme This closes #1, and closes #2. --- README.MD | 23 ++++++++++++++++++++++- examples/ap_fixed/Makefile | 7 +++++++ examples/ap_fixed/test.cpp | 20 ++++++++++++++++++++ examples/ap_int/Makefile | 7 +++++++ examples/ap_int/test.cpp | 16 ++++++++++++++++ 5 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 examples/ap_fixed/Makefile create mode 100644 examples/ap_fixed/test.cpp create mode 100644 examples/ap_int/Makefile create mode 100644 examples/ap_int/test.cpp diff --git a/README.MD b/README.MD index 8e2000b..7849c29 100644 --- a/README.MD +++ b/README.MD @@ -1,10 +1,31 @@ # HLS Arbitrary Precision Types Library This repo provides simulation code of HLS Arbitrary Precision Types. + The code is based from headers shipped with Vivado, but due to absence of synthesis support **it should not be used in an HLS project targeting FPGA**. ----- +## Compatibility + +Tested with g++ (GCC) 6.2.0 on x86_64 GNU/Linux. + +## Usage + +Include the `ap_int.h` or `ap_fixed.h` in C++ code, +and set compiler option to add the path of `include` directory in this repo +into header search directory list. + +``` +$ cd examples/ap_int +$ g++ -I ../../include/ test.cpp +$ ./a.out +a = 11.3137 (0x0b.504ea4p0) +b = 11.3137 (0x0b.504f33p0) +c = a + b = 22.6274 (0x16.a09dd7p0) +$ +``` + +## License Info Copyright 2011-2019 Xilinx, Inc. diff --git a/examples/ap_fixed/Makefile b/examples/ap_fixed/Makefile new file mode 100644 index 0000000..5366811 --- /dev/null +++ b/examples/ap_fixed/Makefile @@ -0,0 +1,7 @@ +a.out: test.cpp + g++ -I../../include test.cpp + ./a.out + +.PHONY: clean +clean: + rm -rf a.out diff --git a/examples/ap_fixed/test.cpp b/examples/ap_fixed/test.cpp new file mode 100644 index 0000000..5e62ab8 --- /dev/null +++ b/examples/ap_fixed/test.cpp @@ -0,0 +1,20 @@ +#include "ap_fixed.h" +#include + +int main(int argc, const char* argv[]) { + + ap_ufixed<28, 4> a = 11.3137; + std::cout << "a = " << a << " (" << a.to_string(AP_HEX) << ")\n"; + +#if __cplusplus >= 201103L + ap_ufixed<28, 4> b = 0xB.504F33p0; // hex-float +#else + ap_ufixed<28, 4> b = "0xB.504F33p0"; +#endif + std::cout << "b = " << b << " (" << b.to_string(AP_HEX) << ")\n"; + + ap_ufixed<29, 5> c = a + b; + std::cout << "c = a + b = " << c.to_double() << " (" << c.to_string(AP_HEX) << ")" << std::endl; + + return 0; +} diff --git a/examples/ap_int/Makefile b/examples/ap_int/Makefile new file mode 100644 index 0000000..c0c307e --- /dev/null +++ b/examples/ap_int/Makefile @@ -0,0 +1,7 @@ +a.out: test.cpp + g++ -I../../include test.cpp -std=c++11 + ./a.out + +.PHONY: clean +clean: + rm -rf a.out diff --git a/examples/ap_int/test.cpp b/examples/ap_int/test.cpp new file mode 100644 index 0000000..38d0eb7 --- /dev/null +++ b/examples/ap_int/test.cpp @@ -0,0 +1,16 @@ +#include "ap_int.h" +#include + +int main(int argc, const char* argv[]) { + + ap_int<5> a = 11; + std::cout << "a = " << a << " (" << a.to_string(AP_HEX) << ")\n"; + + ap_uint<65> b = "0x1ffffffff"; + std::cout << "b = " << b << " (" << b.to_string(AP_HEX) << ")\n"; + + auto c = a + b; + std::cout << "c = a + b = " << c.to_double() << " (" << c.to_string(AP_HEX) << ")" << std::endl; + + return 0; +}