Article 136769 of comp.os.vms:
Path: nntpd.lkg.dec.com!lead.zk3.dec.com!crl.dec.com!crl.dec.com!caen!newsxfer.itd.umich.edu!tank.news.pipex.net!pipex!newsfeed.internetmci.com!uwm.edu!homer.alpha.net!mvb.saic.com!info-vax
From: Jerry Leichter <leichter@lrw.com>
Newsgroups: comp.os.vms
Subject: RE: VAX instruction question
Message-ID: <9512250416.AA20487@uu3.psi.com>
Date: Sun, 24 Dec 95 23:12:12 EDT
Organization: Info-Vax<==>Comp.Os.Vms Gateway
X-Gateway-Source-Info: Mailing List
Lines: 48

	On a VAX, I am currently writing a program that executes some
	high-speed mathematical computations.  I am writing it in MACRO-32 for
	two reasons:  1) It is a translation of a program written in 386
	assembler on a PC clone,

Not a good reason.

				 and 2) increased speed.

*Probably* not a good reason.  It depends entirely on the details of the
algorithm.  If I were you, however, I'd consider recoding in C (FORTRAN would
be better, since the FORTRAN compiler probably does a better job of optimi-
zation of mathematical expressions, but unfortunately FORTRAN doesn't do
unsigned arithmetic) and looking at the generated assembler code.  If you
can't see a way to improve on it - leave it alone.  If you *can* see better
approaches - certainly possible - at least you may be able to re-do in
assembler only the most critical parts.

							  The 386 instruction
	set has both signed and unsigned division instructions, both of which
	return a remainder as well as a quotient, while the only VAX
	instruction that comes close is the EDIV instruction, which is for
	signed division.  Is there any way to put the VAX into unsigned mode,
	or  otherwise force it to perform unsigned computations, since my
	program calls specifically for unsigned, not signed, computations?

No.  The VAX does not have a general unsigned division instruction.  It can
be simulated using EDIV a some additional code:  Unsigned i/j is done by:

	MOVL	I,R0
	MOVL	J,R1
	BGEQ	X
	CLRL	R2
	CMPL	R1,R0
	BGTRU	Y
	INCL	R2
	BRB	Y
X:	EDIV	R1,R0,R2,R0
Y:	<quotient is in R2>

If you know that J < 2^32, the first branch won't be taken and you can just
do the EDIV.  I haven't thought this through carefully enough to know if R0
always contains a valid remainder.

BTW, I got this code by doing what i recommended above:  Writing a small C
program and doing a CC/LIST/MACHINE_CODE.  (I then reorganized things a bit.)

							-- Jerry


