汇编 16位浮点数转换指令

发布于:2024-05-17 ⋅ 阅读:(164) ⋅ 点赞:(0)

VCVTPH2PS

VCVTPH2PS xmm1, xmm2/m64
         Convert four packed FP16(半精度浮点数) values in xmm2/m64 to packed single precision floating-point value in xmm1. 

        将xmm2/m64中的16位整数转换为xmm1中的单精度浮点数。xmm2/m64表示源操作数,而xmm1表示目的操作数。

{3.14, -2.5, 1.618, -4.2}, 每个数值为FP16(16位)

{3.14, -2.5, 1.618, -4.2},转换后每个数值为单精度(32位)

VCVTPH2PS ymm1, xmm2/m128
         Convert eight packed FP16 values in xmm2/m128 to packed single precision floating-point value in ymm1.

将xmm2/m128中的16位整数转换为ymm1中的单精度浮点数。xmm2/m128表示源操作数,而ymm1表示目的操作数。

vCvt_h2s(SRC1[15:0])
{
RETURN Cvt_Half_Precision_To_Single_Precision(SRC1[15:0]);
}

VCVTPH2PS (VEX.128 Encoded Version) 
    DEST[31:0] := vCvt_h2s(SRC1[15:0]);
    DEST[63:32] := vCvt_h2s(SRC1[31:16]);
    DEST[95:64] := vCvt_h2s(SRC1[47:32]);
    DEST[127:96] := vCvt_h2s(SRC1[63:48]);
    DEST[MAXVL-1:128] := 0

VCVTPS2PH

VCVTPS2PH xmm1/m64, xmm2, imm8
        Convert four packed single-precision floating-point values in xmm2 to packed half-precision (16-bit) floating-point values in xmm1/m64. Imm8 provides rounding controls.

xmm2中的单精度浮点数转换为xmm1/m64中的16位压缩的FP16值

IMM8:        

  • 舍入到最接近的偶数
  • 向零舍入
  • 向下舍入(朝负无穷大方向)
  • 向上舍入(朝正无穷大方向)
  • 向最接近的较小的数舍入
  • 向最接近的较大的数舍入

VCVTPS2PH xmm1/m128, ymm2, imm8
         Convert eight packed single-precision floating-point values in ymm2 to packed half-precision (16-bit) floating-point values in xmm1/m128. Imm8 provides rounding controls.

将ymm2寄存器中低64位的单精度浮点数转换为xmm1/m128寄存器中的16位压缩的FP16值

单精度浮点(32位)和半精度浮点(16位)数据之间的转换

IMM8
bits Field Name/value Description Comment
Imm[1:0]

RC=00B

RC=01B

RC=10B

RC=11B

Round to nearest even

Round down

Round up

Truncate

If Imm[2] = 0
Imm[2]

MS1=0

MS1=1

Use imm[1:0] for rounding 

Use MXCSR.RC for rounding

 Ignore MXCSR.RC
Imm[7:3] Ignored Ignored by processor


网站公告

今日签到

点亮在社区的每一天
去签到