From a9700525d81a1232feac695328be6ea47625f8dd Mon Sep 17 00:00:00 2001 From: Andreas Schulz Date: Sat, 7 Jan 1995 17:26:35 +0000 Subject: Work around a compiler bug in gcc2.6.3 in handling (long long) variables and shifting. Also correct the original code as Garrett noticed it in mail. Leave the mishandled code in to use it later if future versions of gcc are correct. The code was part of the calibrate_cyclecounter routine to get the speed of the pentium chip. --- sys/amd64/amd64/tsc.c | 27 ++++++++++++++++++++++++--- sys/amd64/isa/clock.c | 27 ++++++++++++++++++++++++--- sys/i386/i386/tsc.c | 27 ++++++++++++++++++++++++--- sys/i386/isa/clock.c | 27 ++++++++++++++++++++++++--- sys/isa/atrtc.c | 27 ++++++++++++++++++++++++--- 5 files changed, 120 insertions(+), 15 deletions(-) (limited to 'sys') diff --git a/sys/amd64/amd64/tsc.c b/sys/amd64/amd64/tsc.c index c865514fdcb0..95bef69e2715 100644 --- a/sys/amd64/amd64/tsc.c +++ b/sys/amd64/amd64/tsc.c @@ -34,7 +34,7 @@ * SUCH DAMAGE. * * from: @(#)clock.c 7.2 (Berkeley) 5/12/91 - * $Id: clock.c,v 1.28 1994/11/12 16:24:54 ache Exp $ + * $Id: clock.c,v 1.29 1994/12/30 12:43:34 bde Exp $ */ /* @@ -292,9 +292,30 @@ calibrate_cyclecounter(void) * This assumes that you will never have a clock rate higher * than 4GHz, probably a good assumption. */ - cycles_per_sec = (long long)edx + eax; - cycles_per_sec -= (long long)lastedx + lasteax; + /* The following C code is correct, but our current gcc 2.6.3 + * seems to produce bad assembly code for it , ATS , XXXX */ +#if 0 + cycles_per_sec = ((long long)edx << 32) + eax; + cycles_per_sec -= ((long long)lastedx << 32) + lasteax; pentium_mhz = ((long)cycles_per_sec + 500000) / 1000000; /* round up */ +#else + /* produce a workaround for the code above */ + { + union { + long long extralong; + long shorty[2]; + } tmp; + + tmp.shorty[0] = eax; + tmp.shorty[1] = edx; + cycles_per_sec = tmp.extralong; + tmp.shorty[0] = lasteax; + tmp.shorty[1] = lastedx; + cycles_per_sec -= tmp.extralong; + /* round up */ + pentium_mhz = (long) ((cycles_per_sec + 500000) / 1000000); + } +#endif } #endif diff --git a/sys/amd64/isa/clock.c b/sys/amd64/isa/clock.c index c865514fdcb0..95bef69e2715 100644 --- a/sys/amd64/isa/clock.c +++ b/sys/amd64/isa/clock.c @@ -34,7 +34,7 @@ * SUCH DAMAGE. * * from: @(#)clock.c 7.2 (Berkeley) 5/12/91 - * $Id: clock.c,v 1.28 1994/11/12 16:24:54 ache Exp $ + * $Id: clock.c,v 1.29 1994/12/30 12:43:34 bde Exp $ */ /* @@ -292,9 +292,30 @@ calibrate_cyclecounter(void) * This assumes that you will never have a clock rate higher * than 4GHz, probably a good assumption. */ - cycles_per_sec = (long long)edx + eax; - cycles_per_sec -= (long long)lastedx + lasteax; + /* The following C code is correct, but our current gcc 2.6.3 + * seems to produce bad assembly code for it , ATS , XXXX */ +#if 0 + cycles_per_sec = ((long long)edx << 32) + eax; + cycles_per_sec -= ((long long)lastedx << 32) + lasteax; pentium_mhz = ((long)cycles_per_sec + 500000) / 1000000; /* round up */ +#else + /* produce a workaround for the code above */ + { + union { + long long extralong; + long shorty[2]; + } tmp; + + tmp.shorty[0] = eax; + tmp.shorty[1] = edx; + cycles_per_sec = tmp.extralong; + tmp.shorty[0] = lasteax; + tmp.shorty[1] = lastedx; + cycles_per_sec -= tmp.extralong; + /* round up */ + pentium_mhz = (long) ((cycles_per_sec + 500000) / 1000000); + } +#endif } #endif diff --git a/sys/i386/i386/tsc.c b/sys/i386/i386/tsc.c index c865514fdcb0..95bef69e2715 100644 --- a/sys/i386/i386/tsc.c +++ b/sys/i386/i386/tsc.c @@ -34,7 +34,7 @@ * SUCH DAMAGE. * * from: @(#)clock.c 7.2 (Berkeley) 5/12/91 - * $Id: clock.c,v 1.28 1994/11/12 16:24:54 ache Exp $ + * $Id: clock.c,v 1.29 1994/12/30 12:43:34 bde Exp $ */ /* @@ -292,9 +292,30 @@ calibrate_cyclecounter(void) * This assumes that you will never have a clock rate higher * than 4GHz, probably a good assumption. */ - cycles_per_sec = (long long)edx + eax; - cycles_per_sec -= (long long)lastedx + lasteax; + /* The following C code is correct, but our current gcc 2.6.3 + * seems to produce bad assembly code for it , ATS , XXXX */ +#if 0 + cycles_per_sec = ((long long)edx << 32) + eax; + cycles_per_sec -= ((long long)lastedx << 32) + lasteax; pentium_mhz = ((long)cycles_per_sec + 500000) / 1000000; /* round up */ +#else + /* produce a workaround for the code above */ + { + union { + long long extralong; + long shorty[2]; + } tmp; + + tmp.shorty[0] = eax; + tmp.shorty[1] = edx; + cycles_per_sec = tmp.extralong; + tmp.shorty[0] = lasteax; + tmp.shorty[1] = lastedx; + cycles_per_sec -= tmp.extralong; + /* round up */ + pentium_mhz = (long) ((cycles_per_sec + 500000) / 1000000); + } +#endif } #endif diff --git a/sys/i386/isa/clock.c b/sys/i386/isa/clock.c index c865514fdcb0..95bef69e2715 100644 --- a/sys/i386/isa/clock.c +++ b/sys/i386/isa/clock.c @@ -34,7 +34,7 @@ * SUCH DAMAGE. * * from: @(#)clock.c 7.2 (Berkeley) 5/12/91 - * $Id: clock.c,v 1.28 1994/11/12 16:24:54 ache Exp $ + * $Id: clock.c,v 1.29 1994/12/30 12:43:34 bde Exp $ */ /* @@ -292,9 +292,30 @@ calibrate_cyclecounter(void) * This assumes that you will never have a clock rate higher * than 4GHz, probably a good assumption. */ - cycles_per_sec = (long long)edx + eax; - cycles_per_sec -= (long long)lastedx + lasteax; + /* The following C code is correct, but our current gcc 2.6.3 + * seems to produce bad assembly code for it , ATS , XXXX */ +#if 0 + cycles_per_sec = ((long long)edx << 32) + eax; + cycles_per_sec -= ((long long)lastedx << 32) + lasteax; pentium_mhz = ((long)cycles_per_sec + 500000) / 1000000; /* round up */ +#else + /* produce a workaround for the code above */ + { + union { + long long extralong; + long shorty[2]; + } tmp; + + tmp.shorty[0] = eax; + tmp.shorty[1] = edx; + cycles_per_sec = tmp.extralong; + tmp.shorty[0] = lasteax; + tmp.shorty[1] = lastedx; + cycles_per_sec -= tmp.extralong; + /* round up */ + pentium_mhz = (long) ((cycles_per_sec + 500000) / 1000000); + } +#endif } #endif diff --git a/sys/isa/atrtc.c b/sys/isa/atrtc.c index c865514fdcb0..95bef69e2715 100644 --- a/sys/isa/atrtc.c +++ b/sys/isa/atrtc.c @@ -34,7 +34,7 @@ * SUCH DAMAGE. * * from: @(#)clock.c 7.2 (Berkeley) 5/12/91 - * $Id: clock.c,v 1.28 1994/11/12 16:24:54 ache Exp $ + * $Id: clock.c,v 1.29 1994/12/30 12:43:34 bde Exp $ */ /* @@ -292,9 +292,30 @@ calibrate_cyclecounter(void) * This assumes that you will never have a clock rate higher * than 4GHz, probably a good assumption. */ - cycles_per_sec = (long long)edx + eax; - cycles_per_sec -= (long long)lastedx + lasteax; + /* The following C code is correct, but our current gcc 2.6.3 + * seems to produce bad assembly code for it , ATS , XXXX */ +#if 0 + cycles_per_sec = ((long long)edx << 32) + eax; + cycles_per_sec -= ((long long)lastedx << 32) + lasteax; pentium_mhz = ((long)cycles_per_sec + 500000) / 1000000; /* round up */ +#else + /* produce a workaround for the code above */ + { + union { + long long extralong; + long shorty[2]; + } tmp; + + tmp.shorty[0] = eax; + tmp.shorty[1] = edx; + cycles_per_sec = tmp.extralong; + tmp.shorty[0] = lasteax; + tmp.shorty[1] = lastedx; + cycles_per_sec -= tmp.extralong; + /* round up */ + pentium_mhz = (long) ((cycles_per_sec + 500000) / 1000000); + } +#endif } #endif -- cgit v1.3