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