Compare commits

...

2 commits

Author SHA1 Message Date
Camille Monière 7a58367433
New self-explanatory examples 2022-02-14 16:10:10 +01:00
Camille Monière 084b5bbd8b
Update package helpers 2022-02-14 12:09:23 +01:00
12 changed files with 199 additions and 30 deletions

4
.gitignore vendored
View file

@ -39,7 +39,9 @@
test
# packages
packages/tarball/*.tar.gz
packages/tarball/*
!packages/tarball/makefile
!packages/tarball/make_tarball.sh
packages/debian/*
!packages/debian/control

View file

@ -1,5 +1,6 @@
#
# Copyright 2019 Xilinx, Inc.
# Copyright 2022 DrasLorus
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@ -13,10 +14,25 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
all: a.out ex1.out ex2.out ex3.out
a.out: test.cpp
g++ -I../../include test.cpp -std=c++11
g++ -I../../include test.cpp -std=c++14 -o a.out
./a.out
ex1.out: ap_int_manip_ex.cpp
g++ -I../../include ap_int_manip_ex.cpp -std=c++14 -o ex1.out
./ex1.out
ex2.out: ap_int_manip_ex2.cpp
g++ -I../../include ap_int_manip_ex2.cpp -std=c++14 -o ex2.out
./ex2.out
ex3.out: ap_int_manip_ex3.cpp
g++ -I../../include ap_int_manip_ex3.cpp -std=c++14 -o ex3.out
./ex3.out
.PHONY: clean
clean:
rm -rf a.out
rm -rf *.out

View file

@ -0,0 +1,20 @@
#include <ap_int.h>
#include <iostream>
using namespace std;
int main(int, char **) {
const ap_int<16> A = -3987;
const ap_int<16> s_A = ~(A >> 2) + 1;
cout << A << " " << s_A << " " << round(3987. / 4) << endl;
const bool Ri[2] = {false, true};
const ap_int<16> R_val[2] = {-int8_t(Ri[0]), -int8_t(Ri[1])};
const ap_int<16> ps_A = (R_val[0] ^ (A >> 2)) + Ri[0];
const ap_int<16> ms_A = (R_val[1] ^ (A >> 2)) + Ri[1];
cout << ps_A << " " << ms_A << endl;
return 0;
}

View file

@ -0,0 +1,17 @@
#include <ap_int.h>
#include <cstdio>
#include <iostream>
using namespace std;
int main(int, char **) {
const ap_int<32> A = 0xDEADBEEF;
const ap_int<32> s_A = ~(A >> 2) + 1;
cout << A << " " << s_A << " " << (int64_t) round(-1. * A.to_float() / 4.) << endl;
const ap_int<16> dead = A(31, 16);
const ap_int<16> beaf = A(15, 0);
printf("%08x || %04x || %04x\n", A.to_uint(), dead.to_int(), beaf.to_int());
return 0;
}

View file

@ -0,0 +1,18 @@
#include <ap_int.h>
#include <cstdio>
#include <iostream>
using namespace std;
int main(int, char **) {
const ap_int<8> A = 79; // 0x4F = 79
const ap_int<4> msb_A_4bits = A(7, 4); // 0x4 = 4
const ap_int<4> lsb_A_4bits = A(3, 0); // 0xF = -1
const ap_int<8> msb_A_8bits = A(7, 4); // 0x04 = 4
const ap_int<8> lsb_A_8bits = A(3, 0); // 0x0F = 15
printf("%d || %d || %d\n", A.to_int(), msb_A_4bits.to_int(), lsb_A_4bits.to_int());
printf("%d || %d || %d\n", A.to_int(), msb_A_8bits.to_int(), lsb_A_8bits.to_int());
return 0;
}

17
packages/ap_fixed.h Normal file
View file

@ -0,0 +1,17 @@
/*
* Copyright 2022 DrasLorus.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <ap_types/ap_fixed.h>

17
packages/ap_int.h Normal file
View file

@ -0,0 +1,17 @@
/*
* Copyright 2022 DrasLorus.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <ap_types/ap_int.h>

View file

@ -1,5 +1,5 @@
Package: hls-ap-types
Version: 0.0.1
Version: 0.0.1.rc2
Maintainer: Camille 'DrasLorus' Monière <draslorus@draslorus.fr>
Depends:
Architecture: all

View file

@ -1,8 +1,30 @@
#! /bin/sh
version="$(grep "Version" control | cut -d ' ' -f 2)"
mkdir -p hls-ap-types_"$version"-1_all/usr/include/ap_types
cp -r ../../include hls-ap-types_"$version"-1_all/usr/include/ap_types
#
# Copyright 2022 DrasLorus.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
version="$(grep "Version" control | cut -d ' ' -f 2)"
deb_dir="hls-ap-types_$version-1_all"
include_dir="$deb_dir/usr/include"
rm -rfv "$deb_dir"
install -dm755 "$include_dir"/ap_types/etc
install -m644 -t "$include_dir"/ap_types ../../include/*.h
install -Dm644 -t "$include_dir"/ap_types/etc ../../include/etc/ap_private.h
install -m644 -t "$include_dir"/ ../ap_*.h
mkdir -p hls-ap-types_"$version"-1_all/DEBIAN
cp control hls-ap-types_"$version"-1_all/DEBIAN

View file

@ -1,28 +1,21 @@
# This is an example PKGBUILD file. Use this as a start to creating your own,
# and remove these comments. For more information, see 'man PKGBUILD'.
# NOTE: Please fill out the license field for your package! If it is unknown,
# then please put 'unknown'.
# Maintainer: Your Name <youremail@domain.com>
# Maintainer: DrasLorus <draslorus@draslorus.fr>
pkgname=hls-ap-types
pkgver=0.0.1.rc1
pkgver=0.0.1.rc2
pkgrel=1
pkgdesc="AP types for everyone"
arch=('any')
url="https://github.com/DrasLorus/HLS_arbitrary_Precision_Types"
license=('apache2.0')
license=('Apache')
source=("$pkgname-$pkgver::https://github.com/DrasLorus/HLS_arbitrary_Precision_Types/releases/download/v0.0.1-RC1/hls-ap-types-0.0.1-RC1.tar.gz")
sha256sums=('f3efea6d742bac7cb99d9b4b7ff718ce82a5f9c6d9f7a4334aca9750ad7cd9fd')
source=("https://github.com/DrasLorus/HLS_arbitrary_Precision_Types/releases/download/v${pkgver}/${pkgname}-${pkgver}.tar.gz")
sha256sums=('90837e08801ab75f9084c6070a14ee60cae0d78b6a4bec47f1b49a4b9772b90d')
package() {
cd "$srcdir"
_files="$(find include -name .h)"
make PREFIX="${pkgdir}" install
install -dvm644 "${pkgdir}/usr/share/licenses/hls-ap-types/LICENSE" LICENSE.txt
install -dm755 "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
install -m644 -t "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE" "${pkgname}-${pkgver}/LICENSE.TXT"
}

View file

@ -1,2 +1,30 @@
#! /bin/sh
tar -cvzf hls-ap-types-0.0.1-RC1.tar.gz ../../include makefile ../../LICENSE.TXT
#
# Copyright 2022 DrasLorus.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
version="0.0.1.rc2"
tar_dir="hls-ap-types-$version"
rm -rfv "$tar_dir"
install -dm755 "$tar_dir"/ap_types/etc
install -m644 -t "$tar_dir"/ ../../LICENSE.TXT
install -m644 -t "$tar_dir"/ap_types ../../include/*.h
install -Dm644 -t "$tar_dir"/ap_types/etc ../../include/etc/ap_private.h
install -m644 -t "$tar_dir"/ ../ap_*.h
tar -cvzf "$tar_dir".tar.gz "$tar_dir" makefile

View file

@ -1,15 +1,34 @@
files:=$(wildcard include/*.h)
files+=include/etc/ap_private.h
#
# Copyright 2022 DrasLorus.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
tar_dir=hls-ap-types-0.0.1.rc2
ap_types_files:=$(wildcard $(tar_dir)/ap_types/*.h)
top_files:=$(wildcard $(tar_dir)/*.h)
priv_files:=$(wildcard $(tar_dir)/ap_types/etc/*.h)
all: install
install:
@install -dvm755 $(PREFIX)/usr/include/ap_types
@install -vm644 -t $(PREFIX)/usr/include/ap_types/ $(files)
@ln -vs ap_types/ap_fixed.h $(PREFIX)/usr/include/ap_fixed.h
@ln -vs ap_types/ap_int.h $(PREFIX)/usr/include/ap_int.h
install -dCm755 $(PREFIX)/usr/include/ap_types/etc
install -Cm644 -t $(PREFIX)/usr/include $(top_files)
install -Cm644 -t $(PREFIX)/usr/include/ap_types/ $(ap_types_files)
install -Cm644 -t $(PREFIX)/usr/include/ap_types/etc $(priv_files)
uninstall:
unlink $(PREFIX)/usr/include/ap_fixed.h
unlink $(PREFIX)/usr/include/ap_int.h
rm $(PREFIX)/usr/include/ap_fixed.h
rm $(PREFIX)/usr/include/ap_int.h
@rm -rv $(PREFIX)/usr/include/ap_types