Skip to content

Commit

Permalink
C++: Use int32_t and int64_t instead of int/long/long long
Browse files Browse the repository at this point in the history
Either long or long long is redundant, depending on whether we are on Unix or Windows
  • Loading branch information
mstimberg committed Dec 15, 2023
1 parent 454dc5d commit 92a7c39
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions brian2/codegen/generators/cpp_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def c_data_type(dtype):
)


typestrs = ["int", "long", "long long", "float", "double", "long double"]
typestrs = ["int32_t", "int64_t", "float", "double", "long double"]
floattypestrs = ["float", "double", "long double"]
hightype_support_code = "template < typename T1, typename T2 > struct _higher_type;\n"
for ix, xtype in enumerate(typestrs):
Expand All @@ -112,33 +112,33 @@ def c_data_type(dtype):
// Specific implementations for integer types
// (from Cython, see LICENSE file)
template <>
inline int _brian_mod(int x, int y)
inline int32_t _brian_mod(int32_t x, int32_t y)
{
int r = x % y;
int32_t r = x % y;
r += ((r != 0) & ((r ^ y) < 0)) * y;
return r;
}
template <>
inline long _brian_mod(int x, long y)
inline int64_t _brian_mod(int32_t x, int64_t y)
{
long r = x % y;
int64_t r = x % y;
r += ((r != 0) & ((r ^ y) < 0)) * y;
return r;
}
template <>
inline long _brian_mod(long x, int y)
inline int64_t _brian_mod(int64_t x, int32_t y)
{
long r = x % y;
int64_t r = x % y;
r += ((r != 0) & ((r ^ y) < 0)) * y;
return r;
}
template <>
inline long _brian_mod(long x, long y)
inline int64_t _brian_mod(int64_t x, int64_t y)
{
long r = x % y;
int64_t r = x % y;
r += ((r != 0) & ((r ^ y) < 0)) * y;
return r;
}
Expand All @@ -156,30 +156,30 @@ def c_data_type(dtype):
// Specific implementations for integer types
// (from Cython, see LICENSE file)
template <>
inline int _brian_floordiv<int, int>(int a, int b) {
int q = a / b;
int r = a - q*b;
inline int32_t _brian_floordiv<int32_t, int32_t>(int32_t a, int32_t b) {
int32_t q = a / b;
int32_t r = a - q*b;
q -= ((r != 0) & ((r ^ b) < 0));
return q;
}
template <>
inline long _brian_floordiv<int, long>(int a, long b) {
long q = a / b;
long r = a - q*b;
inline int64_t _brian_floordiv<int32_t, int64_t>(int32_t a, int64_t b) {
int64_t q = a / b;
int64_t r = a - q*b;
q -= ((r != 0) & ((r ^ b) < 0));
return q;
}
template <>
inline long _brian_floordiv<long, int>(long a, int b) {
long q = a / b;
long r = a - q*b;
inline int64_t _brian_floordiv<int64_t, int>(int64_t a, int32_t b) {
int64_t q = a / b;
int64_t r = a - q*b;
q -= ((r != 0) & ((r ^ b) < 0));
return q;
}
template <>
inline long _brian_floordiv<long, long>(long a, long b) {
long q = a / b;
long r = a - q*b;
inline int64_t _brian_floordiv<int64_t, int64_t>(int64_t a, int64_t b) {
int64_t q = a / b;
int64_t r = a - q*b;
q -= ((r != 0) & ((r ^ b) < 0));
return q;
}
Expand Down

0 comments on commit 92a7c39

Please sign in to comment.