xref: /freebsd/crypto/openssl/doc/man3/OPENSSL_ia32cap.pod (revision 58f351825a371d1a3dd693d6f64a1245ea851a51)
1e71b7053SJung-uk Kim=pod
2e71b7053SJung-uk Kim
3e71b7053SJung-uk Kim=head1 NAME
4e71b7053SJung-uk Kim
5e71b7053SJung-uk KimOPENSSL_ia32cap - the x86[_64] processor capabilities vector
6e71b7053SJung-uk Kim
7e71b7053SJung-uk Kim=head1 SYNOPSIS
8e71b7053SJung-uk Kim
9e71b7053SJung-uk Kim env OPENSSL_ia32cap=... <application>
10e71b7053SJung-uk Kim
11e71b7053SJung-uk Kim=head1 DESCRIPTION
12e71b7053SJung-uk Kim
13e71b7053SJung-uk KimOpenSSL supports a range of x86[_64] instruction set extensions. These
14e71b7053SJung-uk Kimextensions are denoted by individual bits in capability vector returned
15e71b7053SJung-uk Kimby processor in EDX:ECX register pair after executing CPUID instruction
16e71b7053SJung-uk Kimwith EAX=1 input value (see Intel Application Note #241618). This vector
17e71b7053SJung-uk Kimis copied to memory upon toolkit initialization and used to choose
18e71b7053SJung-uk Kimbetween different code paths to provide optimal performance across wide
19e71b7053SJung-uk Kimrange of processors. For the moment of this writing following bits are
20e71b7053SJung-uk Kimsignificant:
21e71b7053SJung-uk Kim
22e71b7053SJung-uk Kim=over 4
23e71b7053SJung-uk Kim
24e71b7053SJung-uk Kim=item bit #4 denoting presence of Time-Stamp Counter.
25e71b7053SJung-uk Kim
26e71b7053SJung-uk Kim=item bit #19 denoting availability of CLFLUSH instruction;
27e71b7053SJung-uk Kim
28e71b7053SJung-uk Kim=item bit #20, reserved by Intel, is used to choose among RC4 code paths;
29e71b7053SJung-uk Kim
30e71b7053SJung-uk Kim=item bit #23 denoting MMX support;
31e71b7053SJung-uk Kim
32e71b7053SJung-uk Kim=item bit #24, FXSR bit, denoting availability of XMM registers;
33e71b7053SJung-uk Kim
34e71b7053SJung-uk Kim=item bit #25 denoting SSE support;
35e71b7053SJung-uk Kim
36e71b7053SJung-uk Kim=item bit #26 denoting SSE2 support;
37e71b7053SJung-uk Kim
38e71b7053SJung-uk Kim=item bit #28 denoting Hyperthreading, which is used to distinguish
39e71b7053SJung-uk Kimcores with shared cache;
40e71b7053SJung-uk Kim
41e71b7053SJung-uk Kim=item bit #30, reserved by Intel, denotes specifically Intel CPUs;
42e71b7053SJung-uk Kim
43e71b7053SJung-uk Kim=item bit #33 denoting availability of PCLMULQDQ instruction;
44e71b7053SJung-uk Kim
45e71b7053SJung-uk Kim=item bit #41 denoting SSSE3, Supplemental SSE3, support;
46e71b7053SJung-uk Kim
47e71b7053SJung-uk Kim=item bit #43 denoting AMD XOP support (forced to zero on non-AMD CPUs);
48e71b7053SJung-uk Kim
49e71b7053SJung-uk Kim=item bit #54 denoting availability of MOVBE instruction;
50e71b7053SJung-uk Kim
51e71b7053SJung-uk Kim=item bit #57 denoting AES-NI instruction set extension;
52e71b7053SJung-uk Kim
53e71b7053SJung-uk Kim=item bit #58, XSAVE bit, lack of which in combination with MOVBE is used
54e71b7053SJung-uk Kimto identify Atom Silvermont core;
55e71b7053SJung-uk Kim
56e71b7053SJung-uk Kim=item bit #59, OSXSAVE bit, denoting availability of YMM registers;
57e71b7053SJung-uk Kim
58e71b7053SJung-uk Kim=item bit #60 denoting AVX extension;
59e71b7053SJung-uk Kim
60e71b7053SJung-uk Kim=item bit #62 denoting availability of RDRAND instruction;
61e71b7053SJung-uk Kim
62e71b7053SJung-uk Kim=back
63e71b7053SJung-uk Kim
64e71b7053SJung-uk KimFor example, in 32-bit application context clearing bit #26 at run-time
65e71b7053SJung-uk Kimdisables high-performance SSE2 code present in the crypto library, while
66e71b7053SJung-uk Kimclearing bit #24 disables SSE2 code operating on 128-bit XMM register
67e71b7053SJung-uk Kimbank. You might have to do the latter if target OpenSSL application is
68e71b7053SJung-uk Kimexecuted on SSE2 capable CPU, but under control of OS that does not
69e71b7053SJung-uk Kimenable XMM registers. Historically address of the capability vector copy
70e71b7053SJung-uk Kimwas exposed to application through OPENSSL_ia32cap_loc(), but not
71e71b7053SJung-uk Kimanymore. Now the only way to affect the capability detection is to set
72e71b7053SJung-uk KimOPENSSL_ia32cap environment variable prior target application start. To
73e71b7053SJung-uk Kimgive a specific example, on Intel P4 processor 'env
74e71b7053SJung-uk KimOPENSSL_ia32cap=0x16980010 apps/openssl', or better yet 'env
75e71b7053SJung-uk KimOPENSSL_ia32cap=~0x1000000 apps/openssl' would achieve the desired
76e71b7053SJung-uk Kimeffect. Alternatively you can reconfigure the toolkit with no-sse2
77e71b7053SJung-uk Kimoption and recompile.
78e71b7053SJung-uk Kim
79e71b7053SJung-uk KimLess intuitive is clearing bit #28, or ~0x10000000 in the "environment
80e71b7053SJung-uk Kimvariable" terms. The truth is that it's not copied from CPUID output
81e71b7053SJung-uk Kimverbatim, but is adjusted to reflect whether or not the data cache is
82e71b7053SJung-uk Kimactually shared between logical cores. This in turn affects the decision
83e71b7053SJung-uk Kimon whether or not expensive countermeasures against cache-timing attacks
84e71b7053SJung-uk Kimare applied, most notably in AES assembler module.
85e71b7053SJung-uk Kim
86e71b7053SJung-uk KimThe capability vector is further extended with EBX value returned by
87e71b7053SJung-uk KimCPUID with EAX=7 and ECX=0 as input. Following bits are significant:
88e71b7053SJung-uk Kim
89e71b7053SJung-uk Kim=over 4
90e71b7053SJung-uk Kim
91e71b7053SJung-uk Kim=item bit #64+3 denoting availability of BMI1 instructions, e.g. ANDN;
92e71b7053SJung-uk Kim
93e71b7053SJung-uk Kim=item bit #64+5 denoting availability of AVX2 instructions;
94e71b7053SJung-uk Kim
95e71b7053SJung-uk Kim=item bit #64+8 denoting availability of BMI2 instructions, e.g. MULX
96e71b7053SJung-uk Kimand RORX;
97e71b7053SJung-uk Kim
98e71b7053SJung-uk Kim=item bit #64+16 denoting availability of AVX512F extension;
99e71b7053SJung-uk Kim
100e71b7053SJung-uk Kim=item bit #64+18 denoting availability of RDSEED instruction;
101e71b7053SJung-uk Kim
102e71b7053SJung-uk Kim=item bit #64+19 denoting availability of ADCX and ADOX instructions;
103e71b7053SJung-uk Kim
104e71b7053SJung-uk Kim=item bit #64+21 denoting availability of VPMADD52[LH]UQ instructions,
105*58f35182SJung-uk Kimaka AVX512IFMA extension;
106e71b7053SJung-uk Kim
107e71b7053SJung-uk Kim=item bit #64+29 denoting availability of SHA extension;
108e71b7053SJung-uk Kim
109e71b7053SJung-uk Kim=item bit #64+30 denoting availability of AVX512BW extension;
110e71b7053SJung-uk Kim
111e71b7053SJung-uk Kim=item bit #64+31 denoting availability of AVX512VL extension;
112e71b7053SJung-uk Kim
113e71b7053SJung-uk Kim=item bit #64+41 denoting availability of VAES extension;
114e71b7053SJung-uk Kim
115e71b7053SJung-uk Kim=item bit #64+42 denoting availability of VPCLMULQDQ extension;
116e71b7053SJung-uk Kim
117e71b7053SJung-uk Kim=back
118e71b7053SJung-uk Kim
119e71b7053SJung-uk KimTo control this extended capability word use ':' as delimiter when
120e71b7053SJung-uk Kimsetting up OPENSSL_ia32cap environment variable. For example assigning
121e71b7053SJung-uk Kim':~0x20' would disable AVX2 code paths, and ':0' - all post-AVX
122e71b7053SJung-uk Kimextensions.
123e71b7053SJung-uk Kim
124e71b7053SJung-uk KimIt should be noted that whether or not some of the most "fancy"
125e71b7053SJung-uk Kimextension code paths are actually assembled depends on current assembler
126e71b7053SJung-uk Kimversion. Base minimum of AES-NI/PCLMULQDQ, SSSE3 and SHA extension code
127e71b7053SJung-uk Kimpaths are always assembled. Apart from that, minimum assembler version
128e71b7053SJung-uk Kimrequirements are summarized in below table:
129e71b7053SJung-uk Kim
130e71b7053SJung-uk Kim   Extension   | GNU as | nasm   | llvm
131e71b7053SJung-uk Kim   ------------+--------+--------+--------
132e71b7053SJung-uk Kim   AVX         | 2.19   | 2.09   | 3.0
133e71b7053SJung-uk Kim   AVX2        | 2.22   | 2.10   | 3.1
134e71b7053SJung-uk Kim   ADCX/ADOX   | 2.23   | 2.10   | 3.3
135e71b7053SJung-uk Kim   AVX512      | 2.25   | 2.11.8 | see NOTES
136e71b7053SJung-uk Kim   AVX512IFMA  | 2.26   | 2.11.8 | see NOTES
137e71b7053SJung-uk Kim   VAES        | 2.30   | 2.13.3 |
138e71b7053SJung-uk Kim
139e71b7053SJung-uk Kim=head1 NOTES
140e71b7053SJung-uk Kim
141e71b7053SJung-uk KimEven though AVX512 support was implemented in llvm 3.6, compilation of
142e71b7053SJung-uk Kimassembly modules apparently requires explicit -march flag. But then
143e71b7053SJung-uk Kimcompiler generates processor-specific code, which in turn contradicts
144e71b7053SJung-uk Kimthe mere idea of run-time switch execution facilitated by the variable
145e71b7053SJung-uk Kimin question. Till the limitation is lifted, it's possible to work around
146e71b7053SJung-uk Kimthe problem by making build procedure use following script:
147e71b7053SJung-uk Kim
148e71b7053SJung-uk Kim   #!/bin/sh
149e71b7053SJung-uk Kim   exec clang -no-integrated-as "$@"
150e71b7053SJung-uk Kim
151e71b7053SJung-uk Kiminstead of real clang. In which case it doesn't matter which clang
152e71b7053SJung-uk Kimversion is used, as it is GNU assembler version that will be checked.
153e71b7053SJung-uk Kim
154e71b7053SJung-uk Kim=head1 RETURN VALUES
155e71b7053SJung-uk Kim
156e71b7053SJung-uk KimNot available.
157e71b7053SJung-uk Kim
158e71b7053SJung-uk Kim=head1 COPYRIGHT
159e71b7053SJung-uk Kim
160*58f35182SJung-uk KimCopyright 2004-2020 The OpenSSL Project Authors. All Rights Reserved.
161e71b7053SJung-uk Kim
162e71b7053SJung-uk KimLicensed under the OpenSSL license (the "License").  You may not use
163e71b7053SJung-uk Kimthis file except in compliance with the License.  You can obtain a copy
164e71b7053SJung-uk Kimin the file LICENSE in the source distribution or at
165e71b7053SJung-uk KimL<https://www.openssl.org/source/license.html>.
166e71b7053SJung-uk Kim
167e71b7053SJung-uk Kim=cut
168