New self-explanatory examples

This commit is contained in:
Camille Monière 2022-02-14 16:10:10 +01:00
parent 084b5bbd8b
commit 7a58367433
Signed by: moniere
GPG key ID: 188DD5B072181C0F
4 changed files with 73 additions and 2 deletions

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;
}