Instructions of change of rounding modes (IEEE754)

Notations

Near is rounding to the nearest,

Down rounding to the minus infinity,

Up rounding to the plus infinity,

and

Chop chopping rounding mode.

LINUXCFreeBSD 3.x@gcc

Define the following global variables:

int   _RoundNear   =0x133a;

int   _RoundDown   =0x173a;

int   _RoundUp     =0x1b3a;

int   _RoundChop   =0x1f3a;

Then, change of rounding mode can be done by

Near

asm volatile (gfldcw _RoundNearh)

Down

asm volatile (gfldcw _RoundDownh)

Up

asm volatile (gfldcw _RoundUph)

Chop

asm volatile (gfldcw _RoundChoph)

Example of implementation:

On the top of programs, declare the following:

#define Near()   asm volatile (gfldcw _RoundNearh)

#define Down()   asm volatile (gfldcw _RoundDownh)

#define Up()     asm volatile (gfldcw _RoundUph)

#define Chop()   asm volatile (gfldcw _RoundChoph)

Then, we can change rounding mode by

Near();

Down();

Up();

Chop();

SUN Sparc gcc

Define the following global variables:

int   _RoundNear   =0x00000000L;

int   _RoundDown   =0xc0000000L;

int   _RoundUp     =0x80000000L;

int   _RoundChop   =0x40000000L;

Then, we can change rounding mode by

Near

asm volatile (gld %0,%%fsrh: :hgh (_RoundNear))

Down

asm volatile (gld %0,%%fsrh: :hgh (_RoundDown))

Up

asm volatile (gld %0,%%fsrh: :hgh (_RoundUp))

Chop

asm volatile (gld %0,%%fsrh: :hgh (_RoundChop))

Window98@GNU-WIN32

Define the following global variables:

int   _RoundNear   =0x133a;

int   _RoundDown   =0x173a;

int   _RoundUp     =0x1b3a;

int   _RoundChop   =0x1f3a;

Then, we can change rounding mode by

Near

asm volatile (gfldcw __RoundNearh)

Down

asm volatile (gfldcw __RoundDownh)

Up

asm volatile (gfldcw __RoundUph)

Chop

asm volatile (gfldcw __RoundChoph)


last modified 2001/1/13

© Oishi

URI: http://www.oishi.info.waseda.ac.jp/~oishi/FAQ/table.htm