fctiwz

Floating Convert to Integer Word with Round to Zero

fctiwz FRT, FRB

Converts Double to 32-bit Int (Truncate).

Details

The fctiwz instruction converts a double-precision floating-point value in FRB to an integer word format, rounding towards zero. If the result is out of range for a 32-bit signed integer, it saturates to either INT_MIN or INT_MAX. The result is placed into FRT.

Pseudocode Operation

if src is NaN then
    result ← 0x0000_0000
    VXCVI ← 1
    if src is SNaN then VXSNAN ← 1
else
    rounded_value ← round_towards_zero(src)
    if rounded_value > INT_MAX then
        result ← INT_MAX
        VXCVI ← 1
    else if rounded_value < INT_MIN then
        result ← INT_MIN
        VXCVI ← 1
    else
        result ← rounded_value
if not exception then FRT ← result

Programming Note

The fctiwz instruction is commonly used for converting floating-point numbers to integers with truncation. Be cautious of NaN inputs, which will result in zero and set VXCVI; SNaNs also set VXSNAN. Ensure the input is within the 32-bit signed integer range to avoid saturation. This instruction operates at user privilege level.

Example

fctiwz f1, f3

Encoding

Binary Layout
63
0
FRT
6
0
11
FRB
16
15
21
/
31
 
Format X-form
Opcode 0xFC00001E
Extension Floating-Point
Registers Altered FPSCR

Operands

  • FRT
    Target
  • FRB
    Source