Add examples and update readme

This closes #1, and closes #2.
This commit is contained in:
Yuanjie Huang 2019-02-25 14:46:40 +08:00
parent 68d27300a1
commit 0d857f63a9
5 changed files with 72 additions and 1 deletions

View file

@ -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.

View file

@ -0,0 +1,7 @@
a.out: test.cpp
g++ -I../../include test.cpp
./a.out
.PHONY: clean
clean:
rm -rf a.out

View file

@ -0,0 +1,20 @@
#include "ap_fixed.h"
#include <iostream>
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;
}

7
examples/ap_int/Makefile Normal file
View file

@ -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

16
examples/ap_int/test.cpp Normal file
View file

@ -0,0 +1,16 @@
#include "ap_int.h"
#include <iostream>
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;
}