simd 0.5.2 → 0.6.0

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: d43585672169c7a727e7502dea99cb56e8103c2e6a8effe4f32521ee4cae6e5d
4
- data.tar.gz: c404674a578002bdf5933baee75e54680717c562b1e8c839a0661e04dfee27a6
3
+ metadata.gz: 3d53f8f1be0f91871b2d9c24f8391a670d95773055e63f85f9c8f68773afcfd1
4
+ data.tar.gz: 336eb325b0a915398143b74eff672c44caaac641142893f54e50fbdd4ea63713
5
5
  SHA512:
6
- metadata.gz: 86c6b9e43f219190f4bd2a34d0ad1c309eacb56068dbdb0d44f46894b1ceee19bc68c77d4f682d42b335039250730c9637a1d19c5075861c9731fd13a48d71d0
7
- data.tar.gz: a71afed09b9ead560531c9ec2a9ffb0260843398255963b549abe44db0b45dc036fb604a945c9caff7f5d54dd51626f78ed4f2877803a9a5d2bc455e68c5c332
6
+ metadata.gz: ff39834f43fda25c6666fb10283515d04c80560c818eb75e32d01de8858558cca27205d177abf0e7488c1f195b03149b0dec1a24536b233214eb176053a7f6b2
7
+ data.tar.gz: 8caebb2c57d4c2274f485a66af676590ad589837bbea4de8bb3a2fb0613c9c8c3a40069d1a2871368961a4cd1116236ba5f91be88d38539b7d5bdd190b89809b
@@ -131,6 +131,34 @@ VALUE internal_apply_operation(VALUE self, VALUE obj, size_t size, VALUE klass,
131
131
  }
132
132
  #pragma GCC diagnostic pop
133
133
 
134
+ /* Internal: Perform an unary operation across one vector.
135
+ *
136
+ * As above, disable warnings regarding this for the current function. */
137
+ #pragma GCC diagnostic push
138
+ #pragma GCC diagnostic ignored "-Wpointer-arith"
139
+ VALUE internal_apply_unary_operation(VALUE self, size_t size, VALUE klass, u_operation func)
140
+ {
141
+ unsigned long long int length, i;
142
+ vector_t *v1, *rv;
143
+ VALUE result_obj = allocate(klass);
144
+
145
+ Data_Get_Struct(self, vector_t, v1);
146
+ Data_Get_Struct(result_obj, vector_t, rv);
147
+ rv->data = internal_allocate_vector_array(v1->len);
148
+
149
+ length = ((v1->len + (XMM_BYTES / size - 1)) / (XMM_BYTES / size));
150
+ rv->len = v1->len;
151
+
152
+ for(i = 0; i < length; i++)
153
+ {
154
+ func((v1->data + XMM_BYTES * i), (rv->data + XMM_BYTES * i));
155
+ }
156
+ internal_sanitize_unaligned_final_vector(rv, size);
157
+
158
+ return(result_obj);
159
+ }
160
+ #pragma GCC diagnostic pop
161
+
134
162
  /* Internal: Make sure that no null bytes exist beyond the boundary of
135
163
  * unaligned vectors. This function should be called after any operation that
136
164
  * results in the mutation or creation of a vector array.
@@ -11,4 +11,5 @@ VALUE method_length(VALUE self);
11
11
  void *internal_allocate_vector_array(unsigned long long int count);
12
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
+ VALUE internal_apply_unary_operation(VALUE self, size_t size, VALUE klass, u_operation func);
14
15
  void internal_sanitize_unaligned_final_vector(vector_t *rv, size_t size);
@@ -13,13 +13,20 @@ void Init_SIMD_FloatArray(VALUE parent)
13
13
  rb_define_method(SIMD_FloatArray, "/", method_divide, 1);
14
14
  rb_define_method(SIMD_FloatArray, "+", method_add, 1);
15
15
  rb_define_method(SIMD_FloatArray, "-", method_subtract, 1);
16
+ rb_define_method(SIMD_FloatArray, "sqrt", method_sqrt, 0);
16
17
  rb_define_method(SIMD_FloatArray, "&", method_and, 1);
17
18
  rb_define_method(SIMD_FloatArray, "|", method_or, 1);
18
19
  rb_define_method(SIMD_FloatArray, "^", method_xor, 1);
19
20
  rb_define_method(SIMD_FloatArray, "gt", method_gt, 1);
20
21
  rb_define_method(SIMD_FloatArray, "lt", method_lt, 1);
22
+ rb_define_method(SIMD_FloatArray, "gte", method_gte, 1);
23
+ rb_define_method(SIMD_FloatArray, "lte", method_lte, 1);
21
24
  rb_define_method(SIMD_FloatArray, ">", method_gt, 1);
22
25
  rb_define_method(SIMD_FloatArray, "<", method_lt, 1);
26
+ rb_define_method(SIMD_FloatArray, ">=", method_gte, 1);
27
+ rb_define_method(SIMD_FloatArray, "<=", method_lte, 1);
28
+ rb_define_method(SIMD_FloatArray, "eq", method_eq, 1);
29
+ rb_define_method(SIMD_FloatArray, "neq", method_neq, 1);
23
30
  rb_define_method(SIMD_FloatArray, "length", method_length, 0);
24
31
  rb_define_method(SIMD_FloatArray, "to_a", method_to_a, 0);
25
32
  }
@@ -83,6 +90,13 @@ static VALUE method_subtract(VALUE self, VALUE obj)
83
90
  return(internal_apply_operation(self, obj, sizeof(double), SIMD_FloatArray, func_subtract));
84
91
  }
85
92
 
93
+ /* Public: Compute the square root of values contained in a FloatArray object,
94
+ * returning a new FloatArray. */
95
+ static VALUE method_sqrt(VALUE self)
96
+ {
97
+ return(internal_apply_unary_operation(self, sizeof(double), SIMD_FloatArray, func_sqrt));
98
+ }
99
+
86
100
  /* Public: and values contained in the data array with those contained in
87
101
  * another FloatArray object, returning a new FloatArray. */
