bit-twiddle 0.0.2 → 0.0.4

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.
@@ -2,9 +2,16 @@ require 'mkmf'
2
2
 
3
3
  dir = File.dirname(__FILE__)
4
4
 
5
- $CFLAGS << ' -Wall -Werror -O3 -march=native -mtune=native '
5
+ # allow 'CC' env variable to override the compiler used
6
+ if ENV['CC']
7
+ RbConfig::MAKEFILE_CONFIG['CC'] = ENV['CC']
8
+ end
9
+
10
+ $CFLAGS << ' -Wall -Werror -O3 -march=native -mtune=native -std=c99 '
6
11
 
7
- if RUBY_VERSION < '2.2.0'
12
+ if RUBY_ENGINE == 'rbx'
13
+ raise "bit-twiddle does not support Rubinius. Sorry!"
14
+ elsif RUBY_VERSION < '2.2.0'
8
15
  check_sizeof 'BDIGIT'
9
16
  $CFLAGS << " -I#{File.join(dir, 'ruby21')} "
10
17
  else
@@ -0,0 +1 @@
1
+ /* nothing special needed for MRI Ruby 1.9.3 - 2.1 */
@@ -0,0 +1,61 @@
1
+
2
+ #if SIZEOF_INT*2 <= SIZEOF_LONG_LONG
3
+ # define BDIGIT unsigned int
4
+ # define SIZEOF_BDIGIT SIZEOF_INT
5
+ #elif SIZEOF_INT*2 <= SIZEOF_LONG
6
+ # define BDIGIT unsigned int
7
+ # define SIZEOF_BDIGIT SIZEOF_INT
8
+ #elif SIZEOF_SHORT*2 <= SIZEOF_LONG
9
+ # define BDIGIT unsigned short
10
+ # define SIZEOF_BDIGIT SIZEOF_SHORT
11
+ #else
12
+ # define BDIGIT unsigned short
13
+ # define SIZEOF_BDIGIT (SIZEOF_LONG/2)
14
+ # define SIZEOF_ACTUAL_BDIGIT SIZEOF_LONG
15
+ #endif
16
+ #ifndef SIZEOF_ACTUAL_BDIGIT
17
+ # define SIZEOF_ACTUAL_BDIGIT SIZEOF_BDIGIT
18
+ #endif
19
+
20
+ #define FL_USHIFT 12
21
+
22
+ #define FL_USER0 (((VALUE)1)<<(FL_USHIFT+0))
23
+ #define FL_USER1 (((VALUE)1)<<(FL_USHIFT+1))
24
+ #define FL_USER2 (((VALUE)1)<<(FL_USHIFT+2))
25
+ #define FL_USER3 (((VALUE)1)<<(FL_USHIFT+3))
26
+ #define FL_USER4 (((VALUE)1)<<(FL_USHIFT+4))
27
+ #define FL_USER5 (((VALUE)1)<<(FL_USHIFT+5))
28
+
29
+ #define BIGNUM_EMBED_LEN_NUMBITS 3
30
+ #if (SIZEOF_VALUE*3/SIZEOF_ACTUAL_BDIGIT) < (1 << BIGNUM_EMBED_LEN_NUMBITS)-1
31
+ # define BIGNUM_EMBED_LEN_MAX (SIZEOF_VALUE*3/SIZEOF_ACTUAL_BDIGIT)
32
+ #else
33
+ # define BIGNUM_EMBED_LEN_MAX ((1 << BIGNUM_EMBED_LEN_NUMBITS)-1)
34
+ #endif
35
+
36
+ struct RBignum {
37
+ struct RBasic basic;
38
+ union {
39
+ struct {
40
+ size_t len;
41
+ BDIGIT *digits;
42
+ } heap;
43
+ BDIGIT ary[BIGNUM_EMBED_LEN_MAX];
44
+ } as;
45
+ };
46
+
47
+ #define BIGNUM_EMBED_FLAG FL_USER2
48
+ #define BIGNUM_EMBED_LEN_MASK (FL_USER5|FL_USER4|FL_USER3)
49
+ #define BIGNUM_EMBED_LEN_SHIFT (FL_USHIFT+BIGNUM_EMBED_LEN_NUMBITS)
50
+ #define RBIGNUM_LEN(b) \
51
+ ((RBASIC(b)->flags & BIGNUM_EMBED_FLAG) ? \
52
+ (long)((RBASIC(b)->flags >> BIGNUM_EMBED_LEN_SHIFT) & \
53
+ (BIGNUM_EMBED_LEN_MASK >> BIGNUM_EMBED_LEN_SHIFT)) : \
54
+ RBIGNUM(b)->as.heap.len)
55
+ /* LSB:BIGNUM_DIGITS(b)[0], MSB:BIGNUM_DIGITS(b)[BIGNUM_LEN(b)-1] */
56
+ #define RBIGNUM_DIGITS(b) \
57
+ ((RBASIC(b)->flags & BIGNUM_EMBED_FLAG) ? \
58
+ RBIGNUM(b)->as.ary : \
59
+ RBIGNUM(b)->as.heap.digits)
60
+
61
+ #define RBIGNUM(obj) (R_CAST(RBignum)(obj))
@@ -0,0 +1,2 @@
1
+ require 'bit_twiddle' # C extension
2
+ BitTwiddle.add_core_extensions
Binary file
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.0.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Dowad
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-22 00:00:00.000000000 Z
11
+ date: 2015-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -90,8 +90,12 @@ extra_rdoc_files: []
90
90
  files:
91
91
  - LICENSE
92
92
  - README.md
93
+ - ext/bit_twiddle/bit_twiddle.c
93
94
  - ext/bit_twiddle/extconf.rb
95
+ - ext/bit_twiddle/ruby21/bt_bignum.h
96
+ - ext/bit_twiddle/ruby22/bt_bignum.h
94
97
  - lib/bit-twiddle.rb
98
+ - lib/bit-twiddle/core_ext.rb
95
99
  - lib/bit_twiddle.so
96
100
  homepage: http://github.com/alexdowad/bit-twiddle
97
101
  licenses:
@@ -113,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
113
117
  version: '0'
114
118
  requirements: []
115
119
  rubyforge_project:
116
- rubygems_version: 2.4.5
120
+ rubygems_version: 2.2.2
117
121
  signing_key:
118
122
  specification_version: 4
119
123
  summary: Fast bitwise operations for Ruby