Debian Codegraph @

rpython/doc/jit/vectorization.rst

raw
1
2 Vectorization
3 =============
4
5 To find parallel instructions the tracer must provide enough information about
6 memory load/store operations. They must be adjacent in memory. The requirement for
7 that is that they use the same index variable and offset can be expressed as a
8 a linear or affine combination.
9
10 Command line flags:
11
12 * --jit vec=1: turns on the vectorization for marked jitdrivers
13 (e.g. those in the NumPyPy module).
14 * --jit vec_all=1: turns on the vectorization for any jit driver. See parameters for
15 the filtering heuristics of traces.
16
17 Features
18 --------
19
20 Currently the following operations can be vectorized if the trace contains parallel operations:
21
22 * float32/float64: add, subtract, multiply, divide, negate, absolute
23 * int8/int16/int32/int64 arithmetic: add, subtract, multiply, negate, absolute
24 * int8/int16/int32/int64 logical: and, or, xor
25
26 Reduction
27 ---------
28
29 Reduction is implemented:
30
31 * sum, prod, any, all
32
33 Constant & Variable Expansion
34 -----------------------------
35
36 Packed arithmetic operations expand scalar variables or constants into vector registers.
37
38 Guard Strengthening
39 -------------------
40
41 Unrolled guards are strengthend on an arithmetical level (See GuardStrengthenOpt).
42 The resulting vector trace will only have one guard that checks the index.
43
44 Calculations on the index variable that are redundant (because of the merged
45 load/store instructions) are not removed. The backend removes these instructions
46 while assembling the trace.
47
48 In addition a simple heuristic (enabled by --jit vec_all=1) tries to remove
49 array bound checks for application level loops. It tries to identify the array
50 bound checks and adds a transitive guard at the top of the loop::
51
52 label(...)
53 ...
54 guard(i < n) # index guard
55 ...
56 guard(i < len(a))
57 a = load(..., i, ...)
58 ...
59 jump(...)
60 # becomes
61 guard(n < len(a))
62 label(...)
63 guard(i < n) # index guard
64 ...
65 a = load(..., i, ...)
66 ...
67 jump(...)
68
69
70
71 Future Work and Limitations
72 ---------------------------
73
74 * The only SIMD instruction architecture currently supported is SSE4.1
75 * Packed mul for int8,int64 (see PMUL_). It would be possible to use PCLMULQDQ. Only supported
76 by some CPUs and must be checked in the cpuid.
77 * Loop that convert types from int(8|16|32|64) to int(8|16) are not supported in
78 the current SSE4.1 assembler implementation.
79 The opcode needed spans over multiple instructions. In terms of performance
80 there might only be little to non advantage to use SIMD instructions for this
81 conversions.
82 * For a guard that checks true/false on a vector integer register, it would be handy
83 to have 2 xmm registers (one filled with zero bits and the other with one every bit).
84 This cuts down 2 instructions for guard checking, trading for higher register pressure.
85 * prod, sum are only supported by 64 bit data types
86 * isomorphic function prevents the following cases for combination into a pair:
87 1) getarrayitem_gc, getarrayitem_gc_pure
88 2) int_add(v,1), int_sub(v,-1)
89
90 .. _PMUL: http://stackoverflow.com/questions/8866973/can-long-integer-routines-benefit-from-sse/8867025#8867025
91