blob: 4c1e93bf44c31666ae05d4c234e817e9283fd31a (
about) (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# Trying simd stuff. Compile with:
#
# nim --path:contrib/nimsimd/src c simd && ./simd
# nim --path:contrib/nimsimd/src -c -d:release c simd && ./simd
when defined(gcc) or defined(clang):
{.localPassc: "-mavx".}
import nimsimd/avx2
echo "TESTING AVX"
# SIMD floating point multiplication
let
a = mm_set1_ps(1.0) # Vector of 4 float32 each with value 1.0
b = mm_set1_ps(2.0) # Vector of 4 float32 each with value 2.0
c = mm_mul_ps(a, b) # SIMD vector multiplication operator
# Cast the vector to echo as separate float32 values
echo cast[array[4, float32]](c)
var l1 = [1.0, 2.1, 3.2, 4.3]
var l2 = [0.0, 1.1, 2.1, 3.3]
var regs1 = mm256_loadu_pd(l1[0].addr)
var regs2 = mm256_loadu_pd(l2[0].addr)
var result = mm256_sub_pd(regs1,regs2)
echo cast[array[4, float64]](result)
|