From:	SMTP%"system@lokidev.attmail.com" 27-AUG-1996 20:27:24.76
To:	EVERHART
CC:	
Subj:	More amazin' macro

Date: Mon, 26 Aug 1996 20:20:29 -0500
From: system@lokidev.attmail.com ("Brian Schenkenberger, VAXman-")
Subject: More amazin' macro
To: everhart@Arisia.GCE.Com
X-VMS-Mail-To: OA%"attmail!internet!Arisia.GCE.Com!EVERHART"
Mime-Version: 1.0
Content-Type: Text/Plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Message-ID: <ATT-OADEC-3.0-00-system-7D54808D009A7714>

Hi, 

There was a question about lfloating poing in the DECUServe VMS conference
(#2739) today about floating point and Macro32.  I posted a little explain-
ation and a little code to boot.  

It's attached below.  Thought you might find it interesting.  I removed the
copyright symbol so that the mail systems don't trash it as eightbit.

Enjoy --



;++
; Copyright 1996 by Brian Schenkenberger and TMESIS.  ALL RIGHTS RESERVED.
;
; This software is provided "AS IS" and is supplied for informational purpose
; only.  No warranty is expressed or implied and no liability can be accepted
; for any actions or circumstances incurred from the use of this software or 
; from the information contained herein.  The author makes no claim as to the
; suitablility or fitness of the software or information contain herein for a
; particular purpose.
;
; Permission is hereby granted *ONLY* for the "not-for-profit" redistribution
; of this software provided that ALL SOURCE and/or OBJECT CODE remains intact
; and ALL COPYRIGHT NOTICES remain intact from its original distribution.  
;
;(!) NO TITLE TO AND/OR OWNERSHIP OF THIS SOFTWARE IS HEREBY TRANSFERRED. (!)
;--
	.TITLE	MOVE$F0_TO_R0	; Hack to move F0 to R0 on OpenVMS Alpha
	.IDENT	/V1.0 %6.239/	; Brian Schenkenberger (26-August-1996)

;++
; This program provides a quick and simple mechanism to move the contents
; of the floating point value returned in F0 from a floting point routine 
; to the integer register R0 to permit subsequent Macro-32 floating point 
; instructions to reference R0 as the returned floating value.  
; 
; For example:
;
;	PUSHAL	#^xC0DECEED	; seed value for MTH$RANDOM run-time 
;	CALLS	#1,G^MTH$RANDOM	; invoke MTH$RANDOM; return value F0
;	JSB	MOVE$F0_TO_R0	; invoke MOVE$F0_TO_R0; value in R0
;	CVTFL	R0,R0		; convert f_floating value to integer
;
; The movement of a floating value from a floating register to an integer 
; can not be accomplished directly in the Alpha architecture.  The value
; in the floating register must be stored into memory and then, retrieved
; from memory into the integer register.  This is accomplish by using the
; following Alpha instruction sequence
;
;	SUBQ	SP,#8,SP	; make room on stack for 64 bits
;	STF	F0,(SP)		; move contents of F0 to memory
;	LDQ	R0,(SP)		; load R0 from memory contents
;	ADDQ	SP,#8,SP	; restore the stack pointer 
;	RET	R31,(R26)	; return to the caller.
;
; This instruction sequence is written in MACRO-32 in the section below
; by placing the appropriate value for the Alpha instruction sequence in
; a series of .LONG storage directives.  This code thread is then, built
; as a null-frame procedure.  A small "jacket" routine handles the issue
; of making the MACRO-32 compiler happy.
;	
;--
	$EVAX_INSTRDEF	; Alpha instruction format codes
	$EVX_OPCODESDEF	; Alpha (EVAX) opcodes definitions
	$PDSCDEF	; procedure descriptor definitions

	.GLOBAL	MOVE$F0_TO_R0
	.PSECT	CODE,NOWRT,EXE,5
MOVE$F0_TO_R0:	.JSB_ENTRY
		JSB	@___F0_TO_R0
		RSB

	.PSECT	$LINKAGE,NOWRT,NOEXE,5
___F0_TO_R0:	.ADDRESS	___F0_TO_R0_PDSC
		.ALIGN	QUAD

___F0_TO_R0_PDSC:	.LONG	<PDSC$K_KIND_NULL@PDSC$V_KIND>!- 
				<PDSC$M_NATIVE!PDSC$M_NO_JACKET>,0
			.ADDRESS	___F0_TO_R0_C,0	

	.PSECT	___CODE,NOWRT,EXE,5
___F0_to_R0_C:

	;	SUBQ	SP,#8,SP
	.LONG	<EVX$OPC_ADDI@EIF$V_OPCODE>!-	; SUBQ is an integer opcode
        	<EVX$ADDI_SUBQ@EIF$V_OPR_FUNC>!-; the function is: SUBQ
	        <EVX$K_R30@EIF$V_Ra>!-		; Ra = R30
	        <<^X8>@EIF$V_Lit_val>!-		; Literal Value = 8
	        <EVX$K_R30@EIF$V_Rc>		; Rc = R30
       
	;	STF	F0,(SP)
	.LONG	<EVX$OPC_STF@EIF$V_OPCODE>!-	; STF is the Alpha opcode
		<EVX$K_F0@EIF$V_Fa>!-		; Fa = F0 source register
		<EVX$K_R30@EIF$V_Rb>		; Rb = R30 stack location

	;	LDQ	R0,(SP)
	.LONG	<EVX$OPC_LDQ@EIF$V_OPCODE>!-	; LDA is the Alpha opcode
		<EVX$K_R0@EIF$V_Ra>!-		; Ra = R0 destination reg
		<EVX$K_R30@EIF$V_Rb>		; Rb = R30 stack location 


	;	ADDQ	SP,#8,SP
	.LONG	<EVX$OPC_ADDI@EIF$V_OPCODE>!-	; ADDQ is an integer opcode
        	<EVX$ADDI_ADDQ@EIF$V_OPR_FUNC>!-; the function is: ADDQ
	        <EVX$K_R30@EIF$V_Ra>!-		; Ra = R30
	        <<^X8>@EIF$V_Lit_val>!-		; Literal Value = 8
	        <EVX$K_R30@EIF$V_Rc>		; Rc = R30
       
	;	RET	R31,(R26)
	.LONG	<EVX$OPC_JSR@EIF$V_OPCODE>!-	; RET is a jump opcode
	        <EVX$K_R31@EIF$V_Ra>!-		; Ra = R31 (RAZ/IGN)
	        <EVX$K_R26@EIF$V_Rb>!-		; Rb = R26 return address
       		<<^X8001>@EIF$V_mem_imm>	; RET hint/procedure RET

	.END


VAXman-

For without are dogs, and sorcerers, and whoremongers, and murderers,
and idolaters, and whosoever loveth and maketh a lie.  - Revelation -