88
102
  static VALUE method_and(VALUE self, VALUE obj)
@@ -120,6 +134,38 @@ static VALUE method_lt(VALUE self, VALUE obj)
120
134
  return(internal_apply_operation(self, obj, sizeof(double), SIMD_LongArray, func_lt));
121
135
  }
122
136
 
137
+ /* Public: Compare values contained in the data array with those contained in
138
+ * another FloatArray object, return a new LongArray with each element being -1
139
+ * if the data array's value is greater or equal, and 0 otherwise. */
140
+ static VALUE method_gte(VALUE self, VALUE obj)
141
+ {
142
+ return(internal_apply_operation(self, obj, sizeof(double), SIMD_LongArray, func_gte));
143
+ }
144
+
145
+ /* Public: Compare values contained in the data array with those contained in
146
+ * another FloatArray object, return a new LongArray with each element being -1
147
+ * if the data array's value is less or equal, and 0 otherwise. */
148
+ static VALUE method_lte(VALUE self, VALUE obj)
149
+ {
150
+ return(internal_apply_operation(self, obj, sizeof(double), SIMD_LongArray, func_lte));
151
+ }
152
+
153
+ /* Public: Compare values contained in the data array with those contained in
154
+ * another FloatArray object, return a new LongArray with each element being
155
+ * -1 if the data array's value is equal, and 0 otherwise. */
156
+ static VALUE method_eq(VALUE self, VALUE obj)
157
+ {
158
+ return(internal_apply_operation(self, obj, sizeof(double), SIMD_LongArray, func_eq));
159
+ }
160
+
161
+ /* Public: Compare values contained in the data array with those contained in
162
+ * another FloatArray object, return a new LongArray with each element being
163
+ * 0 if the data array's value is equal, and -1 otherwise. */
164
+ static VALUE method_neq(VALUE self, VALUE obj)
165
+ {
166
+ return(internal_apply_operation(self, obj, sizeof(double), SIMD_LongArray, func_neq));
167
+ }
168
+
123
169
  /* Public: Return a Ruby Array containing the doubles within the data array. */
124
170
  static VALUE method_to_a(VALUE self)
125
171
  {
@@ -162,6 +208,13 @@ static void func_subtract(void *v1, void *v2, void *r)
162
208
  *(d2v *)r = *(d2v *)v1 - *(d2v *)v2;
163
209
  }
164
210
 
211
+ /* Function: Compute square root for a vector. */
212
+ static void func_sqrt(void *v1, void *r)
213
+ {
214
+ (*(d2v *)r)[0] = sqrt((*(d2v *)v1)[0]);
215
+ (*(d2v *)r)[1] = sqrt((*(d2v *)v1)[1]);
216
+ }
217
+
165
218
  /* Function: Perform a binary AND on two vectors. */
166
219
  static void func_and(void *v1, void *v2, void *r)
167
220
  {
@@ -191,3 +244,28 @@ static void func_lt(void *v1, void *v2, void *r)
191
244
  {
192
245
  *(l2v *)r = (*(d2v *)v1 < *(d2v *)v2);
193
246
  }
247
+
248
+ /* Function: Compare vectors, return -1 if v1 is greater than v2, 0 otherwise */
249
+ static void func_gte(void *v1, void *v2, void *r)
250
+ {
251
+ *(l2v *)r = (*(d2v *)v1 >= *(d2v *)v2);
252
+ }
253
+
254
+ /* Function: Compare vectors, return -1 if v1 is less than v2, 0 otherwise */
255
+ static void func_lte(void *v1, void *v2, void *r)
256
+ {
257
+ *(l2v *)r = (*(d2v *)v1 <= *(d2v *)v2);
258
+ }
259
+
260
+ /* Function: Compare vectors, return -1 if v1 is equal to v2, 0 otherwise */
261
+ static void func_eq(void *v1, void *v2, void *r)
262
+ {
263
+ *(l2v *)r = (*(d2v *)v1 == *(d2v *)v2);
264
+ }
265
+
266
+
267
+ /* Function: Compare vectors, return 0 if v1 is equal to v2, -1 otherwise */
268
+ static void func_neq(void *v1, void *v2, void *r)
269
+ {
270
+ *(l2v *)r = (*(d2v *)v1 != *(d2v *)v2);
271
+ }
@@ -1,24 +1,36 @@
1
1
  #include "ruby.h"
2
2
  #include "simd_common.h"
3
3
 
4
+ extern VALUE SIMD_FloatArray;
5
+
4
6
  static VALUE method_initialize(VALUE self, VALUE rb_array);
5
7
  static VALUE method_multiply(VALUE self, VALUE obj);
6
8
  static VALUE method_divide(VALUE self, VALUE obj);
7
9
  static VALUE method_add(VALUE self, VALUE obj);
8
10
  static VALUE method_subtract(VALUE self, VALUE obj);
11
+ static VALUE method_sqrt(VALUE self);
9
12
  static VALUE method_and(VALUE self, VALUE obj);
10
13
  static VALUE method_or(VALUE self, VALUE obj);
11
14
  static VALUE method_xor(VALUE self, VALUE obj);
12
15
  static VALUE method_gt(VALUE self, VALUE obj);
13
16
  static VALUE method_lt(VALUE self, VALUE obj);
17
+ static VALUE method_gte(VALUE self, VALUE obj);
18
+ static VALUE method_lte(VALUE self, VALUE obj);
19
+ static VALUE method_eq(VALUE self, VALUE obj);
20
+ static VALUE method_neq(VALUE self, VALUE obj);
14
21
  static VALUE method_to_a(VALUE self);
15
22
 
16
23
  static void func_multiply(void *v1, void *v2, void *r);
17
24
  static void func_divide(void *v1, void *v2, void *r);
18
25
  static void func_add(void *v1, void *v2, void *r);
19
26
  static void func_subtract(void *v1, void *v2, void *r);
27
+ static void func_sqrt(void *v1, void *r);
20
28
  static void func_and(void *v1, void *v2, void *r);
21
29
  static void func_or(void *v1, void *v2, void *r);
22
30
  static void func_xor(void *v1, void *v2, void *r);
23
31
  static void func_gt(void *v1, void *v2, void *r);
24
32
  static void func_lt(void *v1, void *v2, void *r);
33
+ static void func_gte(void *v1, void *v2, void *r);
34
+ static void func_lte(void *v1, void *v2, void *r);
35
+ static void func_eq(void *v1, void *v2, void *r);
36
+ static void func_neq(void *v1, void *v2, void *r);
@@ -1,4 +1,5 @@
1
1
  #include "simd_intarray.h"
2
+ #include "simd_smallfloatarray.h"
2
3
 
3
4
  VALUE SIMD_IntArray = Qnil;
4
5
 
@@ -12,13 +13,20 @@ void Init_SIMD_IntArray(VALUE parent)
12
13
  rb_define_method(SIMD_IntArray, "/", method_divide, 1);
13
14
  rb_define_method(SIMD_IntArray, "+", method_add, 1);
14
15
  rb_define_method(SIMD_IntArray, "-", method_subtract, 1);
16
+ rb_define_method(SIMD_IntArray, "sqrt", method_sqrt, 0);
15
17
  rb_define_method(SIMD_IntArray, "&", method_and, 1);
16
18
  rb_define_method(SIMD_IntArray, "|", method_or, 1);
17
19
  rb_define_method(SIMD_IntArray, "^", method_xor, 1);
18
20
  rb_define_method(SIMD_IntArray, "gt", method_gt, 1);
19
21
  rb_define_method(SIMD_IntArray, "lt", method_lt, 1);
22
+ rb_define_method(SIMD_IntArray, "gte", method_gte, 1);
23
+ rb_define_method(SIMD_IntArray, "lte", method_lte, 1);
24
+ rb_define_method(SIMD_IntArray, "eq", method_eq, 1);
25
+ rb_define_method(SIMD_IntArray, "neq", method_neq, 1);
20
26
  rb_define_method(SIMD_IntArray, ">", method_gt, 1);
21
27
  rb_define_method(SIMD_IntArray, "<", method_lt, 1);
28
+ rb_define_method(SIMD_IntArray, ">=", method_gte, 1);
29
+ rb_define_method(SIMD_IntArray, "<=", method_lte, 1);
22
30
  rb_define_method(SIMD_IntArray, "length", method_length, 0);
23
31
  rb_define_method(SIMD_IntArray, "to_a", method_to_a, 0);
24
32
  }
@@ -68,6 +76,20 @@ static VALUE method_divide(VALUE self, VALUE obj)
68
76
  return(internal_apply_operation(self, obj, sizeof(int), SIMD_IntArray, func_divide));
69
77
  }
70
78
 
79
+ /* Public: Subtract values contained in another FloatArray object from those
80
+ * contained in the current data array object, returning a new FloatArray. */
81
+ static VALUE method_subtract(VALUE self, VALUE obj)
82
+ {
83
+ return(internal_apply_operation(self, obj, sizeof(int), SIMD_IntArray, func_subtract));
84
+ }
85
+
86
+ /* Public: Compute the square root of values contained in a IntArray object,
87
+ * returning a new SmallFloatArray. */
88
+ static VALUE method_sqrt(VALUE self)
89
+ {
90
+ return(internal_apply_unary_operation(self, sizeof(int), SIMD_SmallFloatArray, func_sqrt));
91
+ }
92
+
71
93
  /* Public: add values contained in the data array with those contained in
72
94
  * another FloatArray object, returning a new FloatArray. */
73
95
  static VALUE method_add(VALUE self, VALUE obj)
@@ -112,11 +134,36 @@ static VALUE method_lt(VALUE self, VALUE obj)
112
134
  return(internal_apply_operation(self, obj, sizeof(int), SIMD_IntArray, func_lt));
113
135
  }
114
136
 
