跳转至

FCVT

说明

浮点数转换(Floating-point Convert)
将输入寄存器中浮点型数据转换为目标类型的精度,舍入模式由系统寄存器CSTATE确定,结果写入到目的寄存器中。

汇编语法

    fcvt.{srcT2dstT} SrcL, ->{t, u, Rd}

汇编符号

  • SrcL:输入寄存器,可以索引全局寄存器R0-R23和前序1-4条输出至T队列或U队列的指令结果。
  • srcT:表达源数据类型,范围包括FB,FH,FS,FD等。
  • dstT:表达目标数据类型,范围同srcT。
  • ->:用于指示目的寄存器。
  • {t,u,Rd}:表示三种可选的目的寄存器,编码于RegDst域。其中:
    • t,u:分别表示块内的T和U寄存器队列。
    • Rd:可以索引全局寄存器R1-R23。

编码格式

FCVT

SrcType和DstType域编码如下表:

编码 数据格式 说明
0 FD 64bit双精度浮点数
1 FS 32bit单精度浮点数
2 FH 16bit半精度浮点数
3 FB 8bit低精度浮点数
>3 reserve 保留

执行方式

  • 转换为十进制数:UInt()
  • 通用寄存器读写:R[]
    integer d = UInt(RegDst);
    integer m = UInt(SrcL);
    DataType srcType, dstType;

    RoundingMode rmode;
    if SSR[CSTATE].RV == 1 then rmode = SSR[CSTATE].FRM;
    else rmode = FPRounding_TIEEVEN

    case SrcType of:
        when 0 then srcType = FP64;
        when 1 then srcType = FP32;
        when 2 then srcType = FP16;
        when 3 then srcType = FP8;

    case DstType of:
        when 0 then dstType = FP64;
        when 1 then dstType = FP32;
        when 2 then dstType = FP16;
        when 3 then dstType = FP8;
        otherwise undefined;        # 其他编码未定义

    bits(64) operand = R[m, 64];
    bits(64) result = FPConvert(operand, srcType, dstType, rmode);

    R[d, 64] = result;

舍入模式

此指令使用的舍入模式由系统寄存器CSTATE的FRM字段决定,如果CSTATE中舍入模式是无效的,则使用默认的RNE模式。

备注

本指令属于标准指令扩展,只能用于浮点块指令块体中。