Subject: port-arm32/7760: Division gets wrong result.
To: None <gnats-bugs@gnats.netbsd.org>
From: Richard Earnshaw <rearnsha@cambridge.arm.com>
List: netbsd-bugs
Date: 06/11/1999 09:05:45
>Number:         7760
>Category:       port-arm32
>Synopsis:       Division routine gives wrong result
>Confidential:   no
>Severity:       critical
>Priority:       medium
>Responsible:    port-arm32-maintainer (NetBSD/arm32 Portmaster)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Jun 11 09:05:01 1999
>Last-Modified:
>Originator:     Richard Earnshaw
>Organization:
ARM
-- 
>Release:        NetBSD-1.4
>Environment:
	
System: NetBSD shark1 1.4C NetBSD 1.4C (SHARK) #36: Mon May 24 14:03:27 BST 1999 rearnsha@shark1:/usr/src/sys/arch/arm32/compile/SHARK arm32


>Description:
	The following program demonstrtates that the __divsi3 routine in libc
	is returning the wrong result if the dividend is INT_MIN.


	There are probably similar problems with __modsi3.

>How-To-Repeat:

	Compile and execute the following problem (at any optimization level
	less than -O3).  The two values printed should be identical.

	#include <limits.h>

	int real_result = INT_MIN / 4;

	divit(int x, int y)
	{
	  printf("%d, %d\n", x / y, real_result);
	}

	int main()
	{
	  divit(INT_MIN, 4);
	}

>Fix:
	The routines supplied with the official gcc releases get this right
	(but then, I wrote them :-).

>Audit-Trail:
>Unformatted: