From owner-freebsd-current Wed Nov 25 13:06:03 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id NAA11115 for freebsd-current-outgoing; Wed, 25 Nov 1998 13:06:03 -0800 (PST) (envelope-from owner-freebsd-current@FreeBSD.ORG) Received: from ns.mt.sri.com (sri-gw.MT.net [206.127.105.141]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id NAA11002 for ; Wed, 25 Nov 1998 13:05:46 -0800 (PST) (envelope-from nate@mt.sri.com) Received: from mt.sri.com (rocky.mt.sri.com [206.127.76.100]) by ns.mt.sri.com (8.8.8/8.8.8) with SMTP id OAA09783 for ; Wed, 25 Nov 1998 14:05:42 -0700 (MST) (envelope-from nate@rocky.mt.sri.com) Received: by mt.sri.com (SMI-8.6/SMI-SVR4) id OAA10347; Wed, 25 Nov 1998 14:05:41 -0700 Date: Wed, 25 Nov 1998 14:05:41 -0700 Message-Id: <199811252105.OAA10347@mt.sri.com> From: Nate Williams MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: Nate Williams Cc: current@FreeBSD.ORG Subject: Re: FWD: src/lib/libc/quad/moddi3.c broken! In-Reply-To: <199811252038.NAA10234@mt.sri.com> References: <199811252038.NAA10234@mt.sri.com> X-Mailer: VM 6.34 under 19.16 "Lille" XEmacs Lucid Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG > Keith White just fixed a bug in the JDK that turned out to be a bug in > the libc source code. It's not normally seen because the version in > libgcc.a works, and is used before the libc version. ...... > The version in /usr/src/lib/libc/quad/moddi3.c looked a > little suspicious. To verify the problem, I built the following test > program: > > --- > main() { > long long a, b, c, d; > a = -12L; b = -5L; > c = a % b; > d = a - (a / b) * b; > > printf("long long '%%' %s\n", (c == d) ? "passed" : "failed"); > } > --- > like this: > cc -o remtest remtest.c > ./remtest > long long '%' passed > > cc -c remtest.c > ld -r -o x.o remtest.o -lc > cc -o remtest x.o > ./remtest > long long '%' failed > > Then I was convinced there was a problem with libc. Here is my fix for it which appears to work. I'm not math whiz, but we're using the same sort of logic that exists in the gcc sources, and there is only a slight difference. Note, this 'fix' is also in the NetBSD sources in a slightly different form. They essentially copy the same algorithm as exists in the libgcc2 sources, while I minimized the changes and kept the original format for my fix. If no-one objects, I'll commit this when I get back next week. Nate ---------------- [ Warning, cut-n-paste done here so white-space is hosed ] Index: moddi3.c =================================================================== RCS file: /data/FreeBSD/CVS/src/lib/libc/quad/moddi3.c,v retrieving revision 1.1.1.1 diff -u -r1.1.1.1 moddi3.c --- moddi3.c 1994/05/27 04:57:21 1.1.1.1 +++ moddi3.c 1998/11/25 21:02:23 @@ -59,7 +59,7 @@ else ua = a, neg = 0; if (b < 0) - ub = -(u_quad_t)b, neg ^= 1; + ub = -(u_quad_t)b; else ub = b; (void)__qdivrem(ua, ub, &ur); To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message