115
- /* Public: Subtract values contained in another FloatArray object from those
116
- * contained in the current data array object, returning a new FloatArray. */
117
- static VALUE method_subtract(VALUE self, VALUE obj)
137
+ /* Public: Compare values contained in the data array with those contained in
138
+ * another IntArray object, return a new IntArray with each element being -1 if
139
+ * the data array's value is greater or equal, and 0 otherwise. */
140
+ static VALUE method_gte(VALUE self, VALUE obj)
118
141
  {
119
- return(internal_apply_operation(self, obj, sizeof(int), SIMD_IntArray, func_subtract));
142
+ return(internal_apply_operation(self, obj, sizeof(int), SIMD_IntArray, func_gte));
143
+ }
144
+
145
+ /* Public: Compare values contained in the data array with those contained in
146
+ * another IntArray object, return a new IntArray with each element being -1 if
147
+ * the data array's value is less or equal, and 0 otherwise. */
148
+ static VALUE method_lte(VALUE self, VALUE obj)
149
+ {
150
+ return(internal_apply_operation(self, obj, sizeof(int), SIMD_IntArray, func_lte));
151
+ }
152
+
153
+ /* Public: Compare values contained in the data array with those contained in
154
+ * another IntArray object, return a new IntArray with each element being -1 if
155
+ * the data array's value is equal, and 0 otherwise. */
156
+ static VALUE method_eq(VALUE self, VALUE obj)
157
+ {
158
+ return(internal_apply_operation(self, obj, sizeof(int), SIMD_IntArray, func_eq));
159
+ }
160
+
161
+ /* Public: Compare values contained in the data array with those contained in
162
+ * another IntArray object, return a new IntArray with each element being 0 if
163
+ * the data array's value is equal, and -1 otherwise. */
164
+ static VALUE method_neq(VALUE self, VALUE obj)
165
+ {
166
+ return(internal_apply_operation(self, obj, sizeof(int), SIMD_IntArray, func_neq));
120
167
  }
121
168
 
122
169
  /* Public: Return a Ruby Array containing the doubles within the data array. */
@@ -161,6 +208,15 @@ static void func_subtract(void *v1, void *v2, void *r)
161
208
  *(i4v *)r = *(i4v *)v1 - *(i4v *)v2;
162
209
  }
163
210
 
211
+ /* Function: Compute square root for a vector. */
212
+ static void func_sqrt(void *v1, void *r)
213
+ {
214
+ (*(f4v *)r)[0] = sqrt((*(i4v *)v1)[0]);
215
+ (*(f4v *)r)[1] = sqrt((*(i4v *)v1)[1]);
216
+ (*(f4v *)r)[2] = sqrt((*(i4v *)v1)[2]);
217
+ (*(f4v *)r)[3] = sqrt((*(i4v *)v1)[3]);
218
+ }
219
+
164
220
  /* Function: Perform a binary AND on two vectors. */
165
221
  static void func_and(void *v1, void *v2, void *r)
166
222
  {
@@ -190,3 +246,27 @@ static void func_lt(void *v1, void *v2, void *r)
190
246
  {
191
247
  *(i4v *)r = (*(i4v *)v1 < *(i4v *)v2);
192
248
  }
249
+
250
+ /* Function: Compare vectors, return -1 if v1 is greater than v2, 0 otherwise */
251
+ static void func_gte(void *v1, void *v2, void *r)
252
+ {
253
+ *(i4v *)r = (*(i4v *)v1 >= *(i4v *)v2);
254
+ }
255
+
256
+ /* Function: Compare vectors, return -1 if v1 is less than v2, 0 otherwise */
257
+ static void func_lte(void *v1, void *v2, void *r)
258
+ {
259
+ *(i4v *)r = (*(i4v *)v1 <= *(i4v *)v2);
260
+ }
261
+
262
+ /* Function: Compare vectors, return -1 if v1 is equal to v2, 0 otherwise */
263
+ static void func_eq(void *v1, void *v2, void *r)
264
+ {
265
+ *(i4v *)r = (*(i4v *)v1 == *(i4v *)v2);
266
+ }
267
+
268
+ /* Function: Compare vectors, return 0 if v1 is equal to v2, -1 otherwise */
269
+ static void func_neq(void *v1, void *v2, void *r)
270
+ {
271
+ *(i4v *)r = (*(i4v *)v1 != *(i4v *)v2);
272
+ }
@@ -8,19 +8,29 @@ static VALUE method_multiply(VALUE self, VALUE obj);
8
8
  static VALUE method_divide(VALUE self, VALUE obj);
9
9
  static VALUE method_add(VALUE self, VALUE obj);
10
10
  static VALUE method_subtract(VALUE self, VALUE obj);
11
+ static VALUE method_sqrt(VALUE self);
11
12
  static VALUE method_and(VALUE self, VALUE obj);
12
13
  static VALUE method_or(VALUE self, VALUE obj);
13
14
  static VALUE method_xor(VALUE self, VALUE obj);
14
15
  static VALUE method_gt(VALUE self, VALUE obj);
15
16
  static VALUE method_lt(VALUE self, VALUE obj);
17
+ static VALUE method_gte(VALUE self, VALUE obj);
18
+ static VALUE method_lte(VALUE self, VALUE obj);
19
+ static VALUE method_eq(VALUE self, VALUE obj);
20
+ static VALUE method_neq(VALUE self, VALUE obj);
16
21
  static VALUE method_to_a(VALUE self);
17
22
 
18
23
  static void func_multiply(void *v1, void *v2, void *r);
19
24
  static void func_divide(void *v1, void *v2, void *r);
20
25
  static void func_add(void *v1, void *v2, void *r);
21
26
  static void func_subtract(void *v1, void *v2, void *r);
27
+ static void func_sqrt(void *v1, void *r);
22
28
  static void func_and(void *v1, void *v2, void *r);
23
29
  static void func_or(void *v1, void *v2, void *r);
24
30
  static void func_xor(void *v1, void *v2, void *r);
25
31
  static void func_gt(void *v1, void *v2, void *r);
26
32
  static void func_lt(void *v1, void *v2, void *r);
33
+ static void func_gte(void *v1, void *v2, void *r);
34
+ static void func_lte(void *v1, void *v2, void *r);
35
+ static void func_eq(void *v1, void *v2, void *r);
36
+ static void func_neq(void *v1, void *v2, void *r);
@@ -1,4 +1,5 @@
1
1
  #include "simd_longarray.h"
2
+ #include "simd_floatarray.h"
2
3
 
3
4
  VALUE SIMD_LongArray = Qnil;
4
5
 
@@ -12,13 +13,20 @@ void Init_SIMD_LongArray(VALUE parent)
12
13
  rb_define_method(SIMD_LongArray, "/", method_divide, 1);
13
14
  rb_define_method(SIMD_LongArray, "+", method_add, 1);
14
15
  rb_define_method(SIMD_LongArray, "-", method_subtract, 1);
16
+ rb_define_method(SIMD_LongArray, "sqrt", method_sqrt, 0);
15
17
  rb_define_method(SIMD_LongArray, "&", method_and, 1);
16
18
  rb_define_method(SIMD_LongArray, "|", method_or, 1);
17
19
  rb_define_method(SIMD_LongArray, "^", method_xor, 1);
18
20
  rb_define_method(SIMD_LongArray, "gt", method_gt, 1);
19
21
  rb_define_method(SIMD_LongArray, "lt", method_lt, 1);
22
+ rb_define_method(SIMD_LongArray, "gte", method_gte, 1);
23
+ rb_define_method(SIMD_LongArray, "lte", method_lte, 1);
20
24
  rb_define_method(SIMD_LongArray, ">", method_gt, 1);
21
25
  rb_define_method(SIMD_LongArray, "<", method_lt, 1);
26
+ rb_define_method(SIMD_LongArray, ">=", method_gte, 1);
27
+ rb_define_method(SIMD_LongArray, "<=", method_lte, 1);
28
+ rb_define_method(SIMD_LongArray, "eq", method_eq, 1);
29
+ rb_define_method(SIMD_LongArray, "neq", method_neq, 1);
22
30
  rb_define_method(SIMD_LongArray, "length", method_length, 0);
23
31
  rb_define_method(SIMD_LongArray, "to_a", method_to_a, 0);
24
32
  }
