Issue #14328 has been updated by naruse (Yui NARUSE).


I had tried to use SIMD in some parts.
But its performance improvement is limited.

Of course it can improve performance so much, but it is only in special use cases.
In usual Ruby handles small data and they can't ignore SIMD overhead.

> math operations

Ruby uses GMP if exist.

> sum, min, max, arrays, matrixes

Normal array can store any type.
To use SIMD power, the array should be typed array like NArray.
It's not Ruby itself's issue.

> string manipulations

I tried to use SSE2 for `coderange_scan()` in string.c, but it doesn't improve performance so much.

SSE 4.2 STTNI is also interesting but I don't find a good use case which can pay for increasing code complexity.

----------------------------------------
Feature #14328: SIMD vectorization
https://bugs.ruby-lang.org/issues/14328#change-69545

* Author: ahorek (Pavel Rosick)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
Hello,
in order to make ruby faster, I'd like to propose an optional SIMD optimization for some cases. I want to target SSE2 which is available in all modern x86 processors. (Pentium 4, Athlon 64 and newer).

this is usually automatically handled by GCC during compilation time, but because of dynamic nature of ruby, redefinitions etc. It's very hard to preoptimize it before the actual execution.

## use auto-vectorization provided by JIT ( https://bugs.ruby-lang.org/issues/12589 )
```
GCC can do that, but I'm not sure how reliable and effective it is today

Pros:
we don't have to do anything, let GCC do the job
bigger scope for optimizations

Cons:
slower compilation
```
* gcc docs:
* https://gcc.gnu.org/projects/tree-ssa/vectorization.html

* pypy has this feature implemented for some time now:
* https://morepypy.blogspot.cz/2015/10/pypy-400-released-jit-with-simd.html


## specialize known bottlenecks by hand
```
Pros:
predictable performace
without increased compilation time

Cons:
code complexity
```

unfortunatelly using SIMD isn't for free, there's an overhead, it needs a large data set to be effective. It's useful mainly for math operations, sum, min, max, arrays, matrixes, string manipulations etc. There probably won't be any significant benefit for appliactions like Rails.

what do you think about it?



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>