simd 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/ext/simd/extconf.rb +6 -0
- data/ext/simd/simd.c +8 -0
- data/ext/simd/simd.h +4 -0
- data/ext/simd/simd_floatarray.c +92 -0
- data/ext/simd/simd_floatarray.h +22 -0
- metadata +62 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 11df730f8e1819314d0c0cdf188b24a01e0939cf
|
4
|
+
data.tar.gz: 35be81c3b191dc4b12d587145535813aef3c2e5b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1d02246e5e09becf5f301803cc97a6756a93ae8d6d7858b0218adca7d688573892bbd7e83325c277dee65663e5168f570d8f220d75fa7c81098a8b9d490b8370
|
7
|
+
data.tar.gz: bdd5f50f1e590f839a3067761ad0c865b831e3e97002f2155168f943e9b1258e5f0cc95e6b9481074954865e09c99e2e28ceaeb19480184e4ddf4b9a58b406db
|
data/ext/simd/extconf.rb
ADDED
data/ext/simd/simd.c
ADDED
data/ext/simd/simd.h
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
#include "simd_floatarray.h"
|
2
|
+
|
3
|
+
VALUE SIMD_FloatArray = Qnil;
|
4
|
+
|
5
|
+
void Init_SIMD_FloatArray(VALUE parent)
|
6
|
+
{
|
7
|
+
SIMD_FloatArray = rb_define_class_under(parent, "FloatArray", rb_cObject);
|
8
|
+
rb_define_alloc_func(SIMD_FloatArray, allocate);
|
9
|
+
rb_define_method(SIMD_FloatArray, "initialize", method_initialize, 1);
|
10
|
+
rb_define_method(SIMD_FloatArray, "*", method_multiply, 1);
|
11
|
+
rb_define_method(SIMD_FloatArray, "length", method_length, 0);
|
12
|
+
rb_define_method(SIMD_FloatArray, "to_a", method_to_a, 0);
|
13
|
+
}
|
14
|
+
|
15
|
+
static VALUE allocate(VALUE klass)
|
16
|
+
{
|
17
|
+
double_vector_wrapper *vector = malloc(sizeof(double_vector_wrapper));
|
18
|
+
vector->data = NULL;
|
19
|
+
|
20
|
+
return(Data_Wrap_Struct(klass, NULL, deallocate, vector));
|
21
|
+
}
|
22
|
+
|
23
|
+
static void deallocate(double_vector_wrapper *vector)
|
24
|
+
{
|
25
|
+
free(vector);
|
26
|
+
}
|
27
|
+
|
28
|
+
static VALUE method_initialize(VALUE self, VALUE rb_array)
|
29
|
+
{
|
30
|
+
double_vector_wrapper *vector;
|
31
|
+
long n,m,i;
|
32
|
+
|
33
|
+
Check_Type(rb_array, T_ARRAY);
|
34
|
+
|
35
|
+
Data_Get_Struct(self, double_vector_wrapper, vector);
|
36
|
+
vector->len = n = RARRAY_LEN(rb_array);
|
37
|
+
m = n + (n % 2);
|
38
|
+
vector->data = malloc(((m / 2) * sizeof(d2v_t)));
|
39
|
+
|
40
|
+
for(i = 0; i < n; i++)
|
41
|
+
vector->data[i/2].f[i%2] = NUM2DBL(rb_ary_entry(rb_array, i));
|
42
|
+
|
43
|
+
if(n < m)
|
44
|
+
vector->data[m/2].f[1] = 1.0;
|
45
|
+
|
46
|
+
return(self);
|
47
|
+
}
|
48
|
+
|
49
|
+
static VALUE method_multiply(VALUE self, VALUE obj)
|
50
|
+
{
|
51
|
+
long size, i;
|
52
|
+
double_vector_wrapper *vector, *vector2, *result;
|
53
|
+
|
54
|
+
Data_Get_Struct(self, double_vector_wrapper, vector);
|
55
|
+
Data_Get_Struct(obj, double_vector_wrapper, vector2);
|
56
|
+
|
57
|
+
if(vector->len != vector2->len && vector2->len != 2)
|
58
|
+
rb_raise(rb_eArgError, "Vectors must be the same size, or 2.");
|
59
|
+
|
60
|
+
size = vector->len + (vector->len % 2);
|
61
|
+
result = malloc(sizeof(double_vector_wrapper));
|
62
|
+
result->data = malloc(size * sizeof(d2v_t));
|
63
|
+
result->len = vector->len;
|
64
|
+
|
65
|
+
for(i = 0; i < size / 2; i++)
|
66
|
+
result->data[i].v = vector->data[i].v * vector2->data[i].v;
|
67
|
+
|
68
|
+
return(Data_Wrap_Struct(SIMD_FloatArray, NULL, deallocate, result));
|
69
|
+
}
|
70
|
+
|
71
|
+
static VALUE method_length(VALUE self)
|
72
|
+
{
|
73
|
+
double_vector_wrapper *vector;
|
74
|
+
Data_Get_Struct(self, double_vector_wrapper, vector);
|
75
|
+
|
76
|
+
return(INT2NUM(vector->len));
|
77
|
+
}
|
78
|
+
|
79
|
+
static VALUE method_to_a(VALUE self)
|
80
|
+
{
|
81
|
+
long i;
|
82
|
+
double_vector_wrapper *vector;
|
83
|
+
VALUE rb_array = rb_ary_new();
|
84
|
+
|
85
|
+
Data_Get_Struct(self, double_vector_wrapper, vector);
|
86
|
+
for(i = 0; i < vector->len; i++)
|
87
|
+
{
|
88
|
+
rb_ary_store(rb_array, i, DBL2NUM(vector->data[i/2].f[i%2]));
|
89
|
+
}
|
90
|
+
|
91
|
+
return(rb_array);
|
92
|
+
}
|
@@ -0,0 +1,22 @@
|
|
1
|
+
#include "ruby.h"
|
2
|
+
|
3
|
+
typedef double __attribute__ ((vector_size (16))) v2d;
|
4
|
+
typedef union d2v_t
|
5
|
+
{
|
6
|
+
v2d v;
|
7
|
+
double f[2];
|
8
|
+
} d2v_t;
|
9
|
+
|
10
|
+
typedef struct double_vector_wrapper
|
11
|
+
{
|
12
|
+
d2v_t *data;
|
13
|
+
long len;
|
14
|
+
} double_vector_wrapper;
|
15
|
+
|
16
|
+
static VALUE allocate(VALUE klass);
|
17
|
+
static void deallocate(double_vector_wrapper *floatarray);
|
18
|
+
|
19
|
+
static VALUE method_initialize(VALUE self, VALUE rb_array);
|
20
|
+
static VALUE method_multiply(VALUE self, VALUE obj);
|
21
|
+
static VALUE method_length(VALUE self);
|
22
|
+
static VALUE method_to_a(VALUE self);
|
metadata
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: simd
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tina Wuest
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-12-09 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: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: Access to SIMD (Single Instruction Multiple Data) instructions in Ruby
|
28
|
+
email: tina@wuest.me
|
29
|
+
executables: []
|
30
|
+
extensions:
|
31
|
+
- ext/simd/extconf.rb
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- ext/simd/extconf.rb
|
35
|
+
- ext/simd/simd.c
|
36
|
+
- ext/simd/simd.h
|
37
|
+
- ext/simd/simd_floatarray.c
|
38
|
+
- ext/simd/simd_floatarray.h
|
39
|
+
homepage: https://gitlab.com/wuest/simd-ruby
|
40
|
+
licenses: []
|
41
|
+
metadata: {}
|
42
|
+
post_install_message:
|
43
|
+
rdoc_options: []
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
51
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
requirements: []
|
57
|
+
rubyforge_project:
|
58
|
+
rubygems_version: 2.4.4
|
59
|
+
signing_key:
|
60
|
+
specification_version: 4
|
61
|
+
summary: SIMD instructions in ruby
|
62
|
+
test_files: []
|