[gnu.gcc.bug] problem with gcc 1.33 on sun3 with inline 68881 instructions

andy@CSVAX.CALTECH.EDU (Andy Fyfe) (02/08/89)

(gcc is configured for a sun 3 (sun os 3.5)).

Gcc botches register assignments on the following program when '-O' is used.
Without '-O', the program works ok.  It seems to be necessary that the
function 'pow' be called twice with the same arguments.  The use of "const"
doesn't change anything.
    static inline const double
    log(double x)
    {
	double y;

	asm("flognx %1,%0": "=f" (y): "f" (x));
	return y;
    }

    static inline const double
    exp(double x)			/* returns e^x */
    {
	double y;

	asm("fetoxx %1,%0": "=f" (y): "f" (x));
	return y;
    }

    static inline const double
    pow(double x, double y)		/* returns x^y */
    {
	return exp(y * log(x));
    }

    double
    foo(double x, double y)
    {
	printf("%g\n", pow(x,y));
	return pow(x,y);
    }

    main()
    {
	printf("%g\n", foo(3,2));
    }

The generated assembly code follows:
    #NO_APP
    gcc_compiled.:
    .text
    LC0:
	    .ascii "%g\12\0"
	    .even
    .globl _foo
    _foo:
	    link a6,#0
	    fmovem #0x4,sp@-
	    fmoved a6@(8),fp1
    #APP
	    flognx fp1,fp0
    #NO_APP
	    fmuld a6@(16),fp0
    #APP
	    fetoxx fp2,fp1			<-- should be fp0 not fp2
    #NO_APP
	    fmoved fp1,sp@-
	    pea LC0
	    jbsr _printf
	    fmoved fp2,sp@-			<-- should be fp1 not fp2
	    movel sp@+,d0
	    movel sp@+,d1
	    fmovem a6@(-12),#0x20
	    unlk a6
	    rts
	    .even
    .globl _main
    _main:
	    link a6,#0
	    clrl sp@-
	    movel #1073741824,sp@-
	    clrl sp@-
	    movel #1074266112,sp@-
	    jbsr _foo
	    movel d1,sp@-
	    movel d0,sp@-
	    pea LC0
	    jbsr _printf
	    unlk a6
	    rts