mirror of
https://github.com/DrasLorus/HLS_arbitrary_Precision_Types.git
synced 2024-07-06 14:35:18 +02:00
parent
68d27300a1
commit
0d857f63a9
23
README.MD
23
README.MD
|
@ -1,10 +1,31 @@
|
||||||
# HLS Arbitrary Precision Types Library
|
# HLS Arbitrary Precision Types Library
|
||||||
|
|
||||||
This repo provides simulation code of HLS Arbitrary Precision Types.
|
This repo provides simulation code of HLS Arbitrary Precision Types.
|
||||||
|
|
||||||
The code is based from headers shipped with Vivado,
|
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**.
|
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.
|
Copyright 2011-2019 Xilinx, Inc.
|
||||||
|
|
||||||
|
|
7
examples/ap_fixed/Makefile
Normal file
7
examples/ap_fixed/Makefile
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
a.out: test.cpp
|
||||||
|
g++ -I../../include test.cpp
|
||||||
|
./a.out
|
||||||
|
|
||||||
|
.PHONY: clean
|
||||||
|
clean:
|
||||||
|
rm -rf a.out
|
20
examples/ap_fixed/test.cpp
Normal file
20
examples/ap_fixed/test.cpp
Normal 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
7
examples/ap_int/Makefile
Normal 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
16
examples/ap_int/test.cpp
Normal 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;
|
||||||
|
}
|
Loading…
Reference in a new issue