Article View: comp.arch
Article #12088Re: Is double->int slow?
From: Bryce Cogswell
Date: Fri, 14 Jun 1991 16:36
Date: Fri, 14 Jun 1991 16:36
37 lines
2319 bytes
2319 bytes
I count 16 instructions used to perform the double -> int conversion on
the RS/6000:
4 are used for +/- checking and compensation.
4 are used for range checking.
4 are used to manipulate the FP status register.
4 are used to truncate and move the number to an integer register.
The cc compiler calls a subroutine to perform the conversion, so the
actual number of instructions required in C is larger.
As long as I'm wasting bandwidth on this, here is the code sequence:
The double value is initially in f1. r2 and r6 point to memory containing
constants. c6 and c0 are condition code registers.
lfs f0,12(r2) f0 <- 0.0
fcmpu c6,f1,f0 c6 <- f1 ? f0 [X >= 0]
l r6,16(r2) r6 <- 0x10000778
fabs f5,f1 f5 <- abs( f1 )
lfd f2,8(r6) f2 <- 2^31
mffs f4 f4 <- floating status
fcmpu c0,f5,f2 c0 <- f5 ? f2
lfd f3,0(r6) f3 <- 4512395720392704.0
bc 12,24,L2 branch if c6 less than [X negative]
mtfsb1 30 set floating status bit 30
mtfsb1 31 (re)set floating status bit 31
fa f6,f1,f3 f6 <- f1 + f3 [truncates value]
stfd f6,-8(r1) mem <- f6
mtfsf 1,f4 floating status <- f4
bc 4,0,L3 branch if c0 greater than [X out of range]
l r3,-4(r1) r3 <- mem
If the double is negative a similar sequence of instructions is executed,
except that bit 31 of the status register is reset rather than set.
-- Bryce
Technical Details
Message-ID:
<COGSWELL.91Jun14123657@MEAT.cs.cmu.edu>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!sei.cmu.edu!fs7.ece.cmu.edu!o.gp.cs.cmu.edu!pt.cs.cmu.edu!cogswellReferences:
<1991Jun10.220533.19560@jetsun.weitek.COM> <COGSWELL.91Jun11112827@MEAT.cs.cmu.edu> <1991Jun12.014037.26495@cl.cam.ac.uk> <3698@charon.cwi.nl>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!sei.cmu.edu!fs7.ece.cmu.edu!o.gp.cs.cmu.edu!pt.cs.cmu.edu!cogswell From: cogswell@MEAT.cs.cmu.edu (Bryce Cogswell) Newsgroups: comp.arch Subject: Re: Is double->int slow? Message-ID: <COGSWELL.91Jun14123657@MEAT.cs.cmu.edu> Date: 14 Jun 91 16:36:57 GMT References: <1991Jun10.220533.19560@jetsun.weitek.COM> <COGSWELL.91Jun11112827@MEAT.cs.cmu.edu> <1991Jun12.014037.26495@cl.cam.ac.uk> <3698@charon.cwi.nl> Distribution: comp Organization: Carnegie Mellon University Lines: 37 In-reply-to: dik@cwi.nl's message of 14 Jun 91 00:54:22 GMT