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