simd 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 91f6ffe0659b15461fbf3bfc7657bd72b8e0d6eb
4
- data.tar.gz: 289421206f7343fed00e5fbcf214d0908e835882
3
+ metadata.gz: 459e978d4372f815dc06ad340ce39283369909e7
4
+ data.tar.gz: 7621df63dd917b69b6222f4f5b9fc72a430c8a21
5
5
  SHA512:
6
- metadata.gz: 1c2353151fa088f7ebcb535d095211e83517fd2436e2acee2b5d42e43f776d8df4931007e2a50c0f11026bed64c99be20d25f6e3598e52f10b30301e532420ea
7
- data.tar.gz: 1e0ef0af7c81a176fc908163f6c7d68a09ae651a9d852fecfdf0185a3aed1d1732d4636670576964537f27c687f1c9765d214b75f8d15bcab8e89e1124bcf224
6
+ metadata.gz: ea9d3e2b0366a7b377cea2c7412420b44170613b9704069883e7226982b643c9fb9aaefa16e39f842fce4b446725d85719cea1f16a19a951141d23ac5a2754e4
7
+ data.tar.gz: 99554543164a275329ec030fd482f175e96feb7d74985aee3b4b78c0991d1f55a903ef88c3295522f017016c8cf2edca8a21597ff1c8b6566fab339915b031fc
@@ -1,6 +1,12 @@
1
1
  # Makes Makefiles for Ruby extensions.
2
2
  require 'mkmf'
3
3
 
4
+ cpu = RbConfig::CONFIG['arch'].downcase
5
+ if cpu.include?('arm')
6
+ ver = cpu.gsub(/[^\d]*(\d+).*/, '\\1').to_i
7
+ $CFLAGS << ' -mfpu=neon' if ver >= 6
8
+ end
9
+
4
10
  extension_name = 'simd'
5
11
  dir_config(extension_name)
6
12
  create_makefile(extension_name)
@@ -38,7 +38,7 @@ VALUE method_length(VALUE self)
38
38
  }
39
39
 
40
40
  /* Internal: Allocate memory for the data array. */
41
- void *internal_allocate_vector_array(unsigned long count)
41
+ void *internal_allocate_vector_array(unsigned long long int count)
42
42
  {
43
43
  void *vector = malloc((count + 1) * XMM_BYTES);
44
44
  if(vector == NULL)
@@ -51,7 +51,7 @@ void *internal_allocate_vector_array(unsigned long count)
51
51
 
52
52
  /* Internal: Determine if two arrays can be acted upon, by being of equal
53
53
  * lengths or with the operand's length being a multiple of the data array's. */
54
- int internal_align_vectors(unsigned long v1, unsigned long v2, unsigned int modulo)
54
+ int internal_align_vectors(unsigned long long int v1, unsigned long long int v2, unsigned int modulo)
55
55
  {
56
56
  if((v1 % modulo) != (v2 % modulo))
57
57
  {
@@ -85,7 +85,7 @@ int internal_align_vectors(unsigned long v1, unsigned long v2, unsigned int modu
85
85
  #pragma GCC diagnostic ignored "-Wpointer-arith"
86
86
  VALUE internal_apply_operation(VALUE self, VALUE obj, size_t size, VALUE klass, b_operation func)
87
87
  {
88
- unsigned long length, i, j;
88
+ unsigned long long int length, i, j;
89
89
  int align;
90
90
  vector_t *v1, *v2, *rv;
91
91
  void *data;
@@ -141,7 +141,7 @@ VALUE internal_apply_operation(VALUE self, VALUE obj, size_t size, VALUE klass,
141
141
  #pragma GCC diagnostic ignored "-Wpointer-arith"
142
142
  void internal_sanitize_unaligned_final_vector(vector_t *rv, size_t size)
143
143
  {
144
- unsigned long i;
144
+ unsigned long long int i;
145
145
 
146
146
  if((rv->len * size) % XMM_BYTES)
147
147
  {
@@ -8,7 +8,7 @@ void deallocate(vector_t *vector);
8
8
 
9
9
  VALUE method_length(VALUE self);
10
10
 
11
- void *internal_allocate_vector_array(unsigned long count);
12
- int internal_align_vectors(unsigned long v1, unsigned long v2, unsigned int modulo);
11
+ void *internal_allocate_vector_array(unsigned long long int count);
12
+ int internal_align_vectors(unsigned long long int v1, unsigned long long int v2, unsigned int modulo);
13
13
  VALUE internal_apply_operation(VALUE self, VALUE obj, size_t size, VALUE klass, b_operation func);
14
14
  void internal_sanitize_unaligned_final_vector(vector_t *rv, size_t size);
@@ -12,6 +12,9 @@ void Init_SIMD_FloatArray(VALUE parent)
12
12
  rb_define_method(SIMD_FloatArray, "/", method_divide, 1);
13
13
  rb_define_method(SIMD_FloatArray, "+", method_add, 1);
14
14
  rb_define_method(SIMD_FloatArray, "-", method_subtract, 1);
15
+ rb_define_method(SIMD_FloatArray, "&", method_and, 1);
16
+ rb_define_method(SIMD_FloatArray, "|", method_or, 1);
17
+ rb_define_method(SIMD_FloatArray, "^", method_xor, 1);
15
18
  rb_define_method(SIMD_FloatArray, "length", method_length, 0);
16
19
  rb_define_method(SIMD_FloatArray, "to_a", method_to_a, 0);
17
20
  }
@@ -22,7 +25,7 @@ static VALUE method_initialize(VALUE self, VALUE rb_array)
22
25
  {
23
26
  vector_t *vector;
24
27
  d2v_t *data;
25
- unsigned long n,i;
28
+ unsigned long long int n,i;
26
29
 
27
30
  Check_Type(rb_array, T_ARRAY);
28
31
  Data_Get_Struct(self, vector_t, vector);
@@ -75,10 +78,31 @@ static VALUE method_subtract(VALUE self, VALUE obj)
75
78
  return(internal_apply_operation(self, obj, sizeof(double), SIMD_FloatArray, func_subtract));
76
79
  }
77
80
 
81
+ /* Public: and values contained in the data array with those contained in
82
+ * another FloatArray object, returning a new FloatArray. */
83
+ static VALUE method_and(VALUE self, VALUE obj)
84
+ {
85
+ return(internal_apply_operation(self, obj, sizeof(double), SIMD_FloatArray, func_and));
86
+ }
87
+
88
+ /* Public: or values contained in the data array with those contained in
89
+ * another FloatArray object, returning a new FloatArray. */
90
+ static VALUE method_or(VALUE self, VALUE obj)
91
+ {
92
+ return(internal_apply_operation(self, obj, sizeof(double), SIMD_FloatArray, func_or));
93
+ }
94
+
95
+ /* Public: xor values contained in the data array with those contained in
96
+ * another FloatArray object, returning a new FloatArray. */
97
+ static VALUE method_xor(VALUE self, VALUE obj)
98
+ {
99
+ return(internal_apply_operation(self, obj, sizeof(double), SIMD_FloatArray, func_xor));
100
+ }
101
+
78
102
  /* Public: Return a Ruby Array containing the doubles within the data array. */
79
103
  static VALUE method_to_a(VALUE self)
80
104
  {
81
- unsigned long i;
105
+ unsigned long long int i;
82
106
  vector_t *vector;
83
107
  d2v_t *data;
84
108
  VALUE rb_array = rb_ary_new();
@@ -116,3 +140,21 @@ static void func_subtract(void *v1, void *v2, void *r)
116
140
  {
117
141
  *(d2v *)r = *(d2v *)v1 - *(d2v *)v2;
118
142
  }
143
+
144
+ /* Function: Perform a binary AND on two vectors. */
145
+ static void func_and(void *v1, void *v2, void *r)
146
+ {
147
+ *(l2v *)r = *(l2v *)v1 & *(l2v *)v2;
148
+ }
149
+
150
+ /* Function: Perform a binary OR on two vectors. */
151
+ static void func_or(void *v1, void *v2, void *r)
152
+ {
153
+ *(l2v *)r = *(l2v *)v1 | *(l2v *)v2;
154
+ }
155
+
156
+ /* Function: Perform a binary XOR on two vectors. */
157
+ static void func_xor(void *v1, void *v2, void *r)
158
+ {
159
+ *(l2v *)r = *(l2v *)v1 ^ *(l2v *)v2;
160
+ }
@@ -6,9 +6,15 @@ static VALUE method_multiply(VALUE self, VALUE obj);
6
6
  static VALUE method_divide(VALUE self, VALUE obj);
7
7
  static VALUE method_add(VALUE self, VALUE obj);
8
8
  static VALUE method_subtract(VALUE self, VALUE obj);
9
+ static VALUE method_and(VALUE self, VALUE obj);
10
+ static VALUE method_or(VALUE self, VALUE obj);
11
+ static VALUE method_xor(VALUE self, VALUE obj);
9
12
  static VALUE method_to_a(VALUE self);
10
13
 
11
14
  static void func_multiply(void *v1, void *v2, void *r);
12
15
  static void func_divide(void *v1, void *v2, void *r);
13
16
  static void func_add(void *v1, void *v2, void *r);
14
17
  static void func_subtract(void *v1, void *v2, void *r);
18
+ static void func_and(void *v1, void *v2, void *r);
19
+ static void func_or(void *v1, void *v2, void *r);
20
+ static void func_xor(void *v1, void *v2, void *r);
@@ -25,7 +25,7 @@ static VALUE method_initialize(VALUE self, VALUE rb_array)
25
25
  {
26
26
  vector_t *vector;
27
27
  i4v_t *data;
28
- unsigned long n,i;
28
+ unsigned long long int n,i;
29
29
 
30
30
  Check_Type(rb_array, T_ARRAY);
31
31
  Data_Get_Struct(self, vector_t, vector);
@@ -102,7 +102,7 @@ static VALUE method_subtract(VALUE self, VALUE obj)
102
102
  /* Public: Return a Ruby Array containing the doubles within the data array. */
103
103
  static VALUE method_to_a(VALUE self)
104
104
  {
105
- unsigned long i;
105
+ unsigned long long int i;
106
106
  vector_t *vector;
107
107
  i4v_t *data;
108
108
  VALUE rb_array = rb_ary_new();
@@ -5,10 +5,10 @@ static VALUE method_initialize(VALUE self, VALUE rb_array);
5
5
  static VALUE method_multiply(VALUE self, VALUE obj);
6
6
  static VALUE method_divide(VALUE self, VALUE obj);
7
7
  static VALUE method_add(VALUE self, VALUE obj);
8
+ static VALUE method_subtract(VALUE self, VALUE obj);
8
9
  static VALUE method_and(VALUE self, VALUE obj);
9
10
  static VALUE method_or(VALUE self, VALUE obj);
10
11
  static VALUE method_xor(VALUE self, VALUE obj);
11
- static VALUE method_subtract(VALUE self, VALUE obj);
12
12
  static VALUE method_to_a(VALUE self);
13
13
 
14
14
  static void func_multiply(void *v1, void *v2, void *r);
@@ -25,7 +25,7 @@ static VALUE method_initialize(VALUE self, VALUE rb_array)
25
25
  {
26
26
  vector_t *vector;
27
27
  l2v_t *data;
28
- unsigned long n,i;
28
+ unsigned long long int n,i;
29
29
 
30
30
  Check_Type(rb_array, T_ARRAY);
31
31
  Data_Get_Struct(self, vector_t, vector);
@@ -45,7 +45,7 @@ static VALUE method_initialize(VALUE self, VALUE rb_array)
45
45
  data[i/2].f[i%2] = NUM2LONG(rb_ary_entry(rb_array, i));
46
46
  }
47
47
 
48
- internal_sanitize_unaligned_final_vector(vector, sizeof(long));
48
+ internal_sanitize_unaligned_final_vector(vector, sizeof(long long int));
49
49
 
50
50
  return(self);
51
51
  }
@@ -54,55 +54,55 @@ static VALUE method_initialize(VALUE self, VALUE rb_array)
54
54
  * another FloatArray object, returning a new FloatArray. */
55
55
  static VALUE method_multiply(VALUE self, VALUE obj)
56
56
  {
57
- return(internal_apply_operation(self, obj, sizeof(long), SIMD_LongArray, func_multiply));
57
+ return(internal_apply_operation(self, obj, sizeof(long long int), SIMD_LongArray, func_multiply));
58
58
  }
59
59
 
60
60
  /* Public: Divide values contained in the data array by those contained in
61
61
  * another FloatArray object, returning a new FloatArray. */
62
62
  static VALUE method_divide(VALUE self, VALUE obj)
63
63
  {
64
- return(internal_apply_operation(self, obj, sizeof(long), SIMD_LongArray, func_divide));
64
+ return(internal_apply_operation(self, obj, sizeof(long long int), SIMD_LongArray, func_divide));
65
65
  }
66
66
 
67
67
  /* Public: add values contained in the data array with those contained in
68
68
  * another FloatArray object, returning a new FloatArray. */
69
69
  static VALUE method_add(VALUE self, VALUE obj)
70
70
  {
71
- return(internal_apply_operation(self, obj, sizeof(long), SIMD_LongArray, func_add));
71
+ return(internal_apply_operation(self, obj, sizeof(long long int), SIMD_LongArray, func_add));
72
72
  }
73
73
 
74
74
  /* Public: and values contained in the data array with those contained in
75
75
  * another FloatArray object, returning a new FloatArray. */
76
76
  static VALUE method_and(VALUE self, VALUE obj)
77
77
  {
78
- return(internal_apply_operation(self, obj, sizeof(long), SIMD_LongArray, func_and));
78
+ return(internal_apply_operation(self, obj, sizeof(long long int), SIMD_LongArray, func_and));
79
79
  }
80
80
 
81
81
  /* Public: or values contained in the data array with those contained in
82
82
  * another FloatArray object, returning a new FloatArray. */
83
83
  static VALUE method_or(VALUE self, VALUE obj)
84
84
  {
85
- return(internal_apply_operation(self, obj, sizeof(long), SIMD_LongArray, func_or));
85
+ return(internal_apply_operation(self, obj, sizeof(long long int), SIMD_LongArray, func_or));
86
86
  }
87
87
 
88
88
  /* Public: xor values contained in the data array with those contained in
89
89
  * another FloatArray object, returning a new FloatArray. */
90
90
  static VALUE method_xor(VALUE self, VALUE obj)
91
91
  {
92
- return(internal_apply_operation(self, obj, sizeof(long), SIMD_LongArray, func_xor));
92
+ return(internal_apply_operation(self, obj, sizeof(long long int), SIMD_LongArray, func_xor));
93
93
  }
94
94
 
95
95
  /* Public: Subtract values contained in another FloatArray object from those
96
96
  * contained in the current data array object, returning a new FloatArray. */
97
97
  static VALUE method_subtract(VALUE self, VALUE obj)
98
98
  {
99
- return(internal_apply_operation(self, obj, sizeof(long), SIMD_LongArray, func_subtract));
99
+ return(internal_apply_operation(self, obj, sizeof(long long int), SIMD_LongArray, func_subtract));
100
100
  }
101
101
 
102
102
  /* Public: Return a Ruby Array containing the doubles within the data array. */
103
103
  static VALUE method_to_a(VALUE self)
104
104
  {
105
- unsigned long i;
105
+ unsigned long long int i;
106
106
  vector_t *vector;
107
107
  l2v_t *data;
108
108
  VALUE rb_array = rb_ary_new();
@@ -12,6 +12,9 @@ void Init_SIMD_SmallFloatArray(VALUE parent)
12
12
  rb_define_method(SIMD_SmallFloatArray, "/", method_divide, 1);
13
13
  rb_define_method(SIMD_SmallFloatArray, "+", method_add, 1);
14
14
  rb_define_method(SIMD_SmallFloatArray, "-", method_subtract, 1);
15
+ rb_define_method(SIMD_SmallFloatArray, "&", method_and, 1);
16
+ rb_define_method(SIMD_SmallFloatArray, "|", method_or, 1);
17
+ rb_define_method(SIMD_SmallFloatArray, "^", method_xor, 1);
15
18
  rb_define_method(SIMD_SmallFloatArray, "length", method_length, 0);
16
19
  rb_define_method(SIMD_SmallFloatArray, "to_a", method_to_a, 0);
17
20
  }
@@ -22,7 +25,7 @@ static VALUE method_initialize(VALUE self, VALUE rb_array)
22
25
  {
23
26
  vector_t *vector;
24
27
  f4v_t *data;
25
- unsigned long n,i;
28
+ unsigned long long int n,i;
26
29
 
27
30
  Check_Type(rb_array, T_ARRAY);
28
31
  Data_Get_Struct(self, vector_t, vector);
@@ -75,10 +78,31 @@ static VALUE method_subtract(VALUE self, VALUE obj)
75
78
  return(internal_apply_operation(self, obj, sizeof(float), SIMD_SmallFloatArray, func_subtract));
76
79
  }
77
80
 
81
+ /* Public: and values contained in the data array with those contained in
82
+ * another FloatArray object, returning a new FloatArray. */
83
+ static VALUE method_and(VALUE self, VALUE obj)
84
+ {
85
+ return(internal_apply_operation(self, obj, sizeof(float), SIMD_SmallFloatArray, func_and));
86
+ }
87
+
88
+ /* Public: or values contained in the data array with those contained in
89
+ * another FloatArray object, returning a new FloatArray. */
90
+ static VALUE method_or(VALUE self, VALUE obj)
91
+ {
92
+ return(internal_apply_operation(self, obj, sizeof(float), SIMD_SmallFloatArray, func_or));
93
+ }
94
+
95
+ /* Public: xor values contained in the data array with those contained in
96
+ * another FloatArray object, returning a new FloatArray. */
97
+ static VALUE method_xor(VALUE self, VALUE obj)
98
+ {
99
+ return(internal_apply_operation(self, obj, sizeof(float), SIMD_SmallFloatArray, func_xor));
100
+ }
101
+
78
102
  /* Public: Return a Ruby Array containing the doubles within the data array. */
79
103
  static VALUE method_to_a(VALUE self)
80
104
  {
81
- unsigned long i;
105
+ unsigned long long int i;
82
106
  vector_t *vector;
83
107
  f4v_t *data;
84
108
  VALUE rb_array = rb_ary_new();
@@ -116,3 +140,21 @@ static void func_subtract(void *v1, void *v2, void *r)
116
140
  {
117
141
  *(f4v *)r = *(f4v *)v1 - *(f4v *)v2;
118
142
  }
143
+
144
+ /* Function: Perform a binary AND on two vectors. */
145
+ static void func_and(void *v1, void *v2, void *r)
146
+ {
147
+ *(i4v *)r = *(i4v *)v1 & *(i4v *)v2;
148
+ }
149
+
150
+ /* Function: Perform a binary OR on two vectors. */
151
+ static void func_or(void *v1, void *v2, void *r)
152
+ {
153
+ *(i4v *)r = *(i4v *)v1 | *(i4v *)v2;
154
+ }
155
+
156
+ /* Function: Perform a binary XOR on two vectors. */
157
+ static void func_xor(void *v1, void *v2, void *r)
158
+ {
159
+ *(i4v *)r = *(i4v *)v1 ^ *(i4v *)v2;
160
+ }
@@ -6,9 +6,15 @@ static VALUE method_multiply(VALUE self, VALUE obj);
6
6
  static VALUE method_divide(VALUE self, VALUE obj);
7
7
  static VALUE method_add(VALUE self, VALUE obj);
8
8
  static VALUE method_subtract(VALUE self, VALUE obj);
9
+ static VALUE method_and(VALUE self, VALUE obj);
10
+ static VALUE method_or(VALUE self, VALUE obj);
11
+ static VALUE method_xor(VALUE self, VALUE obj);
9
12
  static VALUE method_to_a(VALUE self);
10
13
 
11
14
  static void func_multiply(void *v1, void *v2, void *r);
12
15
  static void func_divide(void *v1, void *v2, void *r);
13
16
  static void func_add(void *v1, void *v2, void *r);
14
17
  static void func_subtract(void *v1, void *v2, void *r);
18
+ static void func_and(void *v1, void *v2, void *r);
19
+ static void func_or(void *v1, void *v2, void *r);
20
+ static void func_xor(void *v1, void *v2, void *r);
@@ -40,17 +40,17 @@ typedef union i4v_t
40
40
  /*
41
41
  * Types for LongArray
42
42
  */
43
- typedef long int __attribute__ ((vector_size (16))) l2v;
43
+ typedef long long int __attribute__ ((vector_size (16))) l2v;
44
44
  typedef union l2v_t
45
45
  {
46
46
  l2v v;
47
- long int f[2];
47
+ long long int f[2];
48
48
  } l2v_t;
49
49
 
50
50
  typedef struct vector_t
51
51
  {
52
52
  void *data;
53
- unsigned long len;
53
+ unsigned long long int len;
54
54
  } vector_t;
55
55
 
56
56
  typedef void (b_operation)(void *v1, void *v2, void *r);
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tina Wuest
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-16 00:00:00.000000000 Z
11
+ date: 2015-02-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler
@@ -64,7 +64,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
64
64
  version: '0'
65
65
  requirements: []
66
66
  rubyforge_project:
67
- rubygems_version: 2.2.2
67
+ rubygems_version: 2.4.5
68
68
  signing_key:
69
69
  specification_version: 4
70
70
  summary: SIMD instructions in ruby