14.06.2015 Views

Power ISA™ Version 2.03 - Power.org

Power ISA™ Version 2.03 - Power.org

Power ISA™ Version 2.03 - Power.org

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Version</strong> <strong>2.03</strong><br />

E.3 Floating-Point Selection [Category: Floating-Point]<br />

This section gives examples of how the Floating Select<br />

instruction can be used to implement floating-point minimum<br />

and maximum functions, and certain simple<br />

forms of if-then-else constructions, without branching.<br />

The examples show program fragments in an imaginary,<br />

C-like, high-level programming language, and the<br />

corresponding program fragment using fsel and other<br />

<strong>Power</strong> ISA instructions. In the examples, a, b, x, y, and<br />

z are floating-point variables, which are assumed to be<br />

in FPRs fa, fb, fx, fy, and fz. FPR fs is assumed to be<br />

available for scratch space.<br />

Additional examples can be found in Section E.2,<br />

“Floating-Point Conversions [Category: Floating-Point]”<br />

on page 328.<br />

Warning: Care must be taken in using fsel if IEEE<br />

compatibility is required, or if the values being tested<br />

can be NaNs or infinities; see Section E.3.4.<br />

E.3.1<br />

E.3.2<br />

Comparison to Zero<br />

High-level language: <strong>Power</strong> ISA: Notes<br />

if a ≥ 0.0 then x y<br />

else x z<br />

if a > 0.0 then x y<br />

else x z<br />

if a = 0.0 then x y<br />

else x z<br />

fsel fx,fa,fy,fz (1)<br />

fneg fs,fa<br />

fsel fx,fs,fz,fy<br />

fsel fx,fa,fy,fz<br />

fneg fs,fa<br />

fsel fx,fs,fx,fz<br />

Minimum and Maximum<br />

E.3.3 Simple if-then-else<br />

Constructions<br />

(1,2)<br />

(1)<br />

High-level language: <strong>Power</strong> ISA: Notes<br />

x min(a,b)<br />

x max(a,b)<br />

fsub fs,fa,fb<br />

fsel fx,fs,fb,fa<br />

fsub fs,fa,fb<br />

fsel fx,fs,fa,fb<br />

(3,4,5)<br />

(3,4,5)<br />

High-level language: <strong>Power</strong> ISA: Notes<br />

if a ≥ b then x y<br />

else x z<br />

if a > b then x y<br />

else x z<br />

if a = b then x y<br />

else x z<br />

fsub fs,fa,fb<br />

fsel fx,fs,fy,fz<br />

fsub fs,fb,fa<br />

fsel fx,fs,fz,fy<br />

fsub fs,fa,fb<br />

fsel fx,fs,fy,fz<br />

fneg fs,fs<br />

fsel fx,fs,fx,fz<br />

(4,5)<br />

(3,4,5)<br />

(4,5)<br />

E.3.4<br />

Notes<br />

The following Notes apply to the preceding examples<br />

and to the corresponding cases using the other three<br />

arithmetic relations (

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!