Skip to content
Snippets Groups Projects
Commit 92d03b6c authored by Aron Leibfried's avatar Aron Leibfried
Browse files

Remove most preprocessor macros

As suggested by issue #3101

Change-Id: I68be58a329f08348fa900fc26bce6e50625120d0
parent 622807d5
No related branches found
No related tags found
No related merge requests found
#pragma once
#if defined(SYSTEM_HICANN_DLS_MINI)
# define NUM_SLICES (1)
# define NUM_BYTES_PER_SLICE (16)
#elif defined(SYSTEM_HICANN_DLS)
# define NUM_SLICES (8)
# define NUM_BYTES_PER_SLICE (16)
#else
# error "You must define the target system!"
#endif
#define NUM_BYTES_PER_ARRAY (NUM_BYTES_PER_SLICE * NUM_SLICES)
#define NUM_HALFWORDS_PER_ARRAY (NUM_BYTES_PER_ARRAY/2)
#define NUM_WORDS_PER_ARRAY (NUM_HALFWORDS_PER_ARRAY/2)
......@@ -22,6 +22,11 @@ constexpr static uint32_t dls_num_synapses = dls_num_rows * dls_num_columns;
/* Vector size */
constexpr static uint32_t dls_vector_size = 128;
constexpr static uint32_t dls_vector_slices = 8;
constexpr static uint32_t dls_bytes_per_vector_slice = 16;
constexpr static uint32_t dls_bytes_per_vector = dls_bytes_per_vector_slice * dls_vector_slices;
constexpr static uint32_t dls_halfwords_per_vector = dls_bytes_per_vector / 2;
constexpr static uint32_t dls_words_per_vector = dls_halfwords_per_vector / 2;
/* Number of vectors per row */
constexpr static uint32_t dls_num_vectors_per_row = 2;
......
#pragma once
#include <stdint.h>
#include "libnux/constants.h"
#include "libnux/dls.h"
//--------------------------------------------------------------------------------
......@@ -9,9 +9,9 @@
//--------------------------------------------------------------------------------
typedef union {
int32_t words[NUM_WORDS_PER_ARRAY];
int16_t halfwords[NUM_HALFWORDS_PER_ARRAY];
int8_t bytes[NUM_BYTES_PER_ARRAY];
int32_t words[dls_words_per_vector];
int16_t halfwords[dls_halfwords_per_vector];
int8_t bytes[dls_bytes_per_vector];
} fxv_array_t;
typedef enum {
......@@ -27,136 +27,8 @@ typedef enum {
} fxv_reorder_t;
//--------------------------------------------------------------------------------
// Macros
//--------------------------------------------------------------------------------
#define _fxv_store_array(v, reg) \
asm volatile ( \
"fxvstax " #reg ", 0, %[o]\n" \
:: [o] "r" (v) \
)
#define fxv_store_array(a, b) _fxv_store_array(a, b)
#define _fxv_load_array(reg, v) \
asm volatile ( \
"fxvlax " #reg ", 0, %[o]\n" \
:: [o] "r" (v) \
)
#define fxv_load_array(a, b) _fxv_load_array(a, b)
#define _fxv_pack_halfwords(upper, lower, ra, rb, size) \
asm volatile ( \
"fxvpckbu " #upper ", " #ra ", " #rb ", " #size "\n" \
"fxvpckbl " #lower ", " #ra ", " #rb ", " #size "\n" \
);
#define fxv_pack_halfwords(a, b, c, d) _fxv_pack_halfwords(a, b, c, d, 0)
#define fxv_pack_halfwords_padded(a, b, c, d, e) _fxv_pack_halfwords(a, b, c, d, e)
#define _fxv_unpack_to_halfwords(ra, rb, upper, lower, size) \
asm volatile ( \
"fxvupckbl " #ra ", " #upper ", " #lower ", " #size "\n" \
"fxvupckbr " #rb ", " #upper ", " #lower ", " #size "\n" \
)
#define fxv_unpack_to_halfwords(a, b, c, d) _fxv_unpack_to_halfwords(a, b, c, d, 0)
#define fxv_unpack_to_halfwords_padded(a, b, c, d, e) _fxv_unpack_to_halfwords(a, b, c, d, e)
//--------------------------------------------------------------------------------
// Arithmetic vector instructions
//--------------------------------------------------------------------------------
#define _fxv_insn3(op, rt, ra, rb) asm volatile(op " " #rt ", " #ra ", " #rb)
#define _fxv_insn3_cond(op, rt, ra, rb, cond) asm volatile(op " " #rt ", " #ra ", " #rb ", " #cond)
#define _fxv_insn2(op, rt, ra) asm volatile(op " " #rt ", " #ra)
#define _fxv_insn_gpr1(op, rt, gpra) asm volatile(op " " #rt ", %[a]" :: [a] "r"(gpra))
#define _fxv_insn1(op, rt) asm volatile(op " " #rt)
// modulo halfword arithmetic
#define fxv_addhm(x, y, z) _fxv_insn3("fxvaddhm", x, y, z)
#define fxv_addhm_gt(x, y, z) _fxv_insn3_cond("fxvaddhm", x, y, z, 1)
#define fxv_addhm_lt(x, y, z) _fxv_insn3_cond("fxvaddhm", x, y, z, 2)
#define fxv_addhm_eq(x, y, z) _fxv_insn3_cond("fxvaddhm", x, y, z, 3)
#define fxv_subhm(x, y, z) _fxv_insn3("fxvsubhm", x, y, z)
#define fxv_cmph(x) _fxv_insn1("fxvcmph", x)
#define fxv_mulhm(x, y, z) _fxv_insn3("fxvmulhm", x, y, z)
#define fxv_mtach(x) _fxv_insn1("fxvmtach", x)
#define fxv_mahm(x, y, z) _fxv_insn3("fxvmahm", x, y, z)
#define fxv_mahm_gt(x, y, z) _fxv_insn3_cond("fxvmahm", x, y, z, 1)
#define fxv_mahm_lt(x, y, z) _fxv_insn3_cond("fxvmahm", x, y, z, 2)
// fractional halfword arithmetic
#define fxv_addhfs(x, y, z) _fxv_insn3("fxvaddhfs", x, y, z)
#define fxv_addhfs_lt(x, y, z) _fxv_insn3_cond("fxvaddhfs", x, y, z, 2)
#define fxv_subhfs(x, y, z) _fxv_insn3("fxvsubhfs", x, y, z)
#define fxv_mulhfs(x, y, z) _fxv_insn3("fxvmulhfs", x, y, z)
#define fxv_mahfs(x, y, z) _fxv_insn3("fxvmahfs", x, y, z)
#define fxv_mahfs_gt(x, y, z) _fxv_insn3_cond("fxvmahfs", x, y, z, 1)
#define fxv_mahfs_lt(x, y, z) _fxv_insn3_cond("fxvmahfs", x, y, z, 2)
#define fxv_matachfs(x, y) _fxv_insn2("fxvmatachfs", x, y)
#define fxv_mtachf(x) _fxv_insn1("fxvmtachf", x)
// fractional halfword arithmetic
#define fxv_addbm(x, y, z) _fxv_insn3("fxvaddbm", x, y, z)
#define fxv_addbm_gt(x, y, z) _fxv_insn3_cond("fxvaddbm", x, y, z, 1)
#define fxv_addbm_lt(x, y, z) _fxv_insn3_cond("fxvaddbm", x, y, z, 2)
#define fxv_addbm_eq(x, y, z) _fxv_insn3_cond("fxvaddbm", x, y, z, 3)
#define fxv_subbm(x, y, z) _fxv_insn3("fxvsubbm", x, y, z)
#define fxv_cmpb(x) _fxv_insn1("fxvcmpb", x)
#define fxv_mulbm(x, y, z) _fxv_insn3("fxvmulbm", x, y, z)
#define fxv_mtacb(x) _fxv_insn1("fxvmtacb", x)
#define fxv_mabm(x, y, z) _fxv_insn3("fxvmabm", x, y, z)
#define fxv_mabm_gt(x, y, z) _fxv_insn3_cond("fxvmabm", x, y, z, 1)
#define fxv_mabm_lt(x, y, z) _fxv_insn3_cond("fxvmabm", x, y, z, 2)
// fractional byte arithmetic
#define fxv_addbfs(x, y, z) _fxv_insn3("fxvaddbfs", x, y, z)
#define fxv_addbfs_lt(x, y, z) _fxv_insn3_cond("fxvaddbfs", x, y, z, 2)
#define fxv_addtacb(x, y) _fxv_insn2("fxvaddtacb", x, y)
#define fxv_subbfs(x, y, z) _fxv_insn3("fxvsubbfs", x, y, z)
#define fxv_mulbfs(x, y, z) _fxv_insn3("fxvmulbfs", x, y, z)
#define fxv_mabfs(x, y, z) _fxv_insn3("fxvmabfs", x, y, z)
#define fxv_mabfs_gt(x, y, z) _fxv_insn3_cond("fxvmabfs", x, y, z, 1)
#define fxv_mabfs_lt(x, y, z) _fxv_insn3_cond("fxvmabfs", x, y, z, 2)
#define fxv_mtacbf(x) _fxv_insn1("fxvmtacbf", x)
// special operations
#define fxv_splath(x, y) _fxv_insn_gpr1("fxvsplath", x, y)
/** Bugfix for fxvsplatb in HICANN-DLS v1 !
* This instruction has incorrect hazard detection for the general-purpose register
* argument. E.g.:
* lis r9, 15
* fxvsplatb 1, r9
* will use the old value of register r9.
*
* The fix uses the fxvsplath instruction, which does hazard detection correctly. */
//#define fxv_splatb(x, y) _fxv_insn_gpr1("fxvsplatb", x, y)
#define _fxv_splatb(rt, gpra) \
asm volatile("fxvsplath " #rt ", %[a]" \
:: [a] "r"( (( (gpra) & 0xff) << 8) | ( (gpra) & 0xff) ))
#define fxv_splatb(x, y) _fxv_splatb(x, y)
/* End of bugfix for fxvsplatb */
// shift operations
#define fxv_shh(x, y, z) _fxv_insn3("fxvshh", x, y, z)
#define fxv_shb(x, y, z) _fxv_insn3("fxvshb", x, y, z)
// select operation
#define fxv_sel_gt(x, y, z) _fxv_insn3_cond("fxvsel", x, y, z, 1)
#define fxv_sel_lt(x, y, z) _fxv_insn3_cond("fxvsel", x, y, z, 2)
#define fxv_sel_eq(x, y, z) _fxv_insn3_cond("fxvsel", x, y, z, 3)
#define fxv_mov(x, y) _fxv_insn3("fxvsel", x, 0, y)
//--------------------------------------------------------------------------------
// Other operations
//--------------------------------------------------------------------------------
#define fxv_zero_set(x) fxv_splath(x, 0)
extern void fxv_zero_vrf();
......@@ -9,7 +9,6 @@
#include "libnux/time.h"
constexpr static uint32_t default_ppu_cycles_per_us = 250;
#define USEC default_ppu_cycles_per_us // Only correct for default PLL settings (Issue #3705)
void sleep_cycles(uint32_t cycles);
......
......@@ -35,7 +35,7 @@ void libnux_test_inc_failed(void);
#define LIBNUX_TEST_TO_STRING(x) LIBNUX_TEST_STRINGIFY(x)
#ifdef LIBNUX_TEST_MODE_VERBOSE
#define libnux_test_write_passed(msg, args) \
#define LIBNUX_TEST_WRITE_PASSED(msg, args) \
do { \
libnux_test_write_string(__FILE__); \
libnux_test_write_string(":"); \
......@@ -47,10 +47,10 @@ void libnux_test_inc_failed(void);
libnux_test_write_string(")\n"); \
} while (0)
#else
#define libnux_test_write_passed(msg, args)
#define LIBNUX_TEST_WRITE_PASSED(msg, args)
#endif /* write_passed */
#define libnux_test_write_failed(msg, args) \
#define LIBNUX_TEST_WRITE_FAILED(msg, args) \
do { \
libnux_test_write_string(__FILE__); \
libnux_test_write_string(":"); \
......@@ -62,43 +62,69 @@ void libnux_test_inc_failed(void);
libnux_test_write_string(")\n"); \
} while (0)
#define libnux_test_failed(msg, args) \
#define LIBNUX_TEST_FAILED(msg, args) \
do { \
libnux_test_write_failed(msg, args); \
LIBNUX_TEST_WRITE_FAILED(msg, args); \
libnux_test_inc_failed(); \
if (libnux_test_get_action() == libnux_test_action_shutdown) { \
libnux_test_shutdown(); \
} \
} while (0)
#define libnux_test_passed(msg, args) \
#define LIBNUX_TEST_PASSED(msg, args) \
do { \
libnux_test_write_passed(msg, args); \
LIBNUX_TEST_WRITE_PASSED(msg, args); \
libnux_test_inc_passed(); \
} while (0)
/* Checks */
/* Check macros */
#define libnux_test(cond, msg, args) \
#define LIBNUX_TEST(cond, msg, args) \
do { \
if ( (cond) ) { \
libnux_test_passed(msg, args); \
LIBNUX_TEST_PASSED(msg, args); \
} else { \
libnux_test_failed(msg, args); \
LIBNUX_TEST_FAILED(msg, args); \
} \
} while (0)
#define libnux_test_equal(fst, snd) \
libnux_test( (fst) == (snd), "equal", #fst ", " #snd)
#define LIBNUX_TEST_EQUAL(fst, snd) \
LIBNUX_TEST( (fst) == (snd), "equal", #fst ", " #snd)
#define libnux_test_true(cond) \
libnux_test( (cond), "true", #cond)
#define LIBNUX_TEST_TRUE(cond) \
LIBNUX_TEST( (cond), "true", #cond)
#define libnux_test_null(ptr) \
libnux_test( (ptr) == (void*)0, "null", #ptr)
#define LIBNUX_TEST_NULL(ptr) \
LIBNUX_TEST( (ptr) == (void*)0, "null", #ptr)
#define libnux_test_not_null(ptr) \
libnux_test( (ptr) != (void*)0, "not_null", #ptr)
#define LIBNUX_TEST_NOT_NULL(ptr) \
LIBNUX_TEST( (ptr) != (void*)0, "not_null", #ptr)
/* Check functions */
template<typename T, typename U>
void libnux_test_equal(const T &fst, const U &snd)
{
LIBNUX_TEST_EQUAL(fst, snd);
}
template<typename T>
void libnux_test_true(const T &cond)
{
LIBNUX_TEST_TRUE(cond);
}
template<typename T>
void libnux_test_null(const T &ptr)
{
LIBNUX_TEST_NULL(ptr);
}
template<typename T>
void libnux_test_not_null(const T &ptr)
{
LIBNUX_TEST_NOT_NULL(ptr);
}
/* Testcases */
......@@ -108,3 +134,17 @@ void libnux_testcase_end(void);
/* Test summary */
void libnux_test_summary(void);
/* not needed outside */
#undef LIBNUX_TEST_STRINGIFY
#undef LIBNUX_TEST_TO_STRING
#undef LIBNUX_TEST_WRITE_PASSED
#undef LIBNUX_TEST_WRITE_FAILED
#undef LIBNUX_TEST_FAILED
#undef LIBNUX_TEST_PASSED
#undef LIBNUX_TEST
#undef LIBNUX_TEST_EQUAL
#undef LIBNUX_TEST_TRUE
#undef LIBNUX_TEST_NULL
#undef LIBNUX_TEST_NOT_NULL
#include <stddef.h>
#include <stdint.h>
#include "libnux/fxv.h"
#include "libnux/constants.h"
#include "libnux/dls.h"
#include "libnux/sync.h"
void fxv_zero_vrf() {
int i;
volatile uint8_t zeros[NUM_BYTES_PER_ARRAY];
for(i=0; i<NUM_BYTES_PER_ARRAY; i++) {
volatile uint8_t zeros[dls_bytes_per_vector];
for(size_t i = 0; i < dls_bytes_per_vector; i++) {
zeros[i] = 0;
}
sync();
......
......@@ -5,6 +5,6 @@ void send_uniform_spiketrain(spike_t* single_spike, uint32_t number, uint32_t is
uint32_t i;
for (i = number; i > 0; i--) {
send_spike(single_spike);
sleep_cycles(isi_usec * USEC);
sleep_cycles(isi_usec * default_ppu_cycles_per_us);
}
}
#include <s2pp.h>
#include <stddef.h>
#include "libnux/unittest.h"
// needed for current gcc-nux
......@@ -14,7 +15,7 @@
void test_size()
{
libnux_testcase_begin("size == 1B");
libnux_test_equal(sizeof(bool), 1);
libnux_test_equal(sizeof(bool), static_cast<size_t>(1));
libnux_testcase_end();
}
......
......@@ -8,32 +8,32 @@ void test_abs_diff()
{
uint8_t u8bit_1 = 150;
uint8_t u8bit_2 = 15;
libnux_test_equal(abs_diff(u8bit_1, u8bit_2), 135);
libnux_test_equal(abs_diff(u8bit_1, u8bit_2), static_cast<uint8_t>(135));
uint16_t u16bit_1 = 300;
uint16_t u16bit_2 = 3000;
libnux_test_equal(abs_diff(u16bit_1, u16bit_2), 2700);
libnux_test_equal(abs_diff(u16bit_1, u16bit_2), static_cast<uint16_t>(2700));
uint32_t u32bit_1 = 100;
uint32_t u32bit_2 = 100;
libnux_test_equal(abs_diff(u32bit_1, u32bit_2), 0);
libnux_test_equal(abs_diff(u32bit_1, u32bit_2), static_cast<uint32_t>(0));
int8_t s8bit_1 = -10;
int8_t s8bit_2 = -20;
libnux_test_equal(abs_diff(s8bit_1, s8bit_2), 10);
libnux_test_equal(abs_diff(s8bit_1, s8bit_2), static_cast<int8_t>(10));
int16_t s16bit_1 = -1000;
int16_t s16bit_2 = -100;
libnux_test_equal(abs_diff(s16bit_1, s16bit_2), 900);
libnux_test_equal(abs_diff(s16bit_1, s16bit_2), static_cast<int16_t>(900));
}
void test_find_max_amount()
{
std::array<uint8_t, 10> array_1{4, 17, 193, 4, 193, 10, 5, 3, 4, 0};
libnux_test_equal(find_max_amount(array_1), 4);
libnux_test_equal(find_max_amount(array_1), static_cast<uint8_t>(4));
std::array<uint16_t, 5> array_2{1600, 300, 1600, 300, 1600};
libnux_test_equal(find_max_amount(array_2), 1600);
libnux_test_equal(find_max_amount(array_2), static_cast<uint16_t>(1600));
}
void start()
......
#include <s2pp.h>
#include <stddef.h>
#include "libnux/mailbox.h"
#include "libnux/unittest.h"
......@@ -113,10 +114,10 @@ void test_vector_alignment() {
libnux_test_equal(local_small, 0xff);
libnux_test_equal(local_second[0], 0x30);
libnux_test_equal(((uint32_t)&global_first) % sizeof(__vector uint8_t), 0);
libnux_test_equal(((uint32_t)&global_second) % sizeof(__vector uint8_t), 0);
libnux_test_equal(((uint32_t)&local_first) % sizeof(__vector uint8_t), 0);
libnux_test_equal(((uint32_t)&local_second) % sizeof(__vector uint8_t), 0);
libnux_test_equal(((uint32_t)&global_first) % sizeof(__vector uint8_t), static_cast<size_t>(0));
libnux_test_equal(((uint32_t)&global_second) % sizeof(__vector uint8_t), static_cast<size_t>(0));
libnux_test_equal(((uint32_t)&local_first) % sizeof(__vector uint8_t), static_cast<size_t>(0));
libnux_test_equal(((uint32_t)&local_second) % sizeof(__vector uint8_t), static_cast<size_t>(0));
dump_vector(&global_first);
dump_vector(&global_second);
......
......@@ -5,7 +5,7 @@ int start()
{
libnux::reset_neurons();
sleep_cycles(USEC * 10);
sleep_cycles(10 * default_ppu_cycles_per_us);
__vector uint8_t even = vec_splat_u8(1);
__vector uint8_t odd = vec_splat_u8(0);
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment