From:	CSBVAX::CSBVAX::MRGATE::"SMTP::CRVAX.SRI.COM::RELAY-INFO-VAX" 22-FEB-1989 01:14
To:	MRGATE::"ARISIA::EVERHART"
Subj:	Re: VMS->IEEE fp conversion


Received: From KL.SRI.COM by CRVAX.SRI.COM with TCP; Tue, 21 FEB 89 21:31:40 PDT
Received: from ucbvax.Berkeley.EDU by KL.SRI.COM with TCP; Tue, 21 Feb 89 21:16:09 PST
Received: by ucbvax.Berkeley.EDU (5.61/1.34)
	id AA14625; Tue, 21 Feb 89 17:38:42 -0800
Received: from USENET by ucbvax.Berkeley.EDU with netnews
	for info-vax@kl.sri.com (info-vax@kl.sri.com)
	(contact usenet@ucbvax.Berkeley.EDU if you have questions)
Date: 22 Feb 89 00:10:00 GMT
From: modular!olson@arizona.edu  (Jon Olson)
Organization: Modular Mining Systems, Tucson, AZ
Subject: Re: VMS->IEEE fp conversion
Message-Id: <648@modular.UUCP>
References: <62500032@uxe.cso.uiuc.edu>
Sender: info-vax-request@kl.sri.com
To: info-vax@kl.sri.com

I wrote the following MACRO routines a while ago to handle
conversion between IEEE and VAX F-floating point format.
I normally don't write MACRO routines because software portability
is important but, in this case, portability isn't really useful
to anything other than a VAX.  MACRO has circular shift instructions
which aren't available in C or FORTRAN.  Anyway, here is the macro
to do the floating point conversions.  Note that each routine takes
a F-floating point number by reference so they are easily called
from either FORTRAN or C.
;
;	Synopsis: Convert IEEE float to VAX F-float format
;
;	void ntohf( pf )
;	float *pf;
;
   .ENTRY    NTOHF,0
    MOVL     B^4(AP),R1			; R2 = pf
    MOVB     B^2(R1),R0			; shuffle bytes around from BIG-ENDIAN
    ASHL     #8,R0,R0			; to LITTLE-ENDIAN format
    MOVB     B^3(R1),R0
    ASHL     #8,R0,R0
    MOVB     (R1),R0
    ASHL     #8,R0,R0
    MOVB     B^1(R1),R0
    ROTL     #-7,R0,R0			; shift exponent to low-byte
    TSTB     R0				; dont change exponent if zero
    BEQL     NTOHF0
    ADDB2    #2,R0			; difference of 2 between IEEE and vax
NTOHF0:
    ROTL     #7,R0,R0			; shift exponent back proper place
    MOVL     R0,(R1)
    RET
;
;	Synopsis: Convert VAX F-float to IEEE format
;
;	void htonf( pf )
;	float *pf;
;
   .ENTRY    HTONF,0
    MOVL     B^4(AP),R1			; R2 = pf
    MOVL     (R1),R0
    ROTL     #-7,R0,R0			; shift exponent to low-byte
    TSTB     R0				; dont change exponent if zero
    BEQL     NTOHF0
    SUBB2    #2,R0			; difference of 2 between IEEE and vax
HTONF0:
    ROTL     #7,R0,R0			; shift back to proper format
    MOVB     R0,B^1(R1)
    ASHL     #-8,R0,R0
    MOVB     R0,(R1)
    ASHL     #-8,R0,R0
    MOVB     R0,B^3(R1)
    ASHL     #-8,R0,R0
    MOVB     R0,B^2(R1)
    RET

