xref: /freebsd/crypto/openssl/doc/man3/OPENSSL_ia32cap.pod (revision b077aed33b7b6aefca7b17ddb250cf521f938613)
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
72*b077aed3SPierre ProncheryB<OPENSSL_ia32cap> environment variable prior target application start. To
73*b077aed3SPierre Proncherygive a specific example, on Intel P4 processor
74*b077aed3SPierre ProncheryC<env OPENSSL_ia32cap=0x16980010 apps/openssl>, or better yet
75*b077aed3SPierre ProncheryC<env OPENSSL_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
100*b077aed3SPierre Pronchery=item bit #64+17 denoting availability of AVX512DQ extension;
101*b077aed3SPierre Pronchery
102e71b7053SJung-uk Kim=item bit #64+18 denoting availability of RDSEED instruction;
103e71b7053SJung-uk Kim
104e71b7053SJung-uk Kim=item bit #64+19 denoting availability of ADCX and ADOX instructions;
105e71b7053SJung-uk Kim
106e71b7053SJung-uk Kim=item bit #64+21 denoting availability of VPMADD52[LH]UQ instructions,
10758f35182SJung-uk Kimaka AVX512IFMA extension;
108e71b7053SJung-uk Kim
109e71b7053SJung-uk Kim=item bit #64+29 denoting availability of SHA extension;
110e71b7053SJung-uk Kim
111e71b7053SJung-uk Kim=item bit #64+30 denoting availability of AVX512BW extension;
112e71b7053SJung-uk Kim
113e71b7053SJung-uk Kim=item bit #64+31 denoting availability of AVX512VL extension;
114e71b7053SJung-uk Kim
115e71b7053SJung-uk Kim=item bit #64+41 denoting availability of VAES extension;
116e71b7053SJung-uk Kim
117e71b7053SJung-uk Kim=item bit #64+42 denoting availability of VPCLMULQDQ extension;
118e71b7053SJung-uk Kim
119e71b7053SJung-uk Kim=back
120e71b7053SJung-uk Kim
121*b077aed3SPierre ProncheryTo control this extended capability word use C<:> as delimiter when
122*b077aed3SPierre Proncherysetting up B<OPENSSL_ia32cap> environment variable. For example assigning
123*b077aed3SPierre ProncheryC<:~0x20> would disable AVX2 code paths, and C<:0> - all post-AVX
124e71b7053SJung-uk Kimextensions.
125e71b7053SJung-uk Kim
126e71b7053SJung-uk Kim=head1 RETURN VALUES
127e71b7053SJung-uk Kim
128e71b7053SJung-uk KimNot available.
129e71b7053SJung-uk Kim
130e71b7053SJung-uk Kim=head1 COPYRIGHT
131e71b7053SJung-uk Kim
132*b077aed3SPierre ProncheryCopyright 2004-2021 The OpenSSL Project Authors. All Rights Reserved.
133e71b7053SJung-uk Kim
134*b077aed3SPierre ProncheryLicensed under the Apache License 2.0 (the "License").  You may not use
135e71b7053SJung-uk Kimthis file except in compliance with the License.  You can obtain a copy
136e71b7053SJung-uk Kimin the file LICENSE in the source distribution or at
137e71b7053SJung-uk KimL<https://www.openssl.org/source/license.html>.
138e71b7053SJung-uk Kim
139e71b7053SJung-uk Kim=cut
140