No subject

Qiu, Zhe (John) zqiuagulf.uvic.ca
Fri Nov 14 10:38:24 PST 1997


>Hi,

>I just want to know where I can find information on 
>the fastest way to change the rounding mode.
>For instance, on solaris I use the system function 
>ieee_flags, but it appears to be rather slow :-(
> 
> 
>Thanks in advance for any pointers on that,
>Phil.

One way to change rounding mode in C++ on a Solaris machine is to call 
the floating-point environment control functions in a way similar to what 
Mr. Tyde suggests. However since not all compilers conform to the FPCE 
proposal, there are often some variances in the names of the library 
include files and rounding control functions. I do the following on a 
SPARCstation 20 running Solaris 2.6:

# include <ieeefp.h>

fpsetround(FP_RN) /* round to nearest */
fpsetround(FP_RZ) /* round toward zero */
fpsetround(FP_RP) /* round toward +oo */
fpsetround(FP_RM) /* round toward -oo */

I completely agree with Mr. Tydeman on using these macros instead of 
setting ieee_flags in doing so, since this is just a more direct way.

Another cubersome use is to include assembly code directly in your 
program, this is highly hardware dependent, yet sometimes it does worth a 
try. Various packages have used this appoach, e.g. PROFIL/BIAS.

The following code seems working on a Solaris machine:

static unsigned long  CwRoundUp    = 0x80000000L;
static unsigned long  CwRoundDown  = 0xC0000000L;
static unsigned long  CwRoundNear  = 0x00000000L;
  
#define RoundUp    asm volatile ("ld %0,%%fsr" : : "g" (CwRoundUp))
#define RoundDown  asm volatile ("ld %0,%%fsr" : : "g" (CwRoundDown))
#define RoundNear  asm volatile ("ld %0,%%fsr" : : "g" (CwRoundNear))
 
Have fun!

John Qiu.

+-------------------------------------------------------------------+
| Qiu, Zhe (John)                ("`-''-/").___..--''"`-._          |
| Dept. of Comp. Sci.             `6_ 6  )   `-.  (     ).`-.__.`)  |
| Univ. of Victoria               (_Y_.)'  ._   )  `._ `. ``-..-'   |
| P.O. Box 3055, MS 7209        _..`--'_..-_/  /--'_.' ,'           |
| Victoria, B.C., V8W 3P6      (il),-''  (li),'  ((!.-'  a ELW A238 |       
|                                                                   |
| Email: zqiuacsr.uvic.ca   Voice: 250-472-4243   Fax: 250-721-7292 |
+-------------------------------------------------------------------+










More information about the Numeric-interest mailing list