ctfix

Convert To Fixed

ctfix FRT,FRA

Converts a decimal floating-point value to a fixed-point integer.

Details

The ctfix instruction converts the source operand b in FRA[p] to a fixed-point integer and places the result in FRT[p]. The conversion is based on the specified rounding mode.

Pseudocode Operation

if 'ctfix' then
    n <- ConvertToFixed(FRA[p])
    T(n)
    if InexactException then
        FI ← 0, FR ← 0, VXCVI ← 1
        if FE0 and FE1 are not ignore-exception mode then TV
    if InvalidOperation then
        VXCVI ← 1, TV
    if SNaN then
        VXSNAN ← 1, TV

Programming Note

The ctfix instruction is used to convert floating-point numbers to fixed-point integers. Ensure the source operand is properly aligned and within valid range to avoid exceptions. Be cautious of rounding modes as they can affect the result significantly. This instruction operates at user privilege level but may trigger exceptions like inexact conversion or invalid operations, which need to be handled appropriately.

Example

ctfix f1, f2

Encoding

Binary Layout
10011000
0
FRT
6
FRA
11
0000000000000000
16
 
Format X-form
Opcode 0xEC000244
Extension Decimal Floating-Point
Registers Altered FI, FR, VXCVI, VXSNAN, XX, FPSCR

Operands

  • FRT
    Target Floating-Point Register
  • FRA
    Source Floating-Point Register