From: jean.boussier@... Date: 2020-01-10T14:36:33+00:00 Subject: [ruby-core:96766] [Ruby master Misc#16487] Potential for SIMD usage in ruby-core Issue #16487 has been updated by byroot (Jean Boussier). Just to confirm, `__attribute__(target(""))` is how PHP does it: - https://github.com/php/php-src/blob/7ce531f2c28dcfe4aeed271b55b82de65c3bca8a/ext/standard/base64.c#L370-L371 - https://github.com/php/php-src/blob/7ce531f2c28dcfe4aeed271b55b82de65c3bca8a/Zend/zend_portability.h#L592 In the end there's indeed quite a bit of ceremonial code with a significative amount of extra `#ifdef`, but IMHO it's tolerable, and could probably be reduced with some macros. > I'm more worried about code bloat, having many functions (c, sse2, avx2 version etc...) to solve the same problem isn't DRY. It would probably be limited to a few hotpaths though. I might be wrong, but I don't see it used beside a select few string functions. ---------------------------------------- Misc #16487: Potential for SIMD usage in ruby-core https://bugs.ruby-lang.org/issues/16487#change-83760 * Author: byroot (Jean Boussier) * Status: Open * Priority: Normal * Assignee: ---------------------------------------- ### Context There are several ruby core methods that could be optimized with the use of SIMD instructions. I experimented a bit on `coderange_scan` https://github.com/Shopify/ruby/pull/2, and Pavel Rosick� experimented on `String#strip` https://github.com/ruby/ruby/pull/2815. ### Problem The downside of SIMD instructions is that they are not universally available. So it means maintaining several versions of the same code, and switching them either statically or dynamically. And since most Ruby users use precompiled binaries from repositories and such, it would need to be dynamic if we want most users to benefit from it. So it's not exactly "free speed", as it means a complexified codebase. ### Question So the question is to know wether ruby-core is open to patches using SIMD instructions ? And if so under which conditions. cc @shyouhei -- https://bugs.ruby-lang.org/ Unsubscribe: