Coverage Report

Created: 2026-03-31 07:30

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ruby/internal/bits.h
Line
Count
Source
1
#ifndef INTERNAL_BITS_H                                  /*-*-C-*-vi:se ft=c:*/
2
#define INTERNAL_BITS_H
3
/**
4
 * @author     Ruby developers <ruby-core@ruby-lang.org>
5
 * @copyright  This  file  is   a  part  of  the   programming  language  Ruby.
6
 *             Permission  is hereby  granted,  to  either redistribute  and/or
7
 *             modify this file, provided that  the conditions mentioned in the
8
 *             file COPYING are met.  Consult the file for details.
9
 * @brief      Internal header for bitwise integer algorithms.
10
 * @see        Henry S. Warren Jr., "Hacker's Delight" (2nd ed.), 2013.
11
 * @see        SEI CERT C Coding Standard  INT32-C.  "Ensure that operations on
12
 *             signed integers do not result in overflow"
13
 * @see        https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html
14
 * @see        https://clang.llvm.org/docs/LanguageExtensions.html#builtin-rotateleft
15
 * @see        https://clang.llvm.org/docs/LanguageExtensions.html#builtin-rotateright
16
 * @see        https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/byteswap-uint64-byteswap-ulong-byteswap-ushort
17
 * @see        https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/rotl-rotl64-rotr-rotr64
18
 * @see        https://docs.microsoft.com/en-us/cpp/intrinsics/bitscanforward-bitscanforward64
19
 * @see        https://docs.microsoft.com/en-us/cpp/intrinsics/bitscanreverse-bitscanreverse64
20
 * @see        https://docs.microsoft.com/en-us/cpp/intrinsics/lzcnt16-lzcnt-lzcnt64
21
 * @see        https://docs.microsoft.com/en-us/cpp/intrinsics/popcnt16-popcnt-popcnt64
22
 * @see        https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_lzcnt_u32
23
 * @see        https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_tzcnt_u32
24
 * @see        https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_rotl64
25
 * @see        https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_rotr64
26
 * @see        https://stackoverflow.com/a/776523
27
 */
28
#include "ruby/internal/config.h"
29
#include <limits.h>             /* for CHAR_BITS */
30
#include <stdint.h>             /* for uintptr_t */
31
#include "internal/compilers.h" /* for MSC_VERSION_SINCE */
32
33
#ifdef _MSC_VER
34
# include <stdlib.h>            /* for _byteswap_uint64 */
35
#endif
36
37
#if defined(HAVE_X86INTRIN_H)
38
# include <x86intrin.h>         /* for _lzcnt_u64 */
39
#elif defined(_MSC_VER)
40
# include <intrin.h>            /* for the following intrinsics */
41
#endif
42
43
#if defined(_MSC_VER) && defined(__AVX__)
44
# pragma intrinsic(__popcnt)
45
# pragma intrinsic(__popcnt64)
46
#endif
47
48
#if defined(_MSC_VER) && defined(__AVX2__)
49
# pragma intrinsic(__lzcnt)
50
# pragma intrinsic(__lzcnt64)
51
#endif
52
53
#if defined(_MSC_VER)
54
# pragma intrinsic(_rotl)
55
# pragma intrinsic(_rotr)
56
# ifdef _WIN64
57
#  pragma intrinsic(_rotl64)
58
#  pragma intrinsic(_rotr64)
59
# endif
60
# pragma intrinsic(_BitScanForward)
61
# pragma intrinsic(_BitScanReverse)
62
# ifdef _WIN64
63
#  pragma intrinsic(_BitScanForward64)
64
#  pragma intrinsic(_BitScanReverse64)
65
# endif
66
#endif
67
68
#include "ruby/ruby.h"              /* for VALUE */
69
#include "internal/static_assert.h" /* for STATIC_ASSERT */
70
71
/* The most significant bit of the lower part of half-long integer.
72
 * If sizeof(long) == 4, this is 0x8000.
73
 * If sizeof(long) == 8, this is 0x80000000.
74
 */
75
1.31k
#define HALF_LONG_MSB ((SIGNED_VALUE)1<<((SIZEOF_LONG*CHAR_BIT-1)/2))
76
77
#define SIGNED_INTEGER_TYPE_P(T) (0 > ((T)0)-1)
78
79
#define SIGNED_INTEGER_MIN(T)                           \
80
0
    ((sizeof(T) == sizeof(int8_t))  ? ((T)INT8_MIN)  :  \
81
0
    ((sizeof(T) == sizeof(int16_t)) ? ((T)INT16_MIN) :  \
82
0
    ((sizeof(T) == sizeof(int32_t)) ? ((T)INT32_MIN) :  \
83
0
    ((sizeof(T) == sizeof(int64_t)) ? ((T)INT64_MIN) :  \
84
0
     0))))
85
86
0
#define SIGNED_INTEGER_MAX(T) ((T)(SIGNED_INTEGER_MIN(T) ^ ((T)~(T)0)))
87
88
#define UNSIGNED_INTEGER_MAX(T) ((T)~(T)0)
89
90
#ifndef MUL_OVERFLOW_SIGNED_INTEGER_P
91
#if __has_builtin(__builtin_mul_overflow_p)
92
# define MUL_OVERFLOW_P(a, b) \
93
    __builtin_mul_overflow_p((a), (b), (__typeof__(a * b))0)
94
#elif __has_builtin(__builtin_mul_overflow)
95
# define MUL_OVERFLOW_P(a, b) \
96
13.6k
    __extension__ ({ __typeof__(a) c; __builtin_mul_overflow((a), (b), &c); })
97
#endif
98
99
332
#define MUL_OVERFLOW_SIGNED_INTEGER_P(a, b, min, max) ( \
100
332
    (a) == 0 ? 0 : \
101
332
    (a) == -1 ? (b) < -(max) : \
102
332
    (a) > 0 ? \
103
332
      ((b) > 0 ? (max) / (a) < (b) : (min) / (a) > (b)) : \
104
332
      ((b) > 0 ? (min) / (a) < (b) : (max) / (a) > (b)))
105
106
#if __has_builtin(__builtin_mul_overflow_p)
107
/* __builtin_mul_overflow_p can take bitfield */
108
/* and GCC permits bitfields for integers other than int */
109
# define MUL_OVERFLOW_FIXNUM_P(a, b) \
110
    __extension__ ({ \
111
        struct { long fixnum : sizeof(long) * CHAR_BIT - 1; } c = { 0 }; \
112
        __builtin_mul_overflow_p((a), (b), c.fixnum); \
113
    })
114
#else
115
# define MUL_OVERFLOW_FIXNUM_P(a, b) \
116
332
    MUL_OVERFLOW_SIGNED_INTEGER_P(a, b, FIXNUM_MIN, FIXNUM_MAX)
117
#endif
118
119
#if defined(MUL_OVERFLOW_P) && defined(USE___BUILTIN_MUL_OVERFLOW_LONG_LONG)
120
0
# define MUL_OVERFLOW_LONG_LONG_P(a, b) MUL_OVERFLOW_P(a, b)
121
#else
122
# define MUL_OVERFLOW_LONG_LONG_P(a, b) MUL_OVERFLOW_SIGNED_INTEGER_P(a, b, LLONG_MIN, LLONG_MAX)
123
#endif
124
125
#ifdef MUL_OVERFLOW_P
126
11.7k
# define MUL_OVERFLOW_LONG_P(a, b)      MUL_OVERFLOW_P(a, b)
127
0
# define MUL_OVERFLOW_INT_P(a, b)       MUL_OVERFLOW_P(a, b)
128
#else
129
# define MUL_OVERFLOW_LONG_P(a, b)      MUL_OVERFLOW_SIGNED_INTEGER_P(a, b, LONG_MIN, LONG_MAX)
130
# define MUL_OVERFLOW_INT_P(a, b)       MUL_OVERFLOW_SIGNED_INTEGER_P(a, b, INT_MIN, INT_MAX)
131
#endif
132
#endif
133
134
#ifndef ADD_OVERFLOW_SIGNED_INTEGER_P
135
#if __has_builtin(__builtin_add_overflow_p)
136
# define ADD_OVERFLOW_P(a, b) \
137
    __builtin_add_overflow_p((a), (b), (__typeof__(a * b))0)
138
#elif __has_builtin(__builtin_add_overflow)
139
# define ADD_OVERFLOW_P(a, b) \
140
5.37k
    __extension__ ({ __typeof__(a) c; __builtin_add_overflow((a), (b), &c); })
141
#endif
142
143
#define ADD_OVERFLOW_SIGNED_INTEGER_P(a, b, min, max) ( \
144
    (a) > 0 ? (b) > (max) - (a) : (b) < (min) - (a))
145
146
#if __has_builtin(__builtin_add_overflow_p)
147
/* __builtin_add_overflow_p can take bitfield */
148
/* and GCC permits bitfields for integers other than int */
149
# define ADD_OVERFLOW_FIXNUM_P(a, b) \
150
    __extension__ ({ \
151
        struct { long fixnum : sizeof(long) * CHAR_BIT - 1; } c = { 0 }; \
152
        __builtin_add_overflow_p((a), (b), c.fixnum); \
153
    })
154
#else
155
# define ADD_OVERFLOW_FIXNUM_P(a, b) \
156
    ADD_OVERFLOW_SIGNED_INTEGER_P(a, b, FIXNUM_MIN, FIXNUM_MAX)
157
#endif
158
159
#if defined(ADD_OVERFLOW_P) && defined(USE___BUILTIN_ADD_OVERFLOW_LONG_LONG)
160
# define ADD_OVERFLOW_LONG_LONG_P(a, b) ADD_OVERFLOW_P(a, b)
161
#else
162
# define ADD_OVERFLOW_LONG_LONG_P(a, b) ADD_OVERFLOW_SIGNED_INTEGER_P(a, b, LLONG_MIN, LLONG_MAX)
163
#endif
164
165
#ifdef ADD_OVERFLOW_P
166
5.37k
# define ADD_OVERFLOW_LONG_P(a, b)      ADD_OVERFLOW_P(a, b)
167
# define ADD_OVERFLOW_INT_P(a, b)       ADD_OVERFLOW_P(a, b)
168
#else
169
# define ADD_OVERFLOW_LONG_P(a, b)      ADD_OVERFLOW_SIGNED_INTEGER_P(a, b, LONG_MIN, LONG_MAX)
170
# define ADD_OVERFLOW_INT_P(a, b)       ADD_OVERFLOW_SIGNED_INTEGER_P(a, b, INT_MIN, INT_MAX)
171
#endif
172
#endif
173
174
#ifndef SUB_OVERFLOW_SIGNED_INTEGER_P
175
#if __has_builtin(__builtin_sub_overflow_p)
176
# define SUB_OVERFLOW_P(a, b) \
177
    __builtin_sub_overflow_p((a), (b), (__typeof__(a * b))0)
178
#elif __has_builtin(__builtin_sub_overflow)
179
# define SUB_OVERFLOW_P(a, b) \
180
    __extension__ ({ __typeof__(a) c; __builtin_sub_overflow((a), (b), &c); })
181
#endif
182
183
#define SUB_OVERFLOW_SIGNED_INTEGER_P(a, b, min, max) ( \
184
        (b) > 0 ? (a) < (min) + (b) : (a) > (max) + (b))
185
186
#if __has_builtin(__builtin_sub_overflow_p)
187
/* __builtin_sub_overflow_p can take bitfield */
188
/* and GCC permits bitfields for integers other than int */
189
# define SUB_OVERFLOW_FIXNUM_P(a, b) \
190
    __extension__ ({ \
191
        struct { long fixnum : sizeof(long) * CHAR_BIT - 1; } c = { 0 }; \
192
        __builtin_sub_overflow_p((a), (b), c.fixnum); \
193
    })
194
#else
195
# define SUB_OVERFLOW_FIXNUM_P(a, b) \
196
    SUB_OVERFLOW_SIGNED_INTEGER_P(a, b, FIXNUM_MIN, FIXNUM_MAX)
197
#endif
198
199
#if defined(SUB_OVERFLOW_P) && defined(USE___BUILTIN_SUB_OVERFLOW_LONG_LONG)
200
# define SUB_OVERFLOW_LONG_LONG_P(a, b) SUB_OVERFLOW_P(a, b)
201
#else
202
# define SUB_OVERFLOW_LONG_LONG_P(a, b) SUB_OVERFLOW_SIGNED_INTEGER_P(a, b, LLONG_MIN, LLONG_MAX)
203
#endif
204
205
#ifdef SUB_OVERFLOW_P
206
# define SUB_OVERFLOW_LONG_P(a, b)      SUB_OVERFLOW_P(a, b)
207
# define SUB_OVERFLOW_INT_P(a, b)       SUB_OVERFLOW_P(a, b)
208
#else
209
# define SUB_OVERFLOW_LONG_P(a, b)      SUB_OVERFLOW_SIGNED_INTEGER_P(a, b, LONG_MIN, LONG_MAX)
210
# define SUB_OVERFLOW_INT_P(a, b)       SUB_OVERFLOW_SIGNED_INTEGER_P(a, b, INT_MIN, INT_MAX)
211
#endif
212
#endif
213
214
#ifdef HAVE_UINT128_T
215
# define bit_length(x) \
216
24.8k
    (unsigned int) \
217
24.8k
    (sizeof(x) <= sizeof(int32_t) ? 32 - nlz_int32((uint32_t)(x)) : \
218
24.8k
     sizeof(x) <= sizeof(int64_t) ? 64 - nlz_int64((uint64_t)(x)) : \
219
0
                                   128 - nlz_int128((uint128_t)(x)))
220
#else
221
# define bit_length(x) \
222
    (unsigned int) \
223
    (sizeof(x) <= sizeof(int32_t) ? 32 - nlz_int32((uint32_t)(x)) : \
224
                                    64 - nlz_int64((uint64_t)(x)))
225
#endif
226
227
#ifndef swap16
228
0
# define swap16 ruby_swap16
229
#endif
230
231
#ifndef swap32
232
0
# define swap32 ruby_swap32
233
#endif
234
235
#ifndef swap64
236
0
# define swap64 ruby_swap64
237
#endif
238
239
static inline uint16_t ruby_swap16(uint16_t);
240
static inline uint32_t ruby_swap32(uint32_t);
241
static inline uint64_t ruby_swap64(uint64_t);
242
static inline unsigned nlz_int(unsigned x);
243
static inline unsigned nlz_long(unsigned long x);
244
static inline unsigned nlz_long_long(unsigned long long x);
245
static inline unsigned nlz_intptr(uintptr_t x);
246
static inline unsigned nlz_int32(uint32_t x);
247
static inline unsigned nlz_int64(uint64_t x);
248
#ifdef HAVE_UINT128_T
249
static inline unsigned nlz_int128(uint128_t x);
250
#endif
251
static inline unsigned rb_popcount32(uint32_t x);
252
static inline unsigned rb_popcount64(uint64_t x);
253
static inline unsigned rb_popcount_intptr(uintptr_t x);
254
static inline int ntz_int32(uint32_t x);
255
static inline int ntz_int64(uint64_t x);
256
static inline int ntz_intptr(uintptr_t x);
257
static inline VALUE RUBY_BIT_ROTL(VALUE, int);
258
static inline VALUE RUBY_BIT_ROTR(VALUE, int);
259
260
static inline uint16_t
261
ruby_swap16(uint16_t x)
262
0
{
263
0
#if __has_builtin(__builtin_bswap16)
264
0
    return __builtin_bswap16(x);
265
266
#elif defined(_MSC_VER)
267
    return _byteswap_ushort(x);
268
269
#else
270
    return (x << 8) | (x >> 8);
271
272
#endif
273
0
}
Unexecuted instantiation: array.c:ruby_swap16
Unexecuted instantiation: bignum.c:ruby_swap16
Unexecuted instantiation: complex.c:ruby_swap16
Unexecuted instantiation: enum.c:ruby_swap16
Unexecuted instantiation: enumerator.c:ruby_swap16
Unexecuted instantiation: gc.c:ruby_swap16
Unexecuted instantiation: hash.c:ruby_swap16
Unexecuted instantiation: io.c:ruby_swap16
Unexecuted instantiation: io_buffer.c:ruby_swap16
Unexecuted instantiation: iseq.c:ruby_swap16
Unexecuted instantiation: load.c:ruby_swap16
Unexecuted instantiation: marshal.c:ruby_swap16
Unexecuted instantiation: node_dump.c:ruby_swap16
Unexecuted instantiation: numeric.c:ruby_swap16
Unexecuted instantiation: object.c:ruby_swap16
Unexecuted instantiation: pack.c:ruby_swap16
Unexecuted instantiation: process.c:ruby_swap16
Unexecuted instantiation: ractor.c:ruby_swap16
Unexecuted instantiation: random.c:ruby_swap16
Unexecuted instantiation: range.c:ruby_swap16
Unexecuted instantiation: rational.c:ruby_swap16
Unexecuted instantiation: re.c:ruby_swap16
Unexecuted instantiation: ruby.c:ruby_swap16
Unexecuted instantiation: ruby_parser.c:ruby_swap16
Unexecuted instantiation: set.c:ruby_swap16
Unexecuted instantiation: sprintf.c:ruby_swap16
Unexecuted instantiation: st.c:ruby_swap16
Unexecuted instantiation: string.c:ruby_swap16
Unexecuted instantiation: thread.c:ruby_swap16
Unexecuted instantiation: time.c:ruby_swap16
Unexecuted instantiation: vm.c:ruby_swap16
Unexecuted instantiation: vm_trace.c:ruby_swap16
Unexecuted instantiation: ast.c:ruby_swap16
Unexecuted instantiation: compile.c:ruby_swap16
Unexecuted instantiation: parse.c:ruby_swap16
274
275
static inline uint32_t
276
ruby_swap32(uint32_t x)
277
0
{
278
0
#if __has_builtin(__builtin_bswap32)
279
0
    return __builtin_bswap32(x);
280
281
#elif defined(_MSC_VER)
282
    return _byteswap_ulong(x);
283
284
#else
285
    x = ((x & 0x0000FFFF) << 16) | ((x & 0xFFFF0000) >> 16);
286
    x = ((x & 0x00FF00FF) <<  8) | ((x & 0xFF00FF00) >>  8);
287
    return x;
288
289
#endif
290
0
}
Unexecuted instantiation: array.c:ruby_swap32
Unexecuted instantiation: bignum.c:ruby_swap32
Unexecuted instantiation: complex.c:ruby_swap32
Unexecuted instantiation: enum.c:ruby_swap32
Unexecuted instantiation: enumerator.c:ruby_swap32
Unexecuted instantiation: gc.c:ruby_swap32
Unexecuted instantiation: hash.c:ruby_swap32
Unexecuted instantiation: io.c:ruby_swap32
Unexecuted instantiation: io_buffer.c:ruby_swap32
Unexecuted instantiation: iseq.c:ruby_swap32
Unexecuted instantiation: load.c:ruby_swap32
Unexecuted instantiation: marshal.c:ruby_swap32
Unexecuted instantiation: node_dump.c:ruby_swap32
Unexecuted instantiation: numeric.c:ruby_swap32
Unexecuted instantiation: object.c:ruby_swap32
Unexecuted instantiation: pack.c:ruby_swap32
Unexecuted instantiation: process.c:ruby_swap32
Unexecuted instantiation: ractor.c:ruby_swap32
Unexecuted instantiation: random.c:ruby_swap32
Unexecuted instantiation: range.c:ruby_swap32
Unexecuted instantiation: rational.c:ruby_swap32
Unexecuted instantiation: re.c:ruby_swap32
Unexecuted instantiation: ruby.c:ruby_swap32
Unexecuted instantiation: ruby_parser.c:ruby_swap32
Unexecuted instantiation: set.c:ruby_swap32
Unexecuted instantiation: sprintf.c:ruby_swap32
Unexecuted instantiation: st.c:ruby_swap32
Unexecuted instantiation: string.c:ruby_swap32
Unexecuted instantiation: thread.c:ruby_swap32
Unexecuted instantiation: time.c:ruby_swap32
Unexecuted instantiation: vm.c:ruby_swap32
Unexecuted instantiation: vm_trace.c:ruby_swap32
Unexecuted instantiation: ast.c:ruby_swap32
Unexecuted instantiation: compile.c:ruby_swap32
Unexecuted instantiation: parse.c:ruby_swap32
291
292
static inline uint64_t
293
ruby_swap64(uint64_t x)
294
0
{
295
0
#if __has_builtin(__builtin_bswap64)
296
0
    return __builtin_bswap64(x);
297
298
#elif defined(_MSC_VER)
299
    return _byteswap_uint64(x);
300
301
#else
302
    x = ((x & 0x00000000FFFFFFFFULL) << 32) | ((x & 0xFFFFFFFF00000000ULL) >> 32);
303
    x = ((x & 0x0000FFFF0000FFFFULL) << 16) | ((x & 0xFFFF0000FFFF0000ULL) >> 16);
304
    x = ((x & 0x00FF00FF00FF00FFULL) <<  8) | ((x & 0xFF00FF00FF00FF00ULL) >>  8);
305
    return x;
306
307
#endif
308
0
}
Unexecuted instantiation: array.c:ruby_swap64
Unexecuted instantiation: bignum.c:ruby_swap64
Unexecuted instantiation: complex.c:ruby_swap64
Unexecuted instantiation: enum.c:ruby_swap64
Unexecuted instantiation: enumerator.c:ruby_swap64
Unexecuted instantiation: gc.c:ruby_swap64
Unexecuted instantiation: hash.c:ruby_swap64
Unexecuted instantiation: io.c:ruby_swap64
Unexecuted instantiation: io_buffer.c:ruby_swap64
Unexecuted instantiation: iseq.c:ruby_swap64
Unexecuted instantiation: load.c:ruby_swap64
Unexecuted instantiation: marshal.c:ruby_swap64
Unexecuted instantiation: node_dump.c:ruby_swap64
Unexecuted instantiation: numeric.c:ruby_swap64
Unexecuted instantiation: object.c:ruby_swap64
Unexecuted instantiation: pack.c:ruby_swap64
Unexecuted instantiation: process.c:ruby_swap64
Unexecuted instantiation: ractor.c:ruby_swap64
Unexecuted instantiation: random.c:ruby_swap64
Unexecuted instantiation: range.c:ruby_swap64
Unexecuted instantiation: rational.c:ruby_swap64
Unexecuted instantiation: re.c:ruby_swap64
Unexecuted instantiation: ruby.c:ruby_swap64
Unexecuted instantiation: ruby_parser.c:ruby_swap64
Unexecuted instantiation: set.c:ruby_swap64
Unexecuted instantiation: sprintf.c:ruby_swap64
Unexecuted instantiation: st.c:ruby_swap64
Unexecuted instantiation: string.c:ruby_swap64
Unexecuted instantiation: thread.c:ruby_swap64
Unexecuted instantiation: time.c:ruby_swap64
Unexecuted instantiation: vm.c:ruby_swap64
Unexecuted instantiation: vm_trace.c:ruby_swap64
Unexecuted instantiation: ast.c:ruby_swap64
Unexecuted instantiation: compile.c:ruby_swap64
Unexecuted instantiation: parse.c:ruby_swap64
309
310
static inline unsigned int
311
nlz_int32(uint32_t x)
312
35.1k
{
313
#if defined(_MSC_VER) && defined(__AVX2__)
314
    /* Note: It seems there is no such thing like __LZCNT__ predefined in MSVC.
315
     * AMD  CPUs have  had this  instruction for  decades (since  K10) but  for
316
     * Intel, Haswell is  the oldest one.  We need to  use __AVX2__ for maximum
317
     * safety. */
318
    return (unsigned int)__lzcnt(x);
319
320
#elif defined(__x86_64__) && defined(__LZCNT__)
321
    return (unsigned int)_lzcnt_u32(x);
322
323
#elif defined(_MSC_VER) /* &&! defined(__AVX2__) */
324
    unsigned long r;
325
    return _BitScanReverse(&r, x) ? (31 - (int)r) : 32;
326
327
#elif __has_builtin(__builtin_clz)
328
35.1k
    STATIC_ASSERT(sizeof_int, sizeof(int) * CHAR_BIT == 32);
329
35.1k
    return x ? (unsigned int)__builtin_clz(x) : 32;
330
331
#else
332
    uint32_t y;
333
    unsigned n = 32;
334
    y = x >> 16; if (y) {n -= 16; x = y;}
335
    y = x >>  8; if (y) {n -=  8; x = y;}
336
    y = x >>  4; if (y) {n -=  4; x = y;}
337
    y = x >>  2; if (y) {n -=  2; x = y;}
338
    y = x >>  1; if (y) {return n - 2;}
339
    return (unsigned int)(n - x);
340
#endif
341
35.1k
}
Unexecuted instantiation: array.c:nlz_int32
bignum.c:nlz_int32
Line
Count
Source
312
35.1k
{
313
#if defined(_MSC_VER) && defined(__AVX2__)
314
    /* Note: It seems there is no such thing like __LZCNT__ predefined in MSVC.
315
     * AMD  CPUs have  had this  instruction for  decades (since  K10) but  for
316
     * Intel, Haswell is  the oldest one.  We need to  use __AVX2__ for maximum
317
     * safety. */
318
    return (unsigned int)__lzcnt(x);
319
320
#elif defined(__x86_64__) && defined(__LZCNT__)
321
    return (unsigned int)_lzcnt_u32(x);
322
323
#elif defined(_MSC_VER) /* &&! defined(__AVX2__) */
324
    unsigned long r;
325
    return _BitScanReverse(&r, x) ? (31 - (int)r) : 32;
326
327
#elif __has_builtin(__builtin_clz)
328
35.1k
    STATIC_ASSERT(sizeof_int, sizeof(int) * CHAR_BIT == 32);
329
35.1k
    return x ? (unsigned int)__builtin_clz(x) : 32;
330
331
#else
332
    uint32_t y;
333
    unsigned n = 32;
334
    y = x >> 16; if (y) {n -= 16; x = y;}
335
    y = x >>  8; if (y) {n -=  8; x = y;}
336
    y = x >>  4; if (y) {n -=  4; x = y;}
337
    y = x >>  2; if (y) {n -=  2; x = y;}
338
    y = x >>  1; if (y) {return n - 2;}
339
    return (unsigned int)(n - x);
340
#endif
341
35.1k
}
Unexecuted instantiation: complex.c:nlz_int32
Unexecuted instantiation: enum.c:nlz_int32
Unexecuted instantiation: enumerator.c:nlz_int32
Unexecuted instantiation: gc.c:nlz_int32
Unexecuted instantiation: hash.c:nlz_int32
Unexecuted instantiation: io.c:nlz_int32
Unexecuted instantiation: io_buffer.c:nlz_int32
Unexecuted instantiation: iseq.c:nlz_int32
Unexecuted instantiation: load.c:nlz_int32
Unexecuted instantiation: marshal.c:nlz_int32
Unexecuted instantiation: node_dump.c:nlz_int32
Unexecuted instantiation: numeric.c:nlz_int32
Unexecuted instantiation: object.c:nlz_int32
Unexecuted instantiation: pack.c:nlz_int32
Unexecuted instantiation: process.c:nlz_int32
Unexecuted instantiation: ractor.c:nlz_int32
Unexecuted instantiation: random.c:nlz_int32
Unexecuted instantiation: range.c:nlz_int32
Unexecuted instantiation: rational.c:nlz_int32
Unexecuted instantiation: re.c:nlz_int32
Unexecuted instantiation: ruby.c:nlz_int32
Unexecuted instantiation: ruby_parser.c:nlz_int32
Unexecuted instantiation: set.c:nlz_int32
Unexecuted instantiation: sprintf.c:nlz_int32
Unexecuted instantiation: st.c:nlz_int32
Unexecuted instantiation: string.c:nlz_int32
Unexecuted instantiation: thread.c:nlz_int32
Unexecuted instantiation: time.c:nlz_int32
Unexecuted instantiation: vm.c:nlz_int32
Unexecuted instantiation: vm_trace.c:nlz_int32
Unexecuted instantiation: ast.c:nlz_int32
Unexecuted instantiation: compile.c:nlz_int32
Unexecuted instantiation: parse.c:nlz_int32
342
343
static inline unsigned int
344
nlz_int64(uint64_t x)
345
43.7k
{
346
#if defined(_MSC_VER) && defined(__AVX2__)
347
    return (unsigned int)__lzcnt64(x);
348
349
#elif defined(__x86_64__) && defined(__LZCNT__)
350
    return (unsigned int)_lzcnt_u64(x);
351
352
#elif defined(_WIN64) && defined(_MSC_VER) /* &&! defined(__AVX2__) */
353
    unsigned long r;
354
    return _BitScanReverse64(&r, x) ? (63u - (unsigned int)r) : 64;
355
356
#elif __has_builtin(__builtin_clzl)
357
43.7k
    if (x == 0) {
358
21.3k
        return 64;
359
21.3k
    }
360
22.4k
    else if (sizeof(long) * CHAR_BIT == 64) {
361
22.4k
        return (unsigned int)__builtin_clzl((unsigned long)x);
362
22.4k
    }
363
0
    else if (sizeof(long long) * CHAR_BIT == 64) {
364
0
        return (unsigned int)__builtin_clzll((unsigned long long)x);
365
0
    }
366
0
    else {
367
        /* :FIXME: Is there a way to make this branch a compile-time error? */
368
0
        UNREACHABLE_RETURN(~0);
369
0
    }
370
371
#else
372
    uint64_t y;
373
    unsigned int n = 64;
374
    y = x >> 32; if (y) {n -= 32; x = y;}
375
    y = x >> 16; if (y) {n -= 16; x = y;}
376
    y = x >>  8; if (y) {n -=  8; x = y;}
377
    y = x >>  4; if (y) {n -=  4; x = y;}
378
    y = x >>  2; if (y) {n -=  2; x = y;}
379
    y = x >>  1; if (y) {return n - 2;}
380
    return (unsigned int)(n - x);
381
382
#endif
383
43.7k
}
Unexecuted instantiation: array.c:nlz_int64
Unexecuted instantiation: bignum.c:nlz_int64
Unexecuted instantiation: complex.c:nlz_int64
Unexecuted instantiation: enum.c:nlz_int64
Unexecuted instantiation: enumerator.c:nlz_int64
Unexecuted instantiation: gc.c:nlz_int64
Unexecuted instantiation: hash.c:nlz_int64
Unexecuted instantiation: io.c:nlz_int64
Unexecuted instantiation: io_buffer.c:nlz_int64
Unexecuted instantiation: iseq.c:nlz_int64
Unexecuted instantiation: load.c:nlz_int64
Unexecuted instantiation: marshal.c:nlz_int64
Unexecuted instantiation: node_dump.c:nlz_int64
Unexecuted instantiation: numeric.c:nlz_int64
Unexecuted instantiation: object.c:nlz_int64
Unexecuted instantiation: pack.c:nlz_int64
Unexecuted instantiation: process.c:nlz_int64
Unexecuted instantiation: ractor.c:nlz_int64
Unexecuted instantiation: random.c:nlz_int64
Unexecuted instantiation: range.c:nlz_int64
Unexecuted instantiation: rational.c:nlz_int64
Unexecuted instantiation: re.c:nlz_int64
Unexecuted instantiation: ruby.c:nlz_int64
Unexecuted instantiation: ruby_parser.c:nlz_int64
Unexecuted instantiation: set.c:nlz_int64
Unexecuted instantiation: sprintf.c:nlz_int64
st.c:nlz_int64
Line
Count
Source
345
43.7k
{
346
#if defined(_MSC_VER) && defined(__AVX2__)
347
    return (unsigned int)__lzcnt64(x);
348
349
#elif defined(__x86_64__) && defined(__LZCNT__)
350
    return (unsigned int)_lzcnt_u64(x);
351
352
#elif defined(_WIN64) && defined(_MSC_VER) /* &&! defined(__AVX2__) */
353
    unsigned long r;
354
    return _BitScanReverse64(&r, x) ? (63u - (unsigned int)r) : 64;
355
356
#elif __has_builtin(__builtin_clzl)
357
43.7k
    if (x == 0) {
358
21.3k
        return 64;
359
21.3k
    }
360
22.4k
    else if (sizeof(long) * CHAR_BIT == 64) {
361
22.4k
        return (unsigned int)__builtin_clzl((unsigned long)x);
362
22.4k
    }
363
0
    else if (sizeof(long long) * CHAR_BIT == 64) {
364
0
        return (unsigned int)__builtin_clzll((unsigned long long)x);
365
0
    }
366
0
    else {
367
        /* :FIXME: Is there a way to make this branch a compile-time error? */
368
0
        UNREACHABLE_RETURN(~0);
369
0
    }
370
371
#else
372
    uint64_t y;
373
    unsigned int n = 64;
374
    y = x >> 32; if (y) {n -= 32; x = y;}
375
    y = x >> 16; if (y) {n -= 16; x = y;}
376
    y = x >>  8; if (y) {n -=  8; x = y;}
377
    y = x >>  4; if (y) {n -=  4; x = y;}
378
    y = x >>  2; if (y) {n -=  2; x = y;}
379
    y = x >>  1; if (y) {return n - 2;}
380
    return (unsigned int)(n - x);
381
382
#endif
383
43.7k
}
Unexecuted instantiation: string.c:nlz_int64
Unexecuted instantiation: thread.c:nlz_int64
Unexecuted instantiation: time.c:nlz_int64
Unexecuted instantiation: vm.c:nlz_int64
Unexecuted instantiation: vm_trace.c:nlz_int64
Unexecuted instantiation: ast.c:nlz_int64
Unexecuted instantiation: compile.c:nlz_int64
Unexecuted instantiation: parse.c:nlz_int64
384
385
#ifdef HAVE_UINT128_T
386
static inline unsigned int
387
nlz_int128(uint128_t x)
388
0
{
389
0
    uint64_t y = (uint64_t)(x >> 64);
390
0
391
0
    if (x == 0) {
392
0
        return 128;
393
0
    }
394
0
    else if (y == 0) {
395
0
        return (unsigned int)nlz_int64(x) + 64;
396
0
    }
397
0
    else {
398
0
        return (unsigned int)nlz_int64(y);
399
0
    }
400
0
}
Unexecuted instantiation: array.c:nlz_int128
Unexecuted instantiation: bignum.c:nlz_int128
Unexecuted instantiation: complex.c:nlz_int128
Unexecuted instantiation: enum.c:nlz_int128
Unexecuted instantiation: enumerator.c:nlz_int128
Unexecuted instantiation: gc.c:nlz_int128
Unexecuted instantiation: hash.c:nlz_int128
Unexecuted instantiation: io.c:nlz_int128
Unexecuted instantiation: io_buffer.c:nlz_int128
Unexecuted instantiation: iseq.c:nlz_int128
Unexecuted instantiation: load.c:nlz_int128
Unexecuted instantiation: marshal.c:nlz_int128
Unexecuted instantiation: node_dump.c:nlz_int128
Unexecuted instantiation: numeric.c:nlz_int128
Unexecuted instantiation: object.c:nlz_int128
Unexecuted instantiation: pack.c:nlz_int128
Unexecuted instantiation: process.c:nlz_int128
Unexecuted instantiation: ractor.c:nlz_int128
Unexecuted instantiation: random.c:nlz_int128
Unexecuted instantiation: range.c:nlz_int128
Unexecuted instantiation: rational.c:nlz_int128
Unexecuted instantiation: re.c:nlz_int128
Unexecuted instantiation: ruby.c:nlz_int128
Unexecuted instantiation: ruby_parser.c:nlz_int128
Unexecuted instantiation: set.c:nlz_int128
Unexecuted instantiation: sprintf.c:nlz_int128
Unexecuted instantiation: st.c:nlz_int128
Unexecuted instantiation: string.c:nlz_int128
Unexecuted instantiation: thread.c:nlz_int128
Unexecuted instantiation: time.c:nlz_int128
Unexecuted instantiation: vm.c:nlz_int128
Unexecuted instantiation: vm_trace.c:nlz_int128
Unexecuted instantiation: ast.c:nlz_int128
Unexecuted instantiation: compile.c:nlz_int128
Unexecuted instantiation: parse.c:nlz_int128
401
#endif
402
403
static inline unsigned int
404
nlz_int(unsigned int x)
405
10.2k
{
406
10.2k
    if (sizeof(unsigned int) * CHAR_BIT == 32) {
407
10.2k
        return nlz_int32((uint32_t)x);
408
10.2k
    }
409
0
    else if (sizeof(unsigned int) * CHAR_BIT == 64) {
410
0
        return nlz_int64((uint64_t)x);
411
0
    }
412
0
    else {
413
0
        UNREACHABLE_RETURN(~0);
414
0
    }
415
10.2k
}
Unexecuted instantiation: array.c:nlz_int
bignum.c:nlz_int
Line
Count
Source
405
10.2k
{
406
10.2k
    if (sizeof(unsigned int) * CHAR_BIT == 32) {
407
10.2k
        return nlz_int32((uint32_t)x);
408
10.2k
    }
409
0
    else if (sizeof(unsigned int) * CHAR_BIT == 64) {
410
0
        return nlz_int64((uint64_t)x);
411
0
    }
412
0
    else {
413
0
        UNREACHABLE_RETURN(~0);
414
0
    }
415
10.2k
}
Unexecuted instantiation: complex.c:nlz_int
Unexecuted instantiation: enum.c:nlz_int
Unexecuted instantiation: enumerator.c:nlz_int
Unexecuted instantiation: gc.c:nlz_int
Unexecuted instantiation: hash.c:nlz_int
Unexecuted instantiation: io.c:nlz_int
Unexecuted instantiation: io_buffer.c:nlz_int
Unexecuted instantiation: iseq.c:nlz_int
Unexecuted instantiation: load.c:nlz_int
Unexecuted instantiation: marshal.c:nlz_int
Unexecuted instantiation: node_dump.c:nlz_int
Unexecuted instantiation: numeric.c:nlz_int
Unexecuted instantiation: object.c:nlz_int
Unexecuted instantiation: pack.c:nlz_int
Unexecuted instantiation: process.c:nlz_int
Unexecuted instantiation: ractor.c:nlz_int
Unexecuted instantiation: random.c:nlz_int
Unexecuted instantiation: range.c:nlz_int
Unexecuted instantiation: rational.c:nlz_int
Unexecuted instantiation: re.c:nlz_int
Unexecuted instantiation: ruby.c:nlz_int
Unexecuted instantiation: ruby_parser.c:nlz_int
Unexecuted instantiation: set.c:nlz_int
Unexecuted instantiation: sprintf.c:nlz_int
Unexecuted instantiation: st.c:nlz_int
Unexecuted instantiation: string.c:nlz_int
Unexecuted instantiation: thread.c:nlz_int
Unexecuted instantiation: time.c:nlz_int
Unexecuted instantiation: vm.c:nlz_int
Unexecuted instantiation: vm_trace.c:nlz_int
Unexecuted instantiation: ast.c:nlz_int
Unexecuted instantiation: compile.c:nlz_int
Unexecuted instantiation: parse.c:nlz_int
416
417
static inline unsigned int
418
nlz_long(unsigned long x)
419
43.7k
{
420
43.7k
    if (sizeof(unsigned long) * CHAR_BIT == 32) {
421
0
        return nlz_int32((uint32_t)x);
422
0
    }
423
43.7k
    else if (sizeof(unsigned long) * CHAR_BIT == 64) {
424
43.7k
        return nlz_int64((uint64_t)x);
425
43.7k
    }
426
0
    else {
427
0
        UNREACHABLE_RETURN(~0);
428
0
    }
429
43.7k
}
Unexecuted instantiation: array.c:nlz_long
Unexecuted instantiation: bignum.c:nlz_long
Unexecuted instantiation: complex.c:nlz_long
Unexecuted instantiation: enum.c:nlz_long
Unexecuted instantiation: enumerator.c:nlz_long
Unexecuted instantiation: gc.c:nlz_long
Unexecuted instantiation: hash.c:nlz_long
Unexecuted instantiation: io.c:nlz_long
Unexecuted instantiation: io_buffer.c:nlz_long
Unexecuted instantiation: iseq.c:nlz_long
Unexecuted instantiation: load.c:nlz_long
Unexecuted instantiation: marshal.c:nlz_long
Unexecuted instantiation: node_dump.c:nlz_long
Unexecuted instantiation: numeric.c:nlz_long
Unexecuted instantiation: object.c:nlz_long
Unexecuted instantiation: pack.c:nlz_long
Unexecuted instantiation: process.c:nlz_long
Unexecuted instantiation: ractor.c:nlz_long
Unexecuted instantiation: random.c:nlz_long
Unexecuted instantiation: range.c:nlz_long
Unexecuted instantiation: rational.c:nlz_long
Unexecuted instantiation: re.c:nlz_long
Unexecuted instantiation: ruby.c:nlz_long
Unexecuted instantiation: ruby_parser.c:nlz_long
Unexecuted instantiation: set.c:nlz_long
Unexecuted instantiation: sprintf.c:nlz_long
st.c:nlz_long
Line
Count
Source
419
43.7k
{
420
43.7k
    if (sizeof(unsigned long) * CHAR_BIT == 32) {
421
0
        return nlz_int32((uint32_t)x);
422
0
    }
423
43.7k
    else if (sizeof(unsigned long) * CHAR_BIT == 64) {
424
43.7k
        return nlz_int64((uint64_t)x);
425
43.7k
    }
426
0
    else {
427
0
        UNREACHABLE_RETURN(~0);
428
0
    }
429
43.7k
}
Unexecuted instantiation: string.c:nlz_long
Unexecuted instantiation: thread.c:nlz_long
Unexecuted instantiation: time.c:nlz_long
Unexecuted instantiation: vm.c:nlz_long
Unexecuted instantiation: vm_trace.c:nlz_long
Unexecuted instantiation: ast.c:nlz_long
Unexecuted instantiation: compile.c:nlz_long
Unexecuted instantiation: parse.c:nlz_long
430
431
static inline unsigned int
432
nlz_long_long(unsigned long long x)
433
0
{
434
0
    if (sizeof(unsigned long long) * CHAR_BIT == 64) {
435
0
        return nlz_int64((uint64_t)x);
436
0
    }
437
0
#ifdef HAVE_UINT128_T
438
0
    else if (sizeof(unsigned long long) * CHAR_BIT == 128) {
439
0
        return nlz_int128((uint128_t)x);
440
0
    }
441
0
#endif
442
0
    else {
443
0
        UNREACHABLE_RETURN(~0);
444
0
    }
445
0
}
Unexecuted instantiation: array.c:nlz_long_long
Unexecuted instantiation: bignum.c:nlz_long_long
Unexecuted instantiation: complex.c:nlz_long_long
Unexecuted instantiation: enum.c:nlz_long_long
Unexecuted instantiation: enumerator.c:nlz_long_long
Unexecuted instantiation: gc.c:nlz_long_long
Unexecuted instantiation: hash.c:nlz_long_long
Unexecuted instantiation: io.c:nlz_long_long
Unexecuted instantiation: io_buffer.c:nlz_long_long
Unexecuted instantiation: iseq.c:nlz_long_long
Unexecuted instantiation: load.c:nlz_long_long
Unexecuted instantiation: marshal.c:nlz_long_long
Unexecuted instantiation: node_dump.c:nlz_long_long
Unexecuted instantiation: numeric.c:nlz_long_long
Unexecuted instantiation: object.c:nlz_long_long
Unexecuted instantiation: pack.c:nlz_long_long
Unexecuted instantiation: process.c:nlz_long_long
Unexecuted instantiation: ractor.c:nlz_long_long
Unexecuted instantiation: random.c:nlz_long_long
Unexecuted instantiation: range.c:nlz_long_long
Unexecuted instantiation: rational.c:nlz_long_long
Unexecuted instantiation: re.c:nlz_long_long
Unexecuted instantiation: ruby.c:nlz_long_long
Unexecuted instantiation: ruby_parser.c:nlz_long_long
Unexecuted instantiation: set.c:nlz_long_long
Unexecuted instantiation: sprintf.c:nlz_long_long
Unexecuted instantiation: st.c:nlz_long_long
Unexecuted instantiation: string.c:nlz_long_long
Unexecuted instantiation: thread.c:nlz_long_long
Unexecuted instantiation: time.c:nlz_long_long
Unexecuted instantiation: vm.c:nlz_long_long
Unexecuted instantiation: vm_trace.c:nlz_long_long
Unexecuted instantiation: ast.c:nlz_long_long
Unexecuted instantiation: compile.c:nlz_long_long
Unexecuted instantiation: parse.c:nlz_long_long
446
447
static inline unsigned int
448
nlz_intptr(uintptr_t x)
449
43.7k
{
450
43.7k
    if (sizeof(uintptr_t) == sizeof(unsigned int)) {
451
0
        return nlz_int((unsigned int)x);
452
0
    }
453
43.7k
    if (sizeof(uintptr_t) == sizeof(unsigned long)) {
454
43.7k
        return nlz_long((unsigned long)x);
455
43.7k
    }
456
0
    if (sizeof(uintptr_t) == sizeof(unsigned long long)) {
457
0
        return nlz_long_long((unsigned long long)x);
458
0
    }
459
0
    else {
460
0
        UNREACHABLE_RETURN(~0);
461
0
    }
462
0
}
Unexecuted instantiation: array.c:nlz_intptr
Unexecuted instantiation: bignum.c:nlz_intptr
Unexecuted instantiation: complex.c:nlz_intptr
Unexecuted instantiation: enum.c:nlz_intptr
Unexecuted instantiation: enumerator.c:nlz_intptr
Unexecuted instantiation: gc.c:nlz_intptr
Unexecuted instantiation: hash.c:nlz_intptr
Unexecuted instantiation: io.c:nlz_intptr
Unexecuted instantiation: io_buffer.c:nlz_intptr
Unexecuted instantiation: iseq.c:nlz_intptr
Unexecuted instantiation: load.c:nlz_intptr
Unexecuted instantiation: marshal.c:nlz_intptr
Unexecuted instantiation: node_dump.c:nlz_intptr
Unexecuted instantiation: numeric.c:nlz_intptr
Unexecuted instantiation: object.c:nlz_intptr
Unexecuted instantiation: pack.c:nlz_intptr
Unexecuted instantiation: process.c:nlz_intptr
Unexecuted instantiation: ractor.c:nlz_intptr
Unexecuted instantiation: random.c:nlz_intptr
Unexecuted instantiation: range.c:nlz_intptr
Unexecuted instantiation: rational.c:nlz_intptr
Unexecuted instantiation: re.c:nlz_intptr
Unexecuted instantiation: ruby.c:nlz_intptr
Unexecuted instantiation: ruby_parser.c:nlz_intptr
Unexecuted instantiation: set.c:nlz_intptr
Unexecuted instantiation: sprintf.c:nlz_intptr
st.c:nlz_intptr
Line
Count
Source
449
43.7k
{
450
43.7k
    if (sizeof(uintptr_t) == sizeof(unsigned int)) {
451
0
        return nlz_int((unsigned int)x);
452
0
    }
453
43.7k
    if (sizeof(uintptr_t) == sizeof(unsigned long)) {
454
43.7k
        return nlz_long((unsigned long)x);
455
43.7k
    }
456
0
    if (sizeof(uintptr_t) == sizeof(unsigned long long)) {
457
0
        return nlz_long_long((unsigned long long)x);
458
0
    }
459
0
    else {
460
0
        UNREACHABLE_RETURN(~0);
461
0
    }
462
0
}
Unexecuted instantiation: string.c:nlz_intptr
Unexecuted instantiation: thread.c:nlz_intptr
Unexecuted instantiation: time.c:nlz_intptr
Unexecuted instantiation: vm.c:nlz_intptr
Unexecuted instantiation: vm_trace.c:nlz_intptr
Unexecuted instantiation: ast.c:nlz_intptr
Unexecuted instantiation: compile.c:nlz_intptr
Unexecuted instantiation: parse.c:nlz_intptr
463
464
static inline unsigned int
465
rb_popcount32(uint32_t x)
466
0
{
467
0
#if defined(_MSC_VER) && defined(__AVX__)
468
0
    /* Note: CPUs since Nehalem and Barcelona  have had this instruction so SSE
469
0
     * 4.2 should suffice, but it seems there is no such thing like __SSE_4_2__
470
0
     * predefined macro in MSVC.  They do have __AVX__ so use it instead. */
471
0
    return (unsigned int)__popcnt(x);
472
0
473
0
#elif __has_builtin(__builtin_popcount)
474
0
    STATIC_ASSERT(sizeof_int, sizeof(int) * CHAR_BIT >= 32);
475
0
    return (unsigned int)__builtin_popcount(x);
476
0
477
0
#else
478
0
    x = (x & 0x55555555) + (x >> 1 & 0x55555555);
479
0
    x = (x & 0x33333333) + (x >> 2 & 0x33333333);
480
0
    x = (x & 0x07070707) + (x >> 4 & 0x07070707);
481
0
    x = (x & 0x000f000f) + (x >> 8 & 0x000f000f);
482
0
    x = (x & 0x0000001f) + (x >>16 & 0x0000001f);
483
0
    return (unsigned int)x;
484
0
485
0
#endif
486
0
}
Unexecuted instantiation: array.c:rb_popcount32
Unexecuted instantiation: bignum.c:rb_popcount32
Unexecuted instantiation: complex.c:rb_popcount32
Unexecuted instantiation: enum.c:rb_popcount32
Unexecuted instantiation: enumerator.c:rb_popcount32
Unexecuted instantiation: gc.c:rb_popcount32
Unexecuted instantiation: hash.c:rb_popcount32
Unexecuted instantiation: io.c:rb_popcount32
Unexecuted instantiation: io_buffer.c:rb_popcount32
Unexecuted instantiation: iseq.c:rb_popcount32
Unexecuted instantiation: load.c:rb_popcount32
Unexecuted instantiation: marshal.c:rb_popcount32
Unexecuted instantiation: node_dump.c:rb_popcount32
Unexecuted instantiation: numeric.c:rb_popcount32
Unexecuted instantiation: object.c:rb_popcount32
Unexecuted instantiation: pack.c:rb_popcount32
Unexecuted instantiation: process.c:rb_popcount32
Unexecuted instantiation: ractor.c:rb_popcount32
Unexecuted instantiation: random.c:rb_popcount32
Unexecuted instantiation: range.c:rb_popcount32
Unexecuted instantiation: rational.c:rb_popcount32
Unexecuted instantiation: re.c:rb_popcount32
Unexecuted instantiation: ruby.c:rb_popcount32
Unexecuted instantiation: ruby_parser.c:rb_popcount32
Unexecuted instantiation: set.c:rb_popcount32
Unexecuted instantiation: sprintf.c:rb_popcount32
Unexecuted instantiation: st.c:rb_popcount32
Unexecuted instantiation: string.c:rb_popcount32
Unexecuted instantiation: thread.c:rb_popcount32
Unexecuted instantiation: time.c:rb_popcount32
Unexecuted instantiation: vm.c:rb_popcount32
Unexecuted instantiation: vm_trace.c:rb_popcount32
Unexecuted instantiation: ast.c:rb_popcount32
Unexecuted instantiation: compile.c:rb_popcount32
Unexecuted instantiation: parse.c:rb_popcount32
487
488
static inline unsigned int
489
rb_popcount64(uint64_t x)
490
0
{
491
#if defined(_MSC_VER) && defined(__AVX__)
492
    return (unsigned int)__popcnt64(x);
493
494
#elif __has_builtin(__builtin_popcount)
495
0
    if (sizeof(long) * CHAR_BIT == 64) {
496
0
        return (unsigned int)__builtin_popcountl((unsigned long)x);
497
0
    }
498
0
    else if (sizeof(long long) * CHAR_BIT == 64) {
499
0
        return (unsigned int)__builtin_popcountll((unsigned long long)x);
500
0
    }
501
0
    else {
502
        /* :FIXME: Is there a way to make this branch a compile-time error? */
503
0
        UNREACHABLE_RETURN(~0);
504
0
    }
505
506
#else
507
    x = (x & 0x5555555555555555) + (x >> 1 & 0x5555555555555555);
508
    x = (x & 0x3333333333333333) + (x >> 2 & 0x3333333333333333);
509
    x = (x & 0x0707070707070707) + (x >> 4 & 0x0707070707070707);
510
    x = (x & 0x000f000f000f000f) + (x >> 8 & 0x000f000f000f000f);
511
    x = (x & 0x0000001f0000001f) + (x >>16 & 0x0000001f0000001f);
512
    x = (x & 0x000000000000003f) + (x >>32 & 0x000000000000003f);
513
    return (unsigned int)x;
514
515
#endif
516
0
}
Unexecuted instantiation: array.c:rb_popcount64
Unexecuted instantiation: bignum.c:rb_popcount64
Unexecuted instantiation: complex.c:rb_popcount64
Unexecuted instantiation: enum.c:rb_popcount64
Unexecuted instantiation: enumerator.c:rb_popcount64
Unexecuted instantiation: gc.c:rb_popcount64
Unexecuted instantiation: hash.c:rb_popcount64
Unexecuted instantiation: io.c:rb_popcount64
Unexecuted instantiation: io_buffer.c:rb_popcount64
Unexecuted instantiation: iseq.c:rb_popcount64
Unexecuted instantiation: load.c:rb_popcount64
Unexecuted instantiation: marshal.c:rb_popcount64
Unexecuted instantiation: node_dump.c:rb_popcount64
Unexecuted instantiation: numeric.c:rb_popcount64
Unexecuted instantiation: object.c:rb_popcount64
Unexecuted instantiation: pack.c:rb_popcount64
Unexecuted instantiation: process.c:rb_popcount64
Unexecuted instantiation: ractor.c:rb_popcount64
Unexecuted instantiation: random.c:rb_popcount64
Unexecuted instantiation: range.c:rb_popcount64
Unexecuted instantiation: rational.c:rb_popcount64
Unexecuted instantiation: re.c:rb_popcount64
Unexecuted instantiation: ruby.c:rb_popcount64
Unexecuted instantiation: ruby_parser.c:rb_popcount64
Unexecuted instantiation: set.c:rb_popcount64
Unexecuted instantiation: sprintf.c:rb_popcount64
Unexecuted instantiation: st.c:rb_popcount64
Unexecuted instantiation: string.c:rb_popcount64
Unexecuted instantiation: thread.c:rb_popcount64
Unexecuted instantiation: time.c:rb_popcount64
Unexecuted instantiation: vm.c:rb_popcount64
Unexecuted instantiation: vm_trace.c:rb_popcount64
Unexecuted instantiation: ast.c:rb_popcount64
Unexecuted instantiation: compile.c:rb_popcount64
Unexecuted instantiation: parse.c:rb_popcount64
517
518
static inline unsigned int
519
rb_popcount_intptr(uintptr_t x)
520
0
{
521
0
    if (sizeof(uintptr_t) * CHAR_BIT == 64) {
522
0
        return rb_popcount64((uint64_t)x);
523
0
    }
524
0
    else if (sizeof(uintptr_t) * CHAR_BIT == 32) {
525
0
        return rb_popcount32((uint32_t)x);
526
0
    }
527
0
    else {
528
0
        UNREACHABLE_RETURN(~0);
529
0
    }
530
0
}
Unexecuted instantiation: array.c:rb_popcount_intptr
Unexecuted instantiation: bignum.c:rb_popcount_intptr
Unexecuted instantiation: complex.c:rb_popcount_intptr
Unexecuted instantiation: enum.c:rb_popcount_intptr
Unexecuted instantiation: enumerator.c:rb_popcount_intptr
Unexecuted instantiation: gc.c:rb_popcount_intptr
Unexecuted instantiation: hash.c:rb_popcount_intptr
Unexecuted instantiation: io.c:rb_popcount_intptr
Unexecuted instantiation: io_buffer.c:rb_popcount_intptr
Unexecuted instantiation: iseq.c:rb_popcount_intptr
Unexecuted instantiation: load.c:rb_popcount_intptr
Unexecuted instantiation: marshal.c:rb_popcount_intptr
Unexecuted instantiation: node_dump.c:rb_popcount_intptr
Unexecuted instantiation: numeric.c:rb_popcount_intptr
Unexecuted instantiation: object.c:rb_popcount_intptr
Unexecuted instantiation: pack.c:rb_popcount_intptr
Unexecuted instantiation: process.c:rb_popcount_intptr
Unexecuted instantiation: ractor.c:rb_popcount_intptr
Unexecuted instantiation: random.c:rb_popcount_intptr
Unexecuted instantiation: range.c:rb_popcount_intptr
Unexecuted instantiation: rational.c:rb_popcount_intptr
Unexecuted instantiation: re.c:rb_popcount_intptr
Unexecuted instantiation: ruby.c:rb_popcount_intptr
Unexecuted instantiation: ruby_parser.c:rb_popcount_intptr
Unexecuted instantiation: set.c:rb_popcount_intptr
Unexecuted instantiation: sprintf.c:rb_popcount_intptr
Unexecuted instantiation: st.c:rb_popcount_intptr
Unexecuted instantiation: string.c:rb_popcount_intptr
Unexecuted instantiation: thread.c:rb_popcount_intptr
Unexecuted instantiation: time.c:rb_popcount_intptr
Unexecuted instantiation: vm.c:rb_popcount_intptr
Unexecuted instantiation: vm_trace.c:rb_popcount_intptr
Unexecuted instantiation: ast.c:rb_popcount_intptr
Unexecuted instantiation: compile.c:rb_popcount_intptr
Unexecuted instantiation: parse.c:rb_popcount_intptr
531
532
static inline int
533
ntz_int32(uint32_t x)
534
2.74k
{
535
#if defined(__x86_64__) && defined(__BMI__)
536
    return (unsigned)_tzcnt_u32(x);
537
538
#elif defined(_MSC_VER)
539
    /* :FIXME: Is there any way to issue TZCNT instead of BSF, apart from using
540
     *         assembly?  Because issuing LZCNT seems possible (see nlz.h). */
541
    unsigned long r;
542
    return _BitScanForward(&r, x) ? (int)r : 32;
543
544
#elif __has_builtin(__builtin_ctz)
545
2.74k
    STATIC_ASSERT(sizeof_int, sizeof(int) * CHAR_BIT == 32);
546
2.74k
    return x ? (unsigned)__builtin_ctz(x) : 32;
547
548
#else
549
    return rb_popcount32((~x) & (x-1));
550
551
#endif
552
2.74k
}
Unexecuted instantiation: array.c:ntz_int32
Unexecuted instantiation: bignum.c:ntz_int32
Unexecuted instantiation: complex.c:ntz_int32
Unexecuted instantiation: enum.c:ntz_int32
Unexecuted instantiation: enumerator.c:ntz_int32
Unexecuted instantiation: gc.c:ntz_int32
Unexecuted instantiation: hash.c:ntz_int32
Unexecuted instantiation: io.c:ntz_int32
Unexecuted instantiation: io_buffer.c:ntz_int32
Unexecuted instantiation: iseq.c:ntz_int32
Unexecuted instantiation: load.c:ntz_int32
Unexecuted instantiation: marshal.c:ntz_int32
Unexecuted instantiation: node_dump.c:ntz_int32
Unexecuted instantiation: numeric.c:ntz_int32
Unexecuted instantiation: object.c:ntz_int32
Unexecuted instantiation: pack.c:ntz_int32
Unexecuted instantiation: process.c:ntz_int32
Unexecuted instantiation: ractor.c:ntz_int32
Unexecuted instantiation: random.c:ntz_int32
Unexecuted instantiation: range.c:ntz_int32
Unexecuted instantiation: rational.c:ntz_int32
Unexecuted instantiation: re.c:ntz_int32
Unexecuted instantiation: ruby.c:ntz_int32
Unexecuted instantiation: ruby_parser.c:ntz_int32
Unexecuted instantiation: set.c:ntz_int32
Unexecuted instantiation: sprintf.c:ntz_int32
Unexecuted instantiation: st.c:ntz_int32
Unexecuted instantiation: string.c:ntz_int32
Unexecuted instantiation: thread.c:ntz_int32
Unexecuted instantiation: time.c:ntz_int32
Unexecuted instantiation: vm.c:ntz_int32
Unexecuted instantiation: vm_trace.c:ntz_int32
Unexecuted instantiation: ast.c:ntz_int32
compile.c:ntz_int32
Line
Count
Source
534
2.74k
{
535
#if defined(__x86_64__) && defined(__BMI__)
536
    return (unsigned)_tzcnt_u32(x);
537
538
#elif defined(_MSC_VER)
539
    /* :FIXME: Is there any way to issue TZCNT instead of BSF, apart from using
540
     *         assembly?  Because issuing LZCNT seems possible (see nlz.h). */
541
    unsigned long r;
542
    return _BitScanForward(&r, x) ? (int)r : 32;
543
544
#elif __has_builtin(__builtin_ctz)
545
2.74k
    STATIC_ASSERT(sizeof_int, sizeof(int) * CHAR_BIT == 32);
546
2.74k
    return x ? (unsigned)__builtin_ctz(x) : 32;
547
548
#else
549
    return rb_popcount32((~x) & (x-1));
550
551
#endif
552
2.74k
}
Unexecuted instantiation: parse.c:ntz_int32
553
554
static inline int
555
ntz_int64(uint64_t x)
556
77.2k
{
557
#if defined(__x86_64__) && defined(__BMI__)
558
    return (unsigned)_tzcnt_u64(x);
559
560
#elif defined(_WIN64) && defined(_MSC_VER)
561
    unsigned long r;
562
    return _BitScanForward64(&r, x) ? (int)r : 64;
563
564
#elif __has_builtin(__builtin_ctzl)
565
77.2k
    if (x == 0) {
566
0
        return 64;
567
0
    }
568
77.2k
    else if (sizeof(long) * CHAR_BIT == 64) {
569
77.2k
        return (unsigned)__builtin_ctzl((unsigned long)x);
570
77.2k
    }
571
0
    else if (sizeof(long long) * CHAR_BIT == 64) {
572
0
        return (unsigned)__builtin_ctzll((unsigned long long)x);
573
0
    }
574
0
    else {
575
        /* :FIXME: Is there a way to make this branch a compile-time error? */
576
0
        UNREACHABLE_RETURN(~0);
577
0
    }
578
579
#else
580
    return rb_popcount64((~x) & (x-1));
581
582
#endif
583
77.2k
}
Unexecuted instantiation: array.c:ntz_int64
Unexecuted instantiation: bignum.c:ntz_int64
Unexecuted instantiation: complex.c:ntz_int64
Unexecuted instantiation: enum.c:ntz_int64
Unexecuted instantiation: enumerator.c:ntz_int64
Unexecuted instantiation: gc.c:ntz_int64
Unexecuted instantiation: hash.c:ntz_int64
Unexecuted instantiation: io.c:ntz_int64
Unexecuted instantiation: io_buffer.c:ntz_int64
Unexecuted instantiation: iseq.c:ntz_int64
Unexecuted instantiation: load.c:ntz_int64
Unexecuted instantiation: marshal.c:ntz_int64
Unexecuted instantiation: node_dump.c:ntz_int64
Unexecuted instantiation: numeric.c:ntz_int64
Unexecuted instantiation: object.c:ntz_int64
Unexecuted instantiation: pack.c:ntz_int64
Unexecuted instantiation: process.c:ntz_int64
Unexecuted instantiation: ractor.c:ntz_int64
Unexecuted instantiation: random.c:ntz_int64
Unexecuted instantiation: range.c:ntz_int64
Unexecuted instantiation: rational.c:ntz_int64
Unexecuted instantiation: re.c:ntz_int64
Unexecuted instantiation: ruby.c:ntz_int64
Unexecuted instantiation: ruby_parser.c:ntz_int64
Unexecuted instantiation: set.c:ntz_int64
Unexecuted instantiation: sprintf.c:ntz_int64
Unexecuted instantiation: st.c:ntz_int64
string.c:ntz_int64
Line
Count
Source
556
77.2k
{
557
#if defined(__x86_64__) && defined(__BMI__)
558
    return (unsigned)_tzcnt_u64(x);
559
560
#elif defined(_WIN64) && defined(_MSC_VER)
561
    unsigned long r;
562
    return _BitScanForward64(&r, x) ? (int)r : 64;
563
564
#elif __has_builtin(__builtin_ctzl)
565
77.2k
    if (x == 0) {
566
0
        return 64;
567
0
    }
568
77.2k
    else if (sizeof(long) * CHAR_BIT == 64) {
569
77.2k
        return (unsigned)__builtin_ctzl((unsigned long)x);
570
77.2k
    }
571
0
    else if (sizeof(long long) * CHAR_BIT == 64) {
572
0
        return (unsigned)__builtin_ctzll((unsigned long long)x);
573
0
    }
574
0
    else {
575
        /* :FIXME: Is there a way to make this branch a compile-time error? */
576
0
        UNREACHABLE_RETURN(~0);
577
0
    }
578
579
#else
580
    return rb_popcount64((~x) & (x-1));
581
582
#endif
583
77.2k
}
Unexecuted instantiation: thread.c:ntz_int64
Unexecuted instantiation: time.c:ntz_int64
Unexecuted instantiation: vm.c:ntz_int64
Unexecuted instantiation: vm_trace.c:ntz_int64
Unexecuted instantiation: ast.c:ntz_int64
Unexecuted instantiation: compile.c:ntz_int64
Unexecuted instantiation: parse.c:ntz_int64
584
585
static inline int
586
ntz_intptr(uintptr_t x)
587
77.2k
{
588
77.2k
    if (sizeof(uintptr_t) * CHAR_BIT == 64) {
589
77.2k
        return ntz_int64((uint64_t)x);
590
77.2k
    }
591
0
    else if (sizeof(uintptr_t) * CHAR_BIT == 32) {
592
0
        return ntz_int32((uint32_t)x);
593
0
    }
594
0
    else {
595
0
        UNREACHABLE_RETURN(~0);
596
0
    }
597
77.2k
}
Unexecuted instantiation: array.c:ntz_intptr
Unexecuted instantiation: bignum.c:ntz_intptr
Unexecuted instantiation: complex.c:ntz_intptr
Unexecuted instantiation: enum.c:ntz_intptr
Unexecuted instantiation: enumerator.c:ntz_intptr
Unexecuted instantiation: gc.c:ntz_intptr
Unexecuted instantiation: hash.c:ntz_intptr
Unexecuted instantiation: io.c:ntz_intptr
Unexecuted instantiation: io_buffer.c:ntz_intptr
Unexecuted instantiation: iseq.c:ntz_intptr
Unexecuted instantiation: load.c:ntz_intptr
Unexecuted instantiation: marshal.c:ntz_intptr
Unexecuted instantiation: node_dump.c:ntz_intptr
Unexecuted instantiation: numeric.c:ntz_intptr
Unexecuted instantiation: object.c:ntz_intptr
Unexecuted instantiation: pack.c:ntz_intptr
Unexecuted instantiation: process.c:ntz_intptr
Unexecuted instantiation: ractor.c:ntz_intptr
Unexecuted instantiation: random.c:ntz_intptr
Unexecuted instantiation: range.c:ntz_intptr
Unexecuted instantiation: rational.c:ntz_intptr
Unexecuted instantiation: re.c:ntz_intptr
Unexecuted instantiation: ruby.c:ntz_intptr
Unexecuted instantiation: ruby_parser.c:ntz_intptr
Unexecuted instantiation: set.c:ntz_intptr
Unexecuted instantiation: sprintf.c:ntz_intptr
Unexecuted instantiation: st.c:ntz_intptr
string.c:ntz_intptr
Line
Count
Source
587
77.2k
{
588
77.2k
    if (sizeof(uintptr_t) * CHAR_BIT == 64) {
589
77.2k
        return ntz_int64((uint64_t)x);
590
77.2k
    }
591
0
    else if (sizeof(uintptr_t) * CHAR_BIT == 32) {
592
0
        return ntz_int32((uint32_t)x);
593
0
    }
594
0
    else {
595
0
        UNREACHABLE_RETURN(~0);
596
0
    }
597
77.2k
}
Unexecuted instantiation: thread.c:ntz_intptr
Unexecuted instantiation: time.c:ntz_intptr
Unexecuted instantiation: vm.c:ntz_intptr
Unexecuted instantiation: vm_trace.c:ntz_intptr
Unexecuted instantiation: ast.c:ntz_intptr
Unexecuted instantiation: compile.c:ntz_intptr
Unexecuted instantiation: parse.c:ntz_intptr
598
599
static inline VALUE
600
RUBY_BIT_ROTL(VALUE v, int n)
601
102k
{
602
#if __has_builtin(__builtin_rotateleft32) && (SIZEOF_VALUE * CHAR_BIT == 32)
603
    return __builtin_rotateleft32(v, n);
604
605
#elif __has_builtin(__builtin_rotateleft64) && (SIZEOF_VALUE * CHAR_BIT == 64)
606
    return __builtin_rotateleft64(v, n);
607
608
#elif defined(_MSC_VER) && (SIZEOF_VALUE * CHAR_BIT == 32)
609
    return _rotl(v, n);
610
611
#elif defined(_MSC_VER) && (SIZEOF_VALUE * CHAR_BIT == 64)
612
    return _rotl64(v, n);
613
614
#elif defined(_lrotl) && (SIZEOF_VALUE == SIZEOF_LONG)
615
    return _lrotl(v, n);
616
617
#else
618
    const int m = (sizeof(VALUE) * CHAR_BIT) - 1;
619
    return (v << (n & m)) | (v >> (-n & m));
620
#endif
621
102k
}
Unexecuted instantiation: array.c:RUBY_BIT_ROTL
Unexecuted instantiation: bignum.c:RUBY_BIT_ROTL
Unexecuted instantiation: complex.c:RUBY_BIT_ROTL
Unexecuted instantiation: enum.c:RUBY_BIT_ROTL
Unexecuted instantiation: enumerator.c:RUBY_BIT_ROTL
Unexecuted instantiation: gc.c:RUBY_BIT_ROTL
Unexecuted instantiation: hash.c:RUBY_BIT_ROTL
Unexecuted instantiation: io.c:RUBY_BIT_ROTL
Unexecuted instantiation: io_buffer.c:RUBY_BIT_ROTL
Unexecuted instantiation: iseq.c:RUBY_BIT_ROTL
Unexecuted instantiation: load.c:RUBY_BIT_ROTL
Unexecuted instantiation: marshal.c:RUBY_BIT_ROTL
Unexecuted instantiation: node_dump.c:RUBY_BIT_ROTL
numeric.c:RUBY_BIT_ROTL
Line
Count
Source
601
102k
{
602
#if __has_builtin(__builtin_rotateleft32) && (SIZEOF_VALUE * CHAR_BIT == 32)
603
    return __builtin_rotateleft32(v, n);
604
605
#elif __has_builtin(__builtin_rotateleft64) && (SIZEOF_VALUE * CHAR_BIT == 64)
606
    return __builtin_rotateleft64(v, n);
607
608
#elif defined(_MSC_VER) && (SIZEOF_VALUE * CHAR_BIT == 32)
609
    return _rotl(v, n);
610
611
#elif defined(_MSC_VER) && (SIZEOF_VALUE * CHAR_BIT == 64)
612
    return _rotl64(v, n);
613
614
#elif defined(_lrotl) && (SIZEOF_VALUE == SIZEOF_LONG)
615
    return _lrotl(v, n);
616
617
#else
618
    const int m = (sizeof(VALUE) * CHAR_BIT) - 1;
619
    return (v << (n & m)) | (v >> (-n & m));
620
#endif
621
102k
}
Unexecuted instantiation: object.c:RUBY_BIT_ROTL
Unexecuted instantiation: pack.c:RUBY_BIT_ROTL
Unexecuted instantiation: process.c:RUBY_BIT_ROTL
Unexecuted instantiation: ractor.c:RUBY_BIT_ROTL
Unexecuted instantiation: random.c:RUBY_BIT_ROTL
Unexecuted instantiation: range.c:RUBY_BIT_ROTL
Unexecuted instantiation: rational.c:RUBY_BIT_ROTL
Unexecuted instantiation: re.c:RUBY_BIT_ROTL
Unexecuted instantiation: ruby.c:RUBY_BIT_ROTL
ruby_parser.c:RUBY_BIT_ROTL
Line
Count
Source
601
19
{
602
#if __has_builtin(__builtin_rotateleft32) && (SIZEOF_VALUE * CHAR_BIT == 32)
603
    return __builtin_rotateleft32(v, n);
604
605
#elif __has_builtin(__builtin_rotateleft64) && (SIZEOF_VALUE * CHAR_BIT == 64)
606
    return __builtin_rotateleft64(v, n);
607
608
#elif defined(_MSC_VER) && (SIZEOF_VALUE * CHAR_BIT == 32)
609
    return _rotl(v, n);
610
611
#elif defined(_MSC_VER) && (SIZEOF_VALUE * CHAR_BIT == 64)
612
    return _rotl64(v, n);
613
614
#elif defined(_lrotl) && (SIZEOF_VALUE == SIZEOF_LONG)
615
    return _lrotl(v, n);
616
617
#else
618
    const int m = (sizeof(VALUE) * CHAR_BIT) - 1;
619
    return (v << (n & m)) | (v >> (-n & m));
620
#endif
621
19
}
Unexecuted instantiation: set.c:RUBY_BIT_ROTL
Unexecuted instantiation: sprintf.c:RUBY_BIT_ROTL
Unexecuted instantiation: st.c:RUBY_BIT_ROTL
Unexecuted instantiation: string.c:RUBY_BIT_ROTL
Unexecuted instantiation: thread.c:RUBY_BIT_ROTL
Unexecuted instantiation: time.c:RUBY_BIT_ROTL
Unexecuted instantiation: vm.c:RUBY_BIT_ROTL
Unexecuted instantiation: vm_trace.c:RUBY_BIT_ROTL
Unexecuted instantiation: ast.c:RUBY_BIT_ROTL
Unexecuted instantiation: compile.c:RUBY_BIT_ROTL
Unexecuted instantiation: parse.c:RUBY_BIT_ROTL
622
623
static inline VALUE
624
RUBY_BIT_ROTR(VALUE v, int n)
625
28
{
626
#if __has_builtin(__builtin_rotateright32) && (SIZEOF_VALUE * CHAR_BIT == 32)
627
    return __builtin_rotateright32(v, n);
628
629
#elif __has_builtin(__builtin_rotateright64) && (SIZEOF_VALUE * CHAR_BIT == 64)
630
    return __builtin_rotateright64(v, n);
631
632
#elif defined(_MSC_VER) && (SIZEOF_VALUE * CHAR_BIT == 32)
633
    return _rotr(v, n);
634
635
#elif defined(_MSC_VER) && (SIZEOF_VALUE * CHAR_BIT == 64)
636
    return _rotr64(v, n);
637
638
#elif defined(_lrotr) && (SIZEOF_VALUE == SIZEOF_LONG)
639
    return _lrotr(v, n);
640
641
#else
642
    const int m = (sizeof(VALUE) * CHAR_BIT) - 1;
643
    return (v << (-n & m)) | (v >> (n & m));
644
#endif
645
28
}
Unexecuted instantiation: array.c:RUBY_BIT_ROTR
Unexecuted instantiation: bignum.c:RUBY_BIT_ROTR
Unexecuted instantiation: complex.c:RUBY_BIT_ROTR
Unexecuted instantiation: enum.c:RUBY_BIT_ROTR
Unexecuted instantiation: enumerator.c:RUBY_BIT_ROTR
Unexecuted instantiation: gc.c:RUBY_BIT_ROTR
Unexecuted instantiation: hash.c:RUBY_BIT_ROTR
Unexecuted instantiation: io.c:RUBY_BIT_ROTR
Unexecuted instantiation: io_buffer.c:RUBY_BIT_ROTR
Unexecuted instantiation: iseq.c:RUBY_BIT_ROTR
Unexecuted instantiation: load.c:RUBY_BIT_ROTR
Unexecuted instantiation: marshal.c:RUBY_BIT_ROTR
Unexecuted instantiation: node_dump.c:RUBY_BIT_ROTR
numeric.c:RUBY_BIT_ROTR
Line
Count
Source
625
28
{
626
#if __has_builtin(__builtin_rotateright32) && (SIZEOF_VALUE * CHAR_BIT == 32)
627
    return __builtin_rotateright32(v, n);
628
629
#elif __has_builtin(__builtin_rotateright64) && (SIZEOF_VALUE * CHAR_BIT == 64)
630
    return __builtin_rotateright64(v, n);
631
632
#elif defined(_MSC_VER) && (SIZEOF_VALUE * CHAR_BIT == 32)
633
    return _rotr(v, n);
634
635
#elif defined(_MSC_VER) && (SIZEOF_VALUE * CHAR_BIT == 64)
636
    return _rotr64(v, n);
637
638
#elif defined(_lrotr) && (SIZEOF_VALUE == SIZEOF_LONG)
639
    return _lrotr(v, n);
640
641
#else
642
    const int m = (sizeof(VALUE) * CHAR_BIT) - 1;
643
    return (v << (-n & m)) | (v >> (n & m));
644
#endif
645
28
}
Unexecuted instantiation: object.c:RUBY_BIT_ROTR
Unexecuted instantiation: pack.c:RUBY_BIT_ROTR
Unexecuted instantiation: process.c:RUBY_BIT_ROTR
Unexecuted instantiation: ractor.c:RUBY_BIT_ROTR
Unexecuted instantiation: random.c:RUBY_BIT_ROTR
Unexecuted instantiation: range.c:RUBY_BIT_ROTR
Unexecuted instantiation: rational.c:RUBY_BIT_ROTR
Unexecuted instantiation: re.c:RUBY_BIT_ROTR
Unexecuted instantiation: ruby.c:RUBY_BIT_ROTR
Unexecuted instantiation: ruby_parser.c:RUBY_BIT_ROTR
Unexecuted instantiation: set.c:RUBY_BIT_ROTR
Unexecuted instantiation: sprintf.c:RUBY_BIT_ROTR
Unexecuted instantiation: st.c:RUBY_BIT_ROTR
Unexecuted instantiation: string.c:RUBY_BIT_ROTR
Unexecuted instantiation: thread.c:RUBY_BIT_ROTR
Unexecuted instantiation: time.c:RUBY_BIT_ROTR
Unexecuted instantiation: vm.c:RUBY_BIT_ROTR
Unexecuted instantiation: vm_trace.c:RUBY_BIT_ROTR
Unexecuted instantiation: ast.c:RUBY_BIT_ROTR
Unexecuted instantiation: compile.c:RUBY_BIT_ROTR
Unexecuted instantiation: parse.c:RUBY_BIT_ROTR
646
647
#endif /* INTERNAL_BITS_H */