Article View: comp.sys.sun
Article #6790Example pgm that is 3X slower on SS2 than on SS1+
From: Mark G. Johnson
Date: Sat, 02 Feb 1991 00:41
Date: Sat, 02 Feb 1991 00:41
57 lines
2507 bytes
2507 bytes
Here is a short C program that runs 3 times faster on a SS1+ than on a
SS2. Mesured with /bin/time,
Compiled with SPARCstation 2 SPARCstation 1+
--------------------------------------------------------------------
cc -O prog.c -lm 29.3 user sec 9.5 user sec
/* ************* code follows *************** */
#include <stdio.h>
#include <math.h>
/* compute the first 1000 digits of PI = 4arctan(1) */
main()
{
long d = 4, r = 10000, n = 251, m = 3.322*n*d;
long i, j, k, q;
static long a[3340];
for (i = 0; i <= m; i++) a[i] = 2;
a[m] = 4;
for (i = 1; i <= n; i++) {
q = 0;
for (k = m; k > 0; k--) {
a[k] = a[k]*r+q;
q = a[k]/(2*k+1);
a[k] -= (2*k+1)*q;
q *= k;
}
a[0] = a[0]*r+q;
q = a[0]/r;
a[0] -= q*r;
printf("%04d%s", q, i & 7 ? " " : "\n");
}
}
/* ************* end of code *************** */
The reason for this unexpected slowdown is rather obscure: the subroutines
that implement multiplication and division get placed in a very unlucky
spot in the SS2's cache. In the SS1 they get plopped in a less dangerous
area.
This can be seen by having the compiler and/or the OS move the
multiplication and division subroutines to new positions. Or, by
finagling the *other* subroutines (e.g. fp math) that might get in the way
of the mult and div subroutines. When you do this, the SS2 becomes faster
than the SS1+.
Compiled with SPARCstation 2 SPARCstation 1+
--------------------------------------------------------------------
cc -O prog.c -lm 29.3 user sec 9.5 user sec
cc -O -Bstatic prog.c -lm 5.2 user sec 8.9 user sec
cc -O prog.c 5.5 user sec 9.5 user sec
Mark Johnson
MIPS Computer Systems, 930 E. Arques M/S 2-02, Sunnyvale, CA 94086
(408) 524-8308 mark@mips.com {or ...!decwrl!mips!mark}
Technical Details
Message-ID:
<1548@brchh104.bnr.ca>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!cunews!bnrgate!brtph3!brchh104!brchs1!bnr.ca!rice.edu!sun-spots-requestShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!cunews!bnrgate!brtph3!brchh104!brchs1!bnr.ca!rice.edu!sun-spots-request From: mark@mips.com (Mark G. Johnson) Newsgroups: comp.sys.sun Subject: Example pgm that is 3X slower on SS2 than on SS1+ Keywords: Miscellaneous Message-ID: <1548@brchh104.bnr.ca> Date: 2 Feb 91 00:41:46 GMT Sender: news@brchh104.bnr.ca Organization: Sun-Spots Lines: 57 Approved: Sun-Spots@rice.edu X-Sun-Spots-Digest: Volume 10, Issue 35, message 7 X-Note: Submissions: sun-spots@rice.edu, Admin: sun-spots-request@rice.edu