[net.lang.c] C compiler test

ucsch.pravda@ucb-vax.ARPA (07/23/86)

On our VAX 11/750 running 4.2bsd I got the incorrect 3 and 4
both normal and optimized.

Maybe you see something in this (I'm no assembler wiz)?
output from cc -S 

LL0:
	.data
	.text
	.align	1
	.globl	_main
_main:
	.word	L12
	jbr 	L14
L15:
	movl	$8,-4(fp)
	.data
	.align	2
L16:
	.double	0d2.50000000000000000000e+00
	.text
	cvtld	-4(fp),r0
	divd2	L16,r0
	cvtdl	r0,r0
	movl	r0,-4(fp)
	.data	1
L18:
	.ascii	"i= %d\12\0"
	.text
	pushl	-4(fp)
	pushl	$L18
	calls	$2,_printf
	movl	$8,-4(fp)
	.data
	.align	2
L19:
	.double	0d2.50000000000000000000e+00
	.text
	cvtdl	L19,r0
	divl2	r0,-4(fp)
	.data	1
L20:
	.ascii	"i= %d\12\0"
	.text
	pushl	-4(fp)
	pushl	$L20
	calls	$2,_printf
	pushl	$0
	calls	$1,_exit
	ret
	.set	L12,0x0
L14:
	subl2	$4,sp
	jbr 	L15
	.data

=============
	Peter L. Rosencrantz
	Mathematics Board
	(or Campus Computer Center)
	University of California
	Santa Cruz, CA 95064

	pravda%ucsc.csnet@csnet-relay.ARPA
	pravda%ucsc%csnet-relay.arpa@CSNET-RELAY
	pravda@ucscc.BITNET
	{ucbvax,drivax,escher}!ucscc!pravda.UUCP

Bader@b.psy.cmu.edu (Miles Bader) (07/23/86)

In the first case (i=i/2.5), it's converting the i to double, dividing by
2.5 and converting the answer back to integer.  In the second case, it's
converting the 2.5 to integer and doing an integer divide.  The first
method seems like the correct one, although less efficient...

jeff@gatech.CSNET (Jeff Lee) (07/23/86)

This bug has been fixed in the 4.3 compiler. It was documented as a
misunderstanding as to what was to be cast.
-- 
Jeff Lee
CSNet:	Jeff @ GATech		ARPA:	Jeff%GATech.CSNet @ CSNet-Relay.ARPA
uucp:	...!{akgua,allegra,hplabs,ihnp4,linus,seismo,ulysses}!gatech!jeff

greg@utcsri.UUCP (Gregory Smith) (07/23/86)

In article <2477@brl-smoke.ARPA> ucsch.pravda@ucb-vax.ARPA writes:
>
>On our VAX 11/750 running 4.2bsd I got the incorrect 3 and 4
>both normal and optimized.
>
>Maybe you see something in this (I'm no assembler wiz)?
:
( Comments mine:)
>L16:	.double	0d2.5e+00
>	.text
>	cvtld	-4(fp),r0 ;	r0 = (double)i
>	divd2	L16,r0	  ;	r0 = r0/2.5  ( double divide )
>	cvtdl	r0,r0	  ;	r0 = (int)r0
>	movl	r0,-4(fp) ;	i = r0
:
>L19:	.double	0d2.5e+00
>	.text
>	cvtdl	L19,r0	  ;	r0 = (int)2.5	( i.e. r=2 )
>	divl2	r0,-4(fp) ;	i=i/r0		( integer divide )

So i /= 2.5 is incorrectly treated as i /= (int)2.5.
( This here VAX running 4.2BSD produces essentially the same code
for both and says 3,3).

-- 
"You'll need more than a Tylenol if you don't tell me where my father is!"
						- The Ice Pirates
----------------------------------------------------------------------
Greg Smith     University of Toronto      UUCP: ..utzoo!utcsri!greg