bit-twiddle 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 25b438e0de17e4ef56155166736b08d0bfc3ba962ae8c85f837e3073ed25e76f
4
- data.tar.gz: b6cff494a2d45bdaa06eff5299a64b32f3a3b4ff284f7c5439a40dda29905b32
3
+ metadata.gz: fb5bc1ef21de0ce254366175d3e55593136fcab5cc5401ff11c1bae85c4c3241
4
+ data.tar.gz: 5f61aa034bb23c84037a18f36ddf2755282407b3820c9db1e6b0953eb7e9ed76
5
5
  SHA512:
6
- metadata.gz: 5097963595ddf9773f481b771958d00315c5a9e15deaa55c1e9290a82398b42b7b4ceccc7c9b6a105b63f30f9fab49b381fcf39ab630dc90343bfaac6cecb058
7
- data.tar.gz: 24233d812e555ed06a9c31d6a098a414ebb5e98589b638fede32b981a43adef8f10e213e22167ec1147dd0aa1d6ed5c0f13753cbd218bf7dad2852c270a85760
6
+ metadata.gz: 30b2b074082ed3e3a79f6cbd0df048e1317bd9b17b8fac0875068b3fb2e04c2b143ef3df93f8cf0e780785bf73705f478a9a82d7d5ef88ac30fce99cef10713a
7
+ data.tar.gz: ef489d27df2ea645ec997e37561414f37d19d9a04a0bc0c6a04cc87d770c413ea53a5c309732a46a38d7b257a50ee662535ffd71133e859b08e6cce4fe4d9cdc
@@ -22,8 +22,10 @@ elsif RUBY_VERSION < '2.3.0'
22
22
  $CFLAGS << " -I#{File.join(dir, 'ruby22')} "
23
23
  elsif RUBY_VERSION < '3.0.0'
24
24
  $CFLAGS << " -I#{File.join(dir, 'ruby23')} "
25
- else
25
+ elsif RUBY_VERSION < '3.1.0'
26
26
  $CFLAGS << " -I#{File.join(dir, 'ruby30')} "
27
+ else
28
+ $CFLAGS << " -I#{File.join(dir, 'ruby31')} "
27
29
  end
28
30
 
29
31
  check_sizeof 'short'
@@ -0,0 +1,83 @@
1
+ #if SIZEOF_INT*2 <= SIZEOF_LONG_LONG
2
+ # define BDIGIT unsigned int
3
+ # define SIZEOF_BDIGIT SIZEOF_INT
4
+ #elif SIZEOF_INT*2 <= SIZEOF_LONG
5
+ # define BDIGIT unsigned int
6
+ # define SIZEOF_BDIGIT SIZEOF_INT
7
+ #elif SIZEOF_SHORT*2 <= SIZEOF_LONG
8
+ # define BDIGIT unsigned short
9
+ # define SIZEOF_BDIGIT SIZEOF_SHORT
10
+ #else
11
+ # define BDIGIT unsigned short
12
+ # define SIZEOF_BDIGIT (SIZEOF_LONG/2)
13
+ # define SIZEOF_ACTUAL_BDIGIT SIZEOF_LONG
14
+ #endif
15
+ #ifndef SIZEOF_ACTUAL_BDIGIT
16
+ # define SIZEOF_ACTUAL_BDIGIT SIZEOF_BDIGIT
17
+ #endif
18
+
19
+ #define RBIGNUM(obj) ((struct RBignum *)(obj))
20
+ #define BIGNUM_SIGN_BIT FL_USER1
21
+ #define BIGNUM_EMBED_FLAG ((VALUE)FL_USER2)
22
+ #define BIGNUM_EMBED_LEN_NUMBITS 3
23
+ #define BIGNUM_EMBED_LEN_MASK \
24
+ (~(~(VALUE)0U << BIGNUM_EMBED_LEN_NUMBITS) << BIGNUM_EMBED_LEN_SHIFT)
25
+ #define BIGNUM_EMBED_LEN_SHIFT \
26
+ (FL_USHIFT+3) /* bit offset of BIGNUM_EMBED_LEN_MASK */
27
+ #ifndef BIGNUM_EMBED_LEN_MAX
28
+ # if (SIZEOF_VALUE*RBIMPL_RVALUE_EMBED_LEN_MAX/SIZEOF_ACTUAL_BDIGIT) < (1 << BIGNUM_EMBED_LEN_NUMBITS)-1
29
+ # define BIGNUM_EMBED_LEN_MAX (SIZEOF_VALUE*RBIMPL_RVALUE_EMBED_LEN_MAX/SIZEOF_ACTUAL_BDIGIT)
30
+ # else
31
+ # define BIGNUM_EMBED_LEN_MAX ((1 << BIGNUM_EMBED_LEN_NUMBITS)-1)
32
+ # endif
33
+ #endif
34
+
35
+ struct RBignum {
36
+ struct RBasic basic;
37
+ union {
38
+ struct {
39
+ size_t len;
40
+ BDIGIT *digits;
41
+ } heap;
42
+ BDIGIT ary[BIGNUM_EMBED_LEN_MAX];
43
+ } as;
44
+ };
45
+
46
+ static inline size_t BIGNUM_LEN(VALUE b);
47
+ static inline BDIGIT *BIGNUM_DIGITS(VALUE b);
48
+ static inline bool BIGNUM_EMBED_P(VALUE b);
49
+
50
+ static inline size_t
51
+ BIGNUM_LEN(VALUE b)
52
+ {
53
+ if (! BIGNUM_EMBED_P(b)) {
54
+ return RBIGNUM(b)->as.heap.len;
55
+ }
56
+ else {
57
+ size_t ret = RBASIC(b)->flags;
58
+ ret &= BIGNUM_EMBED_LEN_MASK;
59
+ ret >>= BIGNUM_EMBED_LEN_SHIFT;
60
+ return ret;
61
+ }
62
+ }
63
+
64
+ /* LSB:BIGNUM_DIGITS(b)[0], MSB:BIGNUM_DIGITS(b)[BIGNUM_LEN(b)-1] */
65
+ static inline BDIGIT *
66
+ BIGNUM_DIGITS(VALUE b)
67
+ {
68
+ if (BIGNUM_EMBED_P(b)) {
69
+ return RBIGNUM(b)->as.ary;
70
+ }
71
+ else {
72
+ return RBIGNUM(b)->as.heap.digits;
73
+ }
74
+ }
75
+
76
+ static inline bool
77
+ BIGNUM_EMBED_P(VALUE b)
78
+ {
79
+ return FL_TEST_RAW(b, BIGNUM_EMBED_FLAG);
80
+ }
81
+
82
+ #define RBIGNUM_DIGITS BIGNUM_DIGITS
83
+ #define RBIGNUM_LEN BIGNUM_LEN
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bit-twiddle
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Dowad
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-20 00:00:00.000000000 Z
11
+ date: 2022-06-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -95,13 +95,14 @@ files:
95
95
  - ext/bit_twiddle/ruby22/bt_bignum.h
96
96
  - ext/bit_twiddle/ruby23/bt_bignum.h
97
97
  - ext/bit_twiddle/ruby30/bt_bignum.h
98
+ - ext/bit_twiddle/ruby31/bt_bignum.h
98
99
  - lib/bit-twiddle.rb
99
100
  - lib/bit-twiddle/core_ext.rb
100
101
  homepage: http://github.com/alexdowad/bit-twiddle
101
102
  licenses:
102
103
  - None (Public Domain)
103
104
  metadata: {}
104
- post_install_message:
105
+ post_install_message:
105
106
  rdoc_options: []
106
107
  require_paths:
107
108
  - lib
@@ -116,8 +117,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
116
117
  - !ruby/object:Gem::Version
117
118
  version: '0'
118
119
  requirements: []
119
- rubygems_version: 3.2.15
120
- signing_key:
120
+ rubygems_version: 3.1.2
121
+ signing_key:
121
122
  specification_version: 4
122
123
  summary: Fast bitwise operations for Ruby
123
124
  test_files: []