Skip to content

Commit

Permalink
fixes #13645
Browse files Browse the repository at this point in the history
  • Loading branch information
Araq committed Mar 16, 2020
1 parent 0f67237 commit b9b53b6
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions lib/nimbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -549,22 +549,24 @@ typedef int Nim_and_C_compiler_disagree_on_target_architecture[sizeof(NI) == siz
#define nimModInt(a, b, res) (((*res) = (a) % (b)), 0)
#define nimModInt64(a, b, res) (((*res) = (a) % (b)), 0)

/* these exist because we cannot have .compilerProcs that are importc'ed
by a different name */

#define nimAddInt64(a, b, res) __builtin_saddll_overflow(a, b, (long long int*)res)
#define nimSubInt64(a, b, res) __builtin_ssubll_overflow(a, b, (long long int*)res)
#define nimMulInt64(a, b, res) __builtin_smulll_overflow(a, b, (long long int*)res)

#if NIM_INTBITS == 32
#define nimAddInt(a, b, res) __builtin_sadd_overflow(a, b, res)
#define nimSubInt(a, b, res) __builtin_ssub_overflow(a, b, res)
#define nimMulInt(a, b, res) __builtin_smul_overflow(a, b, res)
#else
/* map it to the 'long long' variant */
#define nimAddInt(a, b, res) __builtin_saddll_overflow(a, b, (long long int*)res)
#define nimSubInt(a, b, res) __builtin_ssubll_overflow(a, b, (long long int*)res)
#define nimMulInt(a, b, res) __builtin_smulll_overflow(a, b, (long long int*)res)
#if !defined(_MSC_VER)
/* these exist because we cannot have .compilerProcs that are importc'ed
by a different name */

#define nimAddInt64(a, b, res) __builtin_saddll_overflow(a, b, (long long int*)res)
#define nimSubInt64(a, b, res) __builtin_ssubll_overflow(a, b, (long long int*)res)
#define nimMulInt64(a, b, res) __builtin_smulll_overflow(a, b, (long long int*)res)

#if NIM_INTBITS == 32
#define nimAddInt(a, b, res) __builtin_sadd_overflow(a, b, res)
#define nimSubInt(a, b, res) __builtin_ssub_overflow(a, b, res)
#define nimMulInt(a, b, res) __builtin_smul_overflow(a, b, res)
#else
/* map it to the 'long long' variant */
#define nimAddInt(a, b, res) __builtin_saddll_overflow(a, b, (long long int*)res)
#define nimSubInt(a, b, res) __builtin_ssubll_overflow(a, b, (long long int*)res)
#define nimMulInt(a, b, res) __builtin_smulll_overflow(a, b, (long long int*)res)
#endif
#endif

#endif /* NIMBASE_H */

0 comments on commit b9b53b6

Please sign in to comment.