README revision 1.1.1.2 1 1.1.1.2 mrg Copyright 1996, 1999-2001, 2003 Free Software Foundation, Inc.
2 1.1 mrg
3 1.1 mrg This file is part of the GNU MP Library.
4 1.1 mrg
5 1.1 mrg The GNU MP Library is free software; you can redistribute it and/or modify
6 1.1.1.2 mrg it under the terms of either:
7 1.1.1.2 mrg
8 1.1.1.2 mrg * the GNU Lesser General Public License as published by the Free
9 1.1.1.2 mrg Software Foundation; either version 3 of the License, or (at your
10 1.1.1.2 mrg option) any later version.
11 1.1.1.2 mrg
12 1.1.1.2 mrg or
13 1.1.1.2 mrg
14 1.1.1.2 mrg * the GNU General Public License as published by the Free Software
15 1.1.1.2 mrg Foundation; either version 2 of the License, or (at your option) any
16 1.1.1.2 mrg later version.
17 1.1.1.2 mrg
18 1.1.1.2 mrg or both in parallel, as here.
19 1.1 mrg
20 1.1 mrg The GNU MP Library is distributed in the hope that it will be useful, but
21 1.1 mrg WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
22 1.1.1.2 mrg or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23 1.1.1.2 mrg for more details.
24 1.1 mrg
25 1.1.1.2 mrg You should have received copies of the GNU General Public License and the
26 1.1.1.2 mrg GNU Lesser General Public License along with the GNU MP Library. If not,
27 1.1.1.2 mrg see https://www.gnu.org/licenses/.
28 1.1 mrg
29 1.1 mrg
30 1.1 mrg
31 1.1 mrg
32 1.1 mrg
33 1.1 mrg INTEL PENTIUM P5 MPN SUBROUTINES
34 1.1 mrg
35 1.1 mrg
36 1.1 mrg This directory contains mpn functions optimized for Intel Pentium (P5,P54)
37 1.1 mrg processors. The mmx subdirectory has additional code for Pentium with MMX
38 1.1 mrg (P55).
39 1.1 mrg
40 1.1 mrg
41 1.1 mrg STATUS
42 1.1 mrg
43 1.1 mrg cycles/limb
44 1.1 mrg
45 1.1 mrg mpn_add_n/sub_n 2.375
46 1.1 mrg
47 1.1 mrg mpn_mul_1 12.0
48 1.1 mrg mpn_add/submul_1 14.0
49 1.1 mrg
50 1.1 mrg mpn_mul_basecase 14.2 cycles/crossproduct (approx)
51 1.1 mrg
52 1.1 mrg mpn_sqr_basecase 8 cycles/crossproduct (approx)
53 1.1 mrg or 15.5 cycles/triangleproduct (approx)
54 1.1 mrg
55 1.1 mrg mpn_l/rshift 5.375 normal (6.0 on P54)
56 1.1 mrg 1.875 special shift by 1 bit
57 1.1 mrg
58 1.1 mrg mpn_divrem_1 44.0
59 1.1 mrg mpn_mod_1 28.0
60 1.1 mrg mpn_divexact_by3 15.0
61 1.1 mrg
62 1.1 mrg mpn_copyi/copyd 1.0
63 1.1 mrg
64 1.1 mrg Pentium MMX gets the following improvements
65 1.1 mrg
66 1.1 mrg mpn_l/rshift 1.75
67 1.1 mrg
68 1.1 mrg mpn_mul_1 12.0 normal, 7.0 for 16-bit multiplier
69 1.1 mrg
70 1.1 mrg
71 1.1 mrg mpn_add_n and mpn_sub_n run at asymptotically 2 cycles/limb. Due to loop
72 1.1 mrg overhead and other delays (cache refill?), they run at or near 2.5
73 1.1 mrg cycles/limb.
74 1.1 mrg
75 1.1 mrg mpn_mul_1, mpn_addmul_1, mpn_submul_1 all run 1 cycle faster than they
76 1.1 mrg should. Intel documentation says a mul instruction is 10 cycles, but it
77 1.1 mrg measures 9 and the routines using it run as 9.
78 1.1 mrg
79 1.1 mrg
80 1.1 mrg
81 1.1 mrg P55 MMX AND X87
82 1.1 mrg
83 1.1 mrg The cost of switching between MMX and x87 floating point on P55 is about 100
84 1.1 mrg cycles (fld1/por/emms for instance). In order to avoid that the two aren't
85 1.1 mrg mixed and currently that means using MMX and not x87.
86 1.1 mrg
87 1.1 mrg MMX offers a big speedup for lshift and rshift, and a nice speedup for
88 1.1 mrg 16-bit multipliers in mpn_mul_1. If fast code using x87 is found then
89 1.1 mrg perhaps the preference for MMX will be reversed.
90 1.1 mrg
91 1.1 mrg
92 1.1 mrg
93 1.1 mrg
94 1.1 mrg P54 SHLDL
95 1.1 mrg
96 1.1 mrg mpn_lshift and mpn_rshift run at about 6 cycles/limb on P5 and P54, but the
97 1.1 mrg documentation indicates that they should take only 43/8 = 5.375 cycles/limb,
98 1.1 mrg or 5 cycles/limb asymptotically. The P55 runs them at the expected speed.
99 1.1 mrg
100 1.1 mrg It seems that on P54 a shldl or shrdl allows pairing in one following cycle,
101 1.1 mrg but not two. For example, back to back repetitions of the following
102 1.1 mrg
103 1.1 mrg shldl( %cl, %eax, %ebx)
104 1.1 mrg xorl %edx, %edx
105 1.1 mrg xorl %esi, %esi
106 1.1 mrg
107 1.1 mrg run at 5 cycles, as expected, but repetitions of the following run at 7
108 1.1 mrg cycles, whereas 6 would be expected (and is achieved on P55),
109 1.1 mrg
110 1.1 mrg shldl( %cl, %eax, %ebx)
111 1.1 mrg xorl %edx, %edx
112 1.1 mrg xorl %esi, %esi
113 1.1 mrg xorl %edi, %edi
114 1.1 mrg xorl %ebp, %ebp
115 1.1 mrg
116 1.1 mrg Three xorls run at 7 cycles too, so it doesn't seem to be just that pairing
117 1.1 mrg inhibited is only in the second following cycle (or something like that).
118 1.1 mrg
119 1.1 mrg Avoiding this problem would bring P54 shifts down from 6.0 c/l to 5.5 with a
120 1.1 mrg pattern of shift, 2 loads, shift, 2 stores, shift, etc. A start has been
121 1.1 mrg made on something like that, but it's not yet complete.
122 1.1 mrg
123 1.1 mrg
124 1.1 mrg
125 1.1 mrg
126 1.1 mrg OTHER NOTES
127 1.1 mrg
128 1.1 mrg Prefetching Destinations
129 1.1 mrg
130 1.1 mrg Pentium doesn't allocate cache lines on writes, unlike most other modern
131 1.1 mrg processors. Since the functions in the mpn class do array writes, we
132 1.1 mrg have to handle allocating the destination cache lines by reading a word
133 1.1 mrg from it in the loops, to achieve the best performance.
134 1.1 mrg
135 1.1 mrg Prefetching Sources
136 1.1 mrg
137 1.1 mrg Prefetching of sources is pointless since there's no out-of-order loads.
138 1.1 mrg Any load instruction blocks until the line is brought to L1, so it may
139 1.1 mrg as well be the load that wants the data which blocks.
140 1.1 mrg
141 1.1 mrg Data Cache Bank Clashes
142 1.1 mrg
143 1.1 mrg Pairing of memory operations requires that the two issued operations
144 1.1 mrg refer to different cache banks (ie. different addresses modulo 32
145 1.1 mrg bytes). The simplest way to ensure this is to read/write two words from
146 1.1 mrg the same object. If we make operations on different objects, they might
147 1.1 mrg or might not be to the same cache bank.
148 1.1 mrg
149 1.1 mrg PIC %eip Fetching
150 1.1 mrg
151 1.1 mrg A simple call $+5 and popl can be used to get %eip, there's no need to
152 1.1 mrg balance calls and returns since P5 doesn't have any return stack branch
153 1.1 mrg prediction.
154 1.1 mrg
155 1.1 mrg Float Multiplies
156 1.1 mrg
157 1.1 mrg fmul is pairable and can be issued every 2 cycles (with a 4 cycle
158 1.1 mrg latency for data ready to use). This is a lot better than integer mull
159 1.1 mrg or imull at 9 cycles non-pairing. Unfortunately the advantage is
160 1.1 mrg quickly eaten away by needing to throw data through memory back to the
161 1.1 mrg integer registers to adjust for fild and fist being signed, and to do
162 1.1 mrg things like propagating carry bits.
163 1.1 mrg
164 1.1 mrg
165 1.1 mrg
166 1.1 mrg
167 1.1 mrg
168 1.1 mrg REFERENCES
169 1.1 mrg
170 1.1 mrg "Intel Architecture Optimization Manual", 1997, order number 242816. This
171 1.1 mrg is mostly about P5, the parts about P6 aren't relevant. Available on-line:
172 1.1 mrg
173 1.1 mrg http://download.intel.com/design/PentiumII/manuals/242816.htm
174 1.1 mrg
175 1.1 mrg
176 1.1 mrg
177 1.1 mrg ----------------
178 1.1 mrg Local variables:
179 1.1 mrg mode: text
180 1.1 mrg fill-column: 76
181 1.1 mrg End:
182