🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.arch
Article #12109

Branchless conditionals (Was: More on Linpack pivoting)

#12109
From: Eric Hamilton
Date: Fri, 14 Jun 1991 17:35
51 lines
2591 bytes
In article <1991Jun14.134338.4673@linus.mitre.org>, bs@frieda.mitre.org (Robert D. Silverman) writes:

|> :	    ibig  = absdx .le. dmax
|> 	    ^^^^^^^^^^^^^^^^^^^^^^^^
|> 
|> I would be very interested in seeing the assembler code that gets
|> emitted for this line of Fortran. How can this statement get executed
|> WITHOUT a branch??
|>  
|> I also have never seen a machine that has conditional assignment
|> implemented as an instruction! (As indicated above). What machine is
|> this? Could you show us the assembler syntax??
|> 
|> I ** believe ** that the above conditional assignment will get compiled
|> into a test and branch. I don't know of any machine that provides
|> instructions to do otherwise.
|> 
Motorola 88000, for one.  The trick is that the compare instruction puts
the condition code bit vector into a general register instead of a dedicated
condition code register, so that the bitfield instructions can be used
on the condition codes.  For example:

	cmp	scratch,absdx,dmax	; Compare; condition codes to scratch
	extu	ibig,scratch,1<le>	; Extract the le bit into ibig,
					; right-adjusted.

The condition code bit vector is also redundant, in the sense that
if any bit is set, there is another bit, in this case greater-than, which
is known to be clear, and vice versa.  In many cases it turns out the
redundancy is useful.  It's certainly near-as-no-never-mind free.

The ibig = absdx .le. dmax example just barely scratches the surface.  For
example:
	if( a condition b )
		i = i + 1;

can be rendered as:

	cmp	rscratch,x,y
	extu	rscratch,rscratch,1<condition>
	addu	i,i,rscratch

and lots more.  I'll leave it to the compiler folks to post the most aggressively
clever example.

-- 
----------------------------------------------------------------------
Eric Hamilton				+1 919 248 6172
Data General Corporation		hamilton@dg-rtp.rtp.dg.com
62 Alexander Drive			...!mcnc!rti!xyzzy!hamilton
Research Triangle Park, NC  27709, USA
Technical Details
Message-ID: <1991Jun14.173510.22510@dg-rtp.dg.com>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!newstop!sun!amdcad!dgcad!dg-rtp!siberia!hamilton
References: <396@validgh.com> <1991Jun13.234834.22970@neon.Stanford.EDU> <1991Jun14.134338.4673@linus.mitre.org>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!newstop!sun!amdcad!dgcad!dg-rtp!siberia!hamilton
From: hamilton@siberia.rtp.dg.com (Eric Hamilton)
Newsgroups: comp.arch
Subject: Branchless conditionals (Was: More on Linpack pivoting)
Message-ID: <1991Jun14.173510.22510@dg-rtp.dg.com>
Date: 14 Jun 91 17:35:10 GMT
References: <396@validgh.com> <1991Jun13.234834.22970@neon.Stanford.EDU> <1991Jun14.134338.4673@linus.mitre.org>
Sender: hamilton@siberia (Eric Hamilton)
Organization: Data General Corporation, Research Triangle Park, NC
Lines: 50