05.02.2013 Views

ARM Architecture Reference Manual ARMv7-A and ARMv7-R edition

ARM Architecture Reference Manual ARMv7-A and ARMv7-R edition

ARM Architecture Reference Manual ARMv7-A and ARMv7-R edition

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Application Level Programmers’ Model<br />

The following functions perform conversions between single-precision <strong>and</strong> double-precision floating-point<br />

numbers.<br />

// FPSingleToDouble()<br />

// ==================<br />

bits(64) FPSingleToDouble(bits(32) oper<strong>and</strong>, boolean fpscr_controlled)<br />

fpscr_val = if fpscr_controlled then FPSCR else St<strong>and</strong>ardFPSCRValue();<br />

(type,sign,value) = FPUnpack(oper<strong>and</strong>, fpscr_val);<br />

if type == FPType_SNaN || type == FPType_QNaN then<br />

if fpscr_val == ‘1’ then // DN bit set<br />

result = FPDefaultNaN(64);<br />

else<br />

result = sign : ‘11111111111 1’ : oper<strong>and</strong> : Zeros(29);<br />

if type == FPType_SNaN then<br />

FPProcessException(FPExc_InvalidOp, fpscr_val);<br />

elsif type = FPType_Infinity then<br />

result = FPInfinity(sign, 64);<br />

elsif type = FPType_Zero then<br />

result = FPZero(sign, 64);<br />

else<br />

result = FPRound(value, 64, fpscr_val); // Rounding will be exact<br />

return result;<br />

// FPDoubleToSingle()<br />

// ==================<br />

bits(32) FPDoubleToSingle(bits(64) oper<strong>and</strong>, boolean fpscr_controlled)<br />

fpscr_val = if fpscr_controlled then FPSCR else St<strong>and</strong>ardFPSCRValue();<br />

(type,sign,value) = FPUnpack(oper<strong>and</strong>, fpscr_val);<br />

if type == FPType_SNaN || type == FPType_QNaN then<br />

if fpscr_val == ‘1’ then // DN bit set<br />

result = FPDefaultNaN(32);<br />

else<br />

result = sign : ‘11111111 1’ : oper<strong>and</strong>;<br />

if type == FPType_SNaN then<br />

FPProcessException(FPExc_InvalidOp, fpscr_val);<br />

elsif type = FPType_Infinity then<br />

result = FPInfinity(sign, 32);<br />

elsif type = FPType_Zero then<br />

result = FPZero(sign, 32);<br />

else<br />

result = FPRound(value, 32, fpscr_val);<br />

return result;<br />

The following functions perform conversions between floating-point numbers <strong>and</strong> integers or fixed-point<br />

numbers:<br />

// FPToFixed()<br />

// ===========<br />

bits(M) FPToFixed(bits(N) oper<strong>and</strong>, integer M, integer fraction_bits, boolean unsigned,<br />

boolean round_towards_zero, boolean fpscr_controlled)<br />

assert N == 32 || N == 64;<br />

fpscr_val = if fpscr_controlled then FPSCR else St<strong>and</strong>ardFPSCRValue();<br />

<strong>ARM</strong> DDI 0406B Copyright © 1996-1998, 2000, 2004-2008 <strong>ARM</strong> Limited. All rights reserved. A2-65

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

Saved successfully!

Ooh no, something went wrong!