1 #ifndef RBIMPL_ARITHMETIC_LONG_H
2 #define RBIMPL_ARITHMETIC_LONG_H
31 #include "ruby/internal/config.h"
40 #include "ruby/internal/cast.h"
46 #define FIX2LONG RB_FIX2LONG
47 #define FIX2ULONG RB_FIX2ULONG
48 #define INT2FIX RB_INT2FIX
49 #define LONG2FIX RB_INT2FIX
50 #define LONG2NUM RB_LONG2NUM
51 #define NUM2LONG RB_NUM2LONG
52 #define NUM2ULONG RB_NUM2ULONG
53 #define RB_FIX2LONG rb_fix2long
54 #define RB_FIX2ULONG rb_fix2ulong
55 #define RB_LONG2FIX RB_INT2FIX
56 #define RB_LONG2NUM rb_long2num_inline
57 #define RB_NUM2LONG rb_num2long_inline
58 #define RB_NUM2ULONG rb_num2ulong_inline
59 #define RB_ULONG2NUM rb_ulong2num_inline
60 #define ULONG2NUM RB_ULONG2NUM
61 #define rb_fix_new RB_INT2FIX
62 #define rb_long2int rb_long2int_inline
65 #define RB_INT2FIX RB_INT2FIX
117 const unsigned long j = RBIMPL_CAST((
unsigned long)i);
119 const long l = RBIMPL_CAST((
long)k);
137 int i = RBIMPL_CAST((
int)n);
139 if (
sizeof(long) <=
sizeof(
int)) {
162 rbimpl_fix2long_by_idiv(
VALUE x)
171 const long w = RBIMPL_CAST((
long)z);
190 rbimpl_fix2long_by_shift(
VALUE x)
198 const long w = RBIMPL_CAST((
long)z);
216 rbimpl_right_shift_is_arithmetic_p(
void)
218 return (-1 >> 1) == -1;
233 if (rbimpl_right_shift_is_arithmetic_p()) {
234 return rbimpl_fix2long_by_shift(x);
237 return rbimpl_fix2long_by_idiv(x);
251 static
inline unsigned long
292 static inline unsigned long
339 #if RBIMPL_HAS_ATTR_CONSTEXPR_CXX14
342 #elif ! defined(HAVE_BUILTIN___BUILTIN_CHOOSE_EXPR_CONSTANT_P)
344 # define INT2FIX(i) (RBIMPL_CAST((VALUE)(i)) << 1 | RUBY_FIXNUM_FLAG)
348 # define INT2FIX(i) \
349 __builtin_choose_expr( \
350 __builtin_constant_p(i), \
351 RBIMPL_CAST((VALUE)(i)) << 1 | RUBY_FIXNUM_FLAG, \
Defines RBIMPL_ATTR_ARTIFICIAL.
#define RBIMPL_ATTR_ARTIFICIAL()
Wraps (or simulates) __attribute__((artificial))
#define RBIMPL_ASSERT_OR_ASSUME(...)
This is either RUBY_ASSERT or RBIMPL_ASSUME, depending on RUBY_DEBUG.
Defines RBIMPL_ATTR_COLD.
#define RBIMPL_ATTR_COLD()
Wraps (or simulates) __attribute__((cold))
Defines RBIMPL_ATTR_CONST.
#define RBIMPL_ATTR_CONST_UNLESS_DEBUG()
Enables RBIMPL_ATTR_CONST if and only if.
#define RBIMPL_ATTR_CONSTEXPR(_)
Wraps (or simulates) C++11 constexpr.
#define RBIMPL_ATTR_CONSTEXPR_UNLESS_DEBUG(_)
Enables RBIMPL_ATTR_CONSTEXPR if and only if.
Tweaking visibility of C variables/functions.
#define RBIMPL_SYMBOL_EXPORT_END()
Counterpart of RBIMPL_SYMBOL_EXPORT_BEGIN.
#define RBIMPL_SYMBOL_EXPORT_BEGIN()
Shortcut macro equivalent to RUBY_SYMBOL_EXPORT_BEGIN extern "C" {.
Handling of integers formerly known as Fixnums.
#define RB_FIXABLE(_)
Checks if the passed value is in range of fixnum.
#define RB_POSFIXABLE(_)
Checks if the passed value is in range of fixnum, assuming it is a positive number.
RBIMPL_ATTR_CONST() int rb_io_oflags_fmode(int oflags)
Converts an oflags (that rb_io_modestr_oflags() returns) to a fmode (that rb_io_mode_flags() returns)...
RBIMPL_ATTR_NORETURN() void rb_eof_error(void)
Utility function to raise rb_eEOFError.
Defines RBIMPL_ASSUME / RBIMPL_UNREACHABLE.
#define RBIMPL_ASSUME
Wraps (or simulates) __assume.
Arithmetic conversion between C's intptr_t and Ruby's.
VALUE rb_uint2big(uintptr_t i)
Converts a C's intptr_t into an instance of rb_cInteger.
VALUE rb_int2big(intptr_t i)
Converts a C's intptr_t into an instance of rb_cInteger.
static long rb_num2long_inline(VALUE x)
Converts an instance of rb_cNumeric into C's long.
static VALUE RB_INT2FIX(long i)
Converts a C's long into an instance of rb_cInteger.
#define RB_FIX2ULONG
Just another name of rb_fix2ulong.
static unsigned long rb_num2ulong_inline(VALUE x)
Converts an instance of rb_cNumeric into C's unsigned long.
static int rb_long2int_inline(long n)
Checks if int can hold the given integer.
static VALUE rb_ulong2num_inline(unsigned long v)
Converts a C's unsigned long into an instance of rb_cInteger.
static long rb_fix2long(VALUE x)
Converts a Fixnum into C's long.
#define RB_FIX2LONG
Just another name of rb_fix2long.
void rb_out_of_int(SIGNED_VALUE num)
This is an utility function to raise an rb_eRangeError.
long rb_num2long(VALUE num)
Converts an instance of rb_cNumeric into C's long.
#define RB_LONG2FIX
Just another name of RB_INT2FIX.
unsigned long rb_num2ulong(VALUE num)
Converts an instance of rb_cNumeric into C's unsigned long.
static VALUE rb_long2num_inline(long v)
Converts a C's long into an instance of rb_cInteger.
static unsigned long rb_fix2ulong(VALUE x)
Converts a Fixnum into C's unsigned long.
Defines RBIMPL_ATTR_NORETURN.
#define inline
Old Visual Studio versions do not support the inline keyword, so we need to define it to be __inline.
Defines enum ruby_special_consts.
static bool RB_FIXNUM_P(VALUE obj)
Checks if the given object is a so-called Fixnum.
@ RUBY_FIXNUM_FLAG
Flag to denote a fixnum.
intptr_t SIGNED_VALUE
A signed integer type that has the same width with VALUE.
uintptr_t VALUE
Type that represents a Ruby object.