Reserved operand handing on VAX VMS

Nelson H. F. Beebe sun!science.utah.edu!Beebe
Tue Jul 3 13:16:22 PDT 1990


Here is how Fortran on VAX VMS handles a reserved operand:

      real res,x,y,z

      data res / '00008000'x /

      x = abs(res)
      y = res
      z = -res
      write (6,'(4(1x,z8.8,1x))') x,y,z,res
      end

FOO$MAIN                                                         3-Jul-1990 11:55:45	VAX FORTRAN V5.4-79                 Page   2
01                                                               3-Jul-1990 11:55:05	SYS$OPRROOT:[BEEBE]FOO.FOR;3                

		.TITLE	FOO$MAIN
		.IDENT	01

    0000	.PSECT	$PDATA
    0000  L$1:
    0000	.XBYTE	01,82,01,04,13,01,1C,08,08,13,01,03,04

    0000	.PSECT	$LOCAL
    0000  RES:
    0000	.LONG	^X00008000

    0000	.PSECT	$CODE
; 0001
    0000  FOO$MAIN::
    0000	.WORD	^M<IV,R11>
    0002	MOVAL	$LOCAL, R11
; 0005
    0009	BICL3	#^X8000, RES(R11), X(R11)
; 0006
    0012	MOVL	RES(R11), Y(R11)
; 0007
    0016	MNEGF	RES(R11), Z(R11)

That is:
	Absolute value (y = abs(res)) uses an AND to clear
	the sign bit (BICL is an AND-NOT instruction),   No
	trap happens.

	Assignment (y = res) uses a benign 8-byte move.  No
	trap happens.

	Negation (z = -res) uses a floating-point negation
	instruction which traps with a reserved operand
	fault when the program is run.

The results in DOUBLE PRECISION are similar; the generated
instructions are

    0009	MOVQ	RES(R11), R2
; 0005
    000C	MOVQ	R2, R4
    000F	BICW2	#^X8000, R4
; 0007
    0014	MNEGD	R2, R6

For VAX C V3.1, with the test program

#include <stdio.h>

#define abs(x) ( (x < 0.0) ? (-x) : (x) )

int
main(argc,argv)
int argc;
char* argv[];
{
    union
    {
        long i;
        float r;
    } res;
    float x,y,z;

    res.i = 0x00008000L;
    x = abs(res.r);
    y = res.r;
    z = -res.r;

    printf("%08.8x  %08.8x  %08.8x  %08.8x \n",x,y,z,res.r);

    return (0);
}

the generated code is

  250    1   	    res.i = 0x00008000L;
                  E8 AD 00008000 8F D0    000B		movl	#32768,-24(fp)

  251    1   	    x = abs(res.r);
                              E8 AD 53    0013		tstf	-24(fp)
                                 0C 18    0016		bgeq	sym.1
                           50 E8 AD 52    0018		mnegf	-24(fp),r0
                           EC AD 50 50    001C		movf	r0,-20(fp)
                                 0A 11    0020		brb	sym.2
                                 50 D5    0022		tstl	r0
                                          0024	sym.1:
                           50 E8 AD 50    0024		movf	-24(fp),r0
                           EC AD 50 50    0028		movf	r0,-20(fp)
                                          002C	sym.2:
                        F8 AD EC AD 50    002C		movf	-20(fp),-8(fp)

  252    1   	    y = res.r;
                        F4 AD E8 AD 50    0031		movf	-24(fp),-12(fp)

  253    1   	    z = -res.r;
                           50 E8 AD 52    0036		mnegf	-24(fp),r0
                           F0 AD 50 50    003A		movf	r0,-16(fp)

Assignment, sign test (part of abs()), and negation all use
floating-point instructions, and the program dies on the
tstf instruction with a reserved operand fault.
-------



More information about the Numeric-interest mailing list