sPyNNaker neural_modelling 7.1.1
Loading...
Searching...
No Matches
decay.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2015 The University of Manchester
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * https://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
36#ifndef _DECAY_H_
37#define _DECAY_H_
38
39#include <common/maths-util.h>
41
45
52static inline s1615 decay_s1615(s1615 x, decay_t decay) {
53 int64_t s = (int64_t) bitsk(x);
54 int64_t u = (int64_t) bitsulr(decay);
55
56 return kbits((int_k_t) ((s * u) >> 32));
57}
58
65static inline u1616 decay_u1616(u1616 x, decay_t decay) {
66 uint64_t s = (uint64_t) bitsuk(x);
67 uint64_t u = (uint64_t) bitsulr(decay);
68
69 return ukbits((uint_uk_t) ((s * u) >> 32));
70}
71
78static inline s015 decay_s015(s015 x, decay_t decay) {
79 int64_t s = (int64_t) bitsk(x);
80 int64_t u = (int64_t) bitsulr(decay);
81
82 return rbits((int_r_t) ((s * u) >> 32));
83}
84
91static inline u016 decay_u016(u016 x, decay_t decay) {
92 uint64_t s = (uint64_t) bitsuk(x);
93 uint64_t u = (uint64_t) bitsulr(decay);
94
95 return urbits((uint_ur_t) ((s * u) >> 32));
96}
97
98static inline u032 decay_s1615_to_u032(s1615 x, decay_t decay) {
99 uint64_t s = (uint64_t) bitsk(x);
100 uint64_t u = (uint64_t) bitsulr(decay);
101
102 return ulrbits((uint_ulr_t) ((s * u) >> 15));
103}
104
105// The following permits us to do a type-generic macro for decay manipulation
106/*----------------------------------
107 * This method is currently assumed to be faulty. Please do not use it yet.
108 * Plan is to fix method and not need to use the private methods directly.
109 * issue seems to be in __builtin_types_compatible_p always returning False
110 * or at least, that there's the impression that on some types it results in
111 * the abort statement and therefore kills scripts dead on SpiNNaker.
112 * ---------------------------------
113 */
118#define decay(x, d) ({ \
119 __typeof__(x) tmp = (x); \
120 if (__builtin_types_compatible_p(__typeof__(x), s1615)) {\
121 tmp = decay_s1615(x, d); \
122 } else if (__builtin_types_compatible_p(__typeof__(x), u1616)) {\
123 tmp = decay_u1616(x, d); \
124 } else if (__builtin_types_compatible_p(__typeof__(x), s015)) {\
125 tmp = decay_s015(x, d); \
126 } else if (__builtin_types_compatible_p(__typeof__(x), u016)) {\
127 tmp = decay_u016(x, d); \
128 } else {\
129 abort(1); \
130 }\
131 tmp; \
132})
133
134#endif // _DECAY_H_
#define decay(x, d)
This is a type-generic decay "function".
Definition decay.h:118
UFRACT decay_t
Definition decay.h:44
static u1616 decay_u1616(u1616 x, decay_t decay)
this method takes a s1616 and decays it by a given amount (denoted by the decay) (to compensate for t...
Definition decay.h:65
static s1615 decay_s1615(s1615 x, decay_t decay)
this method takes a s1615 and decays it by a given amount (denoted by the decay) (to compensate for t...
Definition decay.h:52
static u016 decay_u016(u016 x, decay_t decay)
this method takes a s016 and decays it by a given amount (denoted by the decay) (to compensate for th...
Definition decay.h:91
static s015 decay_s015(s015 x, decay_t decay)
this method takes a s015 and decays it by a given amount (denoted by the decay) (to compensate for th...
Definition decay.h:78
maths-util.h - first created 7/10/2013 version 0.1
unsigned long fract UFRACT
Type used for "unsigned fractional" numbers.
Definition maths-util.h:98
Data type definitions for SpiNNaker Neuron-modelling.
int16_t int_r_t
uint32_t uint_ulr_t
unsigned fract u016
unsigned accum u1616
uint16_t uint_ur_t
fract s015
uint32_t uint_uk_t
int32_t int_k_t
accum s1615
unsigned long fract u032