@@ -75,6 +83,20 @@ static VALUE method_add(VALUE self, VALUE obj)
75
83
  return(internal_apply_operation(self, obj, sizeof(long long int), SIMD_LongArray, func_add));
76
84
  }
77
85
 
86
+ /* Public: Subtract values contained in another FloatArray object from those
87
+ * contained in the current data array object, returning a new FloatArray. */
88
+ static VALUE method_subtract(VALUE self, VALUE obj)
89
+ {
90
+ return(internal_apply_operation(self, obj, sizeof(long long int), SIMD_LongArray, func_subtract));
91
+ }
92
+
93
+ /* Public: Compute the square root of values contained in a LongArray object,
94
+ * returning a new FloatArray. */
95
+ static VALUE method_sqrt(VALUE self)
96
+ {
97
+ return(internal_apply_unary_operation(self, sizeof(long long int), SIMD_FloatArray, func_sqrt));
98
+ }
99
+
78
100
  /* Public: and values contained in the data array with those contained in
79
101
  * another FloatArray object, returning a new FloatArray. */
80
102
  static VALUE method_and(VALUE self, VALUE obj)
@@ -97,7 +119,7 @@ static VALUE method_xor(VALUE self, VALUE obj)
97
119
  }
98
120
 
99
121
  /* Public: Compare values contained in the data array with those contained in
100
- * another Longrray object, return a new LongArray with each element being -1
122
+ * another LongArray object, return a new LongArray with each element being -1
101
123
  * if the data array's value is greater, and 0 otherwise. */
102
124
  static VALUE method_gt(VALUE self, VALUE obj)
103
125
  {
@@ -112,11 +134,36 @@ static VALUE method_lt(VALUE self, VALUE obj)
112
134
  return(internal_apply_operation(self, obj, sizeof(long long int), SIMD_LongArray, func_lt));
113
135
  }
114
136
 
115
- /* Public: Subtract values contained in another FloatArray object from those
116
- * contained in the current data array object, returning a new FloatArray. */
117
- static VALUE method_subtract(VALUE self, VALUE obj)
137
+ /* Public: Compare values contained in the data array with those contained in
138
+ * another LongArray object, return a new LongArray with each element being -1
139
+ * if the data array's value is greater or equal, and 0 otherwise. */
140
+ static VALUE method_gte(VALUE self, VALUE obj)
118
141
  {
119
- return(internal_apply_operation(self, obj, sizeof(long long int), SIMD_LongArray, func_subtract));
142
+ return(internal_apply_operation(self, obj, sizeof(long long int), SIMD_LongArray, func_gte));
143
+ }
144
+
145
+ /* Public: Compare values contained in the data array with those contained in
146
+ * another LongArray object, return a new LongArray with each element being -1 if
147
+ * the data array's value is less or equal, and 0 otherwise. */
148
+ static VALUE method_lte(VALUE self, VALUE obj)
149
+ {
150
+ return(internal_apply_operation(self, obj, sizeof(long long int), SIMD_LongArray, func_lte));
151
+ }
152
+
153
+ /* Public: Compare values contained in the data array with those contained in
154
+ * another LongArray object, return a new LongArray with each element being -1
155
+ * if the data array's value is equal, and 0 otherwise. */
156
+ static VALUE method_eq(VALUE self, VALUE obj)
157
+ {
158
+ return(internal_apply_operation(self, obj, sizeof(long long int), SIMD_LongArray, func_eq));
159
+ }
160
+
161
+ /* Public: Compare values contained in the data array with those contained in
162
+ * another LongArray object, return a new LongArray with each element being 0 if
163
+ * the data array's value is equal, and -1 otherwise. */
164
+ static VALUE method_neq(VALUE self, VALUE obj)
165
+ {
166
+ return(internal_apply_operation(self, obj, sizeof(long long int), SIMD_LongArray, func_neq));
120
167
  }
121
168
 
122
169
  /* Public: Return a Ruby Array containing the doubles within the data array. */
@@ -161,6 +208,13 @@ static void func_subtract(void *v1, void *v2, void *r)
161
208
  *(l2v *)r = *(l2v *)v1 - *(l2v *)v2;
162
209
  }
163
210
 
211
+ /* Function: Compute square root for a vector. */
212
+ static void func_sqrt(void *v1, void *r)
213
+ {
214
+ (*(d2v *)r)[0] = sqrt((*(l2v *)v1)[0]);
215
+ (*(d2v *)r)[1] = sqrt((*(l2v *)v1)[1]);
216
+ }
217
+
164
218
  /* Function: Perform a binary AND on two vectors. */
165
219
  static void func_and(void *v1, void *v2, void *r)
166
220
  {
@@ -190,3 +244,27 @@ static void func_lt(void *v1, void *v2, void *r)
190
244
  {
191
245
  *(l2v *)r = (*(l2v *)v1 < *(l2v *)v2);
192
246
  }
247
+
248
+ /* Function: Compare vectors, return -1 if v1 is greater than v2, 0 otherwise */
249
+ static void func_gte(void *v1, void *v2, void *r)
250
+ {
251
+ *(l2v *)r = (*(l2v *)v1 >= *(l2v *)v2);
252
+ }
253
+
254
+ /* Function: Compare vectors, return -1 if v1 is less than v2, 0 otherwise */
255
+ static void func_lte(void *v1, void *v2, void *r)
256
+ {
257
+ *(l2v *)r = (*(l2v *)v1 <= *(l2v *)v2);
258
+ }
259
+
260
+ /* Function: Compare vectors, return -1 if v1 is equal to v2, 0 otherwise */
261
+ static void func_eq(void *v1, void *v2, void *r)
262
+ {
263
+ *(l2v *)r = (*(l2v *)v1 == *(l2v *)v2);
264
+ }
265
+
266
+ /* Function: Compare vectors, return 0 if v1 is equal to v2, -1 otherwise */
267
+ static void func_neq(void *v1, void *v2, void *r)
268
+ {
269
+ *(l2v *)r = (*(l2v *)v1 != *(l2v *)v2);
270
+ }
@@ -8,19 +8,29 @@ static VALUE method_multiply(VALUE self, VALUE obj);
8
8
  static VALUE method_divide(VALUE self, VALUE obj);
9
9
  static VALUE method_add(VALUE self, VALUE obj);
10
10
  static VALUE method_subtract(VALUE self, VALUE obj);
11
+ static VALUE method_sqrt(VALUE self);
11
12
  static VALUE method_and(VALUE self, VALUE obj);
12
13
  static VALUE method_or(VALUE self, VALUE obj);
13
14
  static VALUE method_xor(VALUE self, VALUE obj);
14
15
  static VALUE method_gt(VALUE self, VALUE obj);
15
16
  static VALUE method_lt(VALUE self, VALUE obj);
17
+ static VALUE method_gte(VALUE self, VALUE obj);
18
+ static VALUE method_lte(VALUE self, VALUE obj);
19
+ static VALUE method_eq(VALUE self, VALUE obj);
20
+ static VALUE method_neq(VALUE self, VALUE obj);
16
21
  static VALUE method_to_a(VALUE self);
17
22
 
18
23
  static void func_multiply(void *v1, void *v2, void *r);
19
24
  static void func_divide(void *v1, void *v2, void *r);
20
25
  static void func_add(void *v1, void *v2, void *r);
21
26
  static void func_subtract(void *v1, void *v2, void *r);
27
+ static void func_sqrt(void *v1, void *r);
22
28
  static void func_and(void *v1, void *v2, void *r);
23
29
  static void func_or(void *v1, void *v2, void *r);
24
30
  static void func_xor(void *v1, void *v2, void *r);
25
31
  static void func_gt(void *v1, void *v2, void *r);
26
32
  static void func_lt(void *v1, void *v2, void *r);
33
+ static void func_gte(void *v1, void *v2, void *r);
34
+ static void func_lte(void *v1, void *v2, void *r);
35
+ static void func_eq(void *v1, void *v2, void *r);
36
+ static void func_neq(void *v1, void *v2, void *r);
@@ -13,13 +13,20 @@ void Init_SIMD_SmallFloatArray(VALUE parent)
13
13
  rb_define_method(SIMD_SmallFloatArray, "/", method_divide, 1);
14
14
  rb_define_method(SIMD_SmallFloatArray, "+", method_add, 1);
15
15
  rb_define_method(SIMD_SmallFloatArray, "-", method_subtract, 1);
16
+ rb_define_method(SIMD_SmallFloatArray, "sqrt", method_sqrt, 0);
16
17
  rb_define_method(SIMD_SmallFloatArray, "&", method_and, 1);
17
18
  rb_define_method(SIMD_SmallFloatArray, "|", method_or, 1);
18
19
  rb_define_method(SIMD_SmallFloatArray, "^", method_xor, 1);
19
20
  rb_define_method(SIMD_SmallFloatArray, "gt", method_gt, 1);
20
21
  rb_define_method(SIMD_SmallFloatArray, "lt", method_lt, 1);
22
+ rb_define_method(SIMD_SmallFloatArray, "gte", method_gte, 1);
23
+ rb_define_method(SIMD_SmallFloatArray, "lte", method_lte, 1);
24
+ rb_define_method(SIMD_SmallFloatArray, "eq", method_eq, 1);
25
+ rb_define_method(SIMD_SmallFloatArray, "neq", method_neq, 1);
21
26
  rb_define_method(SIMD_SmallFloatArray, ">", method_gt, 1);
22
27
  rb_define_method(SIMD_SmallFloatArray, "<", method_lt, 1);
28
+ rb_define_method(SIMD_SmallFloatArray, ">=", method_gte, 1);
29
+ rb_define_method(SIMD_SmallFloatArray, "<=", method_lte, 1);
23
30
  rb_define_method(SIMD_SmallFloatArray, "length", method_length, 0);
24
31
  rb_define_method(SIMD_SmallFloatArray, "to_a", method_to_a, 0);
25
32
  }
@@ -83,6 +90,13 @@ static VALUE method_subtract(VALUE self, VALUE obj)
83
90
  return(internal_apply_operation(self, obj, sizeof(float), SIMD_SmallFloatArray, func_subtract));
84
91
  }
85
92
 
93
+ /* Public: Compute the square root of values contained in a SmallFloatArray
94
+ * object, returning a new SmallFloatArray. */
95
+ static VALUE method_sqrt(VALUE self)
96
+ {
97
+ return(internal_apply_unary_operation(self, sizeof(float), SIMD_SmallFloatArray, func_sqrt));
98
+ }
99
+
86
100
  /* Public: and values contained in the data array with those contained in
87
101
  * another FloatArray object, returning a new FloatArray. */
88
102
  static VALUE method_and(VALUE self, VALUE obj)
@@ -120,6 +134,38 @@ static VALUE method_lt(VALUE self, VALUE obj)
120
134
  return(internal_apply_operation(self, obj, sizeof(float), SIMD_IntArray, func_lt));
121
135
  }
122
136
 
137
+ /* Public: Compare values contained in the data array with those contained in
138
+ * another SmallFloatArray object, return a new IntArray with each element being
139
+ * -1 if the data array's value is greater or equal, and 0 otherwise. */
140
+ static VALUE method_gte(VALUE self, VALUE obj)
141
+ {
142
+ return(internal_apply_operation(self, obj, sizeof(float), SIMD_IntArray, func_gte));
143
+ }
144
+
145
+ /* Public: Compare values contained in the data array with those contained in
146
+ * another SmallFloatArray object, return a new IntArray with each element being
147
+ * -1 if the data array's value is less or equal, and 0 otherwise. */
148
+ static VALUE method_lte(VALUE self, VALUE obj)
149
+ {
150
+ return(internal_apply_operation(self, obj, sizeof(float), SIMD_IntArray, func_lte));
151
+ }
152
+
153
+ /* Public: Compare values contained in the data array with those contained in
154
+ * another SmallFloatArray object, return a new IntArray with each element being
155
+ * -1 if the data array's value is equal, and 0 otherwise. */
156
+ static VALUE method_eq(VALUE self, VALUE obj)
157
+ {
158
+ return(internal_apply_operation(self, obj, sizeof(float), SIMD_IntArray, func_eq));
159
+ }
160
+
161
+ /* Public: Compare values contained in the data array with those contained in
162
+ * another SmallFloatArray object, return a new IntArray with each element being
163
+ * 0 if the data array's value is equal, and -1 otherwise. */
164
+ static VALUE method_neq(VALUE self, VALUE obj)
165
+ {
166
+ return(internal_apply_operation(self, obj, sizeof(float), SIMD_IntArray, func_neq));
167
+ }
168
+
123
169
  /* Public: Return a Ruby Array containing the doubles within the data array. */
124
170
  static VALUE method_to_a(VALUE self)
125
171
  {
@@ -162,6 +208,15 @@ static void func_subtract(void *v1, void *v2, void *r)
162
208
  *(f4v *)r = *(f4v *)v1 - *(f4v *)v2;
163
209
  }
164
210
 
211
+ /* Function: Compute square root for a vector. */
212
+ static void func_sqrt(void *v1, void *r)
213
+ {
214
+ (*(f4v *)r)[0] = sqrt((*(f4v *)v1)[0]);
215
+ (*(f4v *)r)[1] = sqrt((*(f4v *)v1)[1]);
216
+ (*(f4v *)r)[2] = sqrt((*(f4v *)v1)[2]);
217
+ (*(f4v *)r)[3] = sqrt((*(f4v *)v1)[3]);
218
+ }
219
+
165
220
  /* Function: Perform a binary AND on two vectors. */
166
221
  static void func_and(void *v1, void *v2, void *r)
167
222
  {
@@ -191,3 +246,27 @@ static void func_lt(void *v1, void *v2, void *r)
191
246
  {
192
247
  *(i4v *)r = (*(f4v *)v1 < *(f4v *)v2);
193
248
  }
249
+
250
+ /* Function: Compare vectors, return -1 if v1 is greater than v2, 0 otherwise */
251
+ static void func_gte(void *v1, void *v2, void *r)
252
+ {
253
+ *(i4v *)r = (*(f4v *)v1 >= *(f4v *)v2);
254
+ }
255
+
256
+ /* Function: Compare vectors, return -1 if v1 is less than v2, 0 otherwise */
257
+ static void func_lte(void *v1, void *v2, void *r)
258
+ {
259
+ *(i4v *)r = (*(f4v *)v1 <= *(f4v *)v2);
260
+ }
261
+
262
+ /* Function: Compare vectors, return -1 if v1 is equal to v2, 0 otherwise */
263
+ static void func_eq(void *v1, void *v2, void *r)
264
+ {
265
+ *(i4v *)r = (*(f4v *)v1 == *(f4v *)v2);
266
+ }
267
+
268
+ /* Function: Compare vectors, return 0 if v1 is equal to v2, -1 otherwise */
269
+ static void func_neq(void *v1, void *v2, void *r)
270
+ {
271
+ *(i4v *)r = (*(f4v *)v1 != *(f4v *)v2);
272
+ }
@@ -1,24 +1,36 @@
1
1
  #include "ruby.h"
2
2
  #include "simd_common.h"
3
3
 
4
+ extern VALUE SIMD_SmallFloatArray;
5
+
4
6
  static VALUE method_initialize(VALUE self, VALUE rb_array);
5
7
  static VALUE method_multiply(VALUE self, VALUE obj);
6
8
  static VALUE method_divide(VALUE self, VALUE obj);
7
9
  static VALUE method_add(VALUE self, VALUE obj);
8
10
  static VALUE method_subtract(VALUE self, VALUE obj);
11
+ static VALUE method_sqrt(VALUE self);
9
12
  static VALUE method_and(VALUE self, VALUE obj);
10
13
  static VALUE method_or(VALUE self, VALUE obj);
11
14
  static VALUE method_xor(VALUE self, VALUE obj);
12
15
  static VALUE method_gt(VALUE self, VALUE obj);
13
16
  static VALUE method_lt(VALUE self, VALUE obj);
17
+ static VALUE method_gte(VALUE self, VALUE obj);
18
+ static VALUE method_lte(VALUE self, VALUE obj);
19
+ static VALUE method_eq(VALUE self, VALUE obj);
20
+ static VALUE method_neq(VALUE self, VALUE obj);
14
21
  static VALUE method_to_a(VALUE self);
15
22
 
16
23
  static void func_multiply(void *v1, void *v2, void *r);
17
24
  static void func_divide(void *v1, void *v2, void *r);
18
25
  static void func_add(void *v1, void *v2, void *r);
19
26
  static void func_subtract(void *v1, void *v2, void *r);
27
+ static void func_sqrt(void *v1, void *r);
20
28
  static void func_and(void *v1, void *v2, void *r);
21
29
  static void func_or(void *v1, void *v2, void *r);
22
30
  static void func_xor(void *v1, void *v2, void *r);
23
31
  static void func_gt(void *v1, void *v2, void *r);
24
32
  static void func_lt(void *v1, void *v2, void *r);
33
+ static void func_gte(void *v1, void *v2, void *r);
34
+ static void func_lte(void *v1, void *v2, void *r);
35
+ static void func_eq(void *v1, void *v2, void *r);
36
+ static void func_neq(void *v1, void *v2, void *r);
@@ -54,3 +54,4 @@ typedef struct vector_t
54
54
  } vector_t;
55
55
 
56
56
  typedef void (b_operation)(void *v1, void *v2, void *r);
57
+ typedef void (u_operation)(void *v1, void *r);
metadata CHANGED
@@ -1,29 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tina Wuest
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2022-08-29 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: rake-compiler
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '1.2'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '1.2'
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies: []
27
12
  description: Access to SIMD (Single Instruction Multiple Data) instructions in Ruby
28
13
  email: tina@wuest.me
29
14
  executables: []
@@ -45,10 +30,14 @@ files:
45
30
  - ext/simd/simd_smallfloatarray.c
46
31
  - ext/simd/simd_smallfloatarray.h
47
32
  - ext/simd/simd_types.h
48
- homepage: https://gitlab.com/wuest/simd-ruby
49
- licenses: []
50
- metadata: {}
51
- post_install_message:
33
+ homepage: https://github.com/wuest/simd-ruby
34
+ licenses:
35
+ - MIT
36
+ metadata:
37
+ homepage_uri: https://github.com/wuest/simd-ruby
38
+ source_code_uri: https://github.com/wuest/simd-ruby
39
+ changelog_uri: https://github.com/wuest/simd-ruby/blob/main/CHANGELOG.md
40
+ rubygems_mfa_required: 'true'
52
41
  rdoc_options: []
53
42
  require_paths:
54
43
  - lib
@@ -56,15 +45,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
56
45
  requirements:
57
46
  - - ">="
58
47
  - !ruby/object:Gem::Version
59
- version: '0'
48
+ version: 3.0.0
60
49
  required_rubygems_version: !ruby/object:Gem::Requirement
61
50
  requirements:
62
51
  - - ">="
63
52
  - !ruby/object:Gem::Version
64
53
  version: '0'
65
54
  requirements: []
66
- rubygems_version: 3.3.7
67
- signing_key:
55
+ rubygems_version: 3.6.9
68
56
  specification_version: 4
69
57
  summary: SIMD instructions in ruby
70
58
  test_files: []