471
471
end
472
472
y
473
473
end
474
-
474
+
475
475
Timing results::
476
476
477
477
julia> @time loopinc()
@@ -546,8 +546,8 @@ properties.
546
546
Be certain before doing this. If the subscripts are ever out of bounds,
547
547
you may suffer crashes or silent corruption.
548
548
- Write ``@simd `` in front of ``for `` loops that are amenable to vectorization.
549
- **This feature is experimental ** and could change or disappear in future
550
- versions of Julia.
549
+ **This feature is experimental ** and could change or disappear in future
550
+ versions of Julia.
551
551
552
552
Here is an example with both forms of markup::
553
553
@@ -566,7 +566,7 @@ Here is an example with both forms of markup::
566
566
end
567
567
s
568
568
end
569
-
569
+
570
570
function timeit( n, reps )
571
571
x = rand(Float32,n)
572
572
y = rand(Float32,n)
@@ -599,26 +599,27 @@ properties of the loop:
599
599
possibly causing different results than without ``@simd ``.
600
600
- No iteration ever waits on another iteration to make forward progress.
601
601
602
- A loop containing ``break ``, ``continue ``, or ``goto `` will cause a
602
+ A loop containing ``break ``, ``continue ``, or ``goto `` will cause a
603
603
compile-time error.
604
604
605
- Using ``@simd `` merely gives the compiler license to vectorize. Whether
606
- it actually does so depends on the compiler. To actually benefit from the
607
- current implementation, your loop should have the following additional
605
+ Using ``@simd `` merely gives the compiler license to vectorize. Whether
606
+ it actually does so depends on the compiler. To actually benefit from the
607
+ current implementation, your loop should have the following additional
608
608
properties:
609
609
610
610
- The loop must be an innermost loop.
611
- - The loop body must be straight-line code. This is why ``@inbounds `` is
611
+ - The loop body must be straight-line code. This is why ``@inbounds `` is
612
612
currently needed for all array accesses. The compiler can sometimes turn
613
- short ``&& ``, ``|| ``, and ``?: `` expressions into straight-line code,
614
- if it is safe to evaluate all operands unconditionally. Consider using
613
+ short ``&& ``, ``|| ``, and ``?: `` expressions into straight-line code,
614
+ if it is safe to evaluate all operands unconditionally. Consider using
615
615
``ifelse `` instead of ``?: `` in the loop if it is safe to do so.
616
- - Accesses must have a stride pattern and cannot be "gathers" (random-index reads)
616
+ - Accesses must have a stride pattern and cannot be "gathers" (random-index reads)
617
617
or "scatters" (random-index writes).
618
618
- The stride should be unit stride.
619
- - In some simple cases, for example with 2-3 arrays accessed in a loop, the
620
- LLVM auto-vectorization may kick in automatically, leading to no further
621
- speedup with ``@simd ``.
619
+ - In some simple cases, for example with 2-3 arrays accessed in a loop, the
620
+ LLVM auto-vectorization may kick in automatically, leading to no further
621
+ speedup with ``@simd ``.
622
+
622
623
.. raw :: html
623
624
<style > .red {color :red } </style >
624
625
0 commit comments