private static void EmitF2F( EmitterContext context, DstFmt srcType, DstFmt dstType, IntegerRound roundingMode, Operand src, int rd, bool absolute, bool negate, bool saturate) { Operand srcB = context.FPAbsNeg(src, absolute, negate, srcType.ToInstFPType()); if (srcType == dstType) { srcB = roundingMode switch { IntegerRound.Round => context.FPRound(srcB, srcType.ToInstFPType()), IntegerRound.Floor => context.FPFloor(srcB, srcType.ToInstFPType()), IntegerRound.Ceil => context.FPCeiling(srcB, srcType.ToInstFPType()), IntegerRound.Trunc => context.FPTruncate(srcB, srcType.ToInstFPType()), _ => srcB }; } // We don't need to handle conversions between FP16 <-> FP32 // since we do FP16 operations as FP32 directly. // FP16 <-> FP64 conversions are invalid. if (srcType == DstFmt.F32 && dstType == DstFmt.F64) { srcB = context.FP32ConvertToFP64(srcB); } else if (srcType == DstFmt.F64 && dstType == DstFmt.F32) { srcB = context.FP64ConvertToFP32(srcB); } srcB = context.FPSaturate(srcB, saturate, dstType.ToInstFPType()); WriteFP(context, dstType, srcB, rd); // TODO: CC. }
private static void EmitF2I( EmitterContext context, DstFmt srcType, IDstFmt dstType, RoundMode2 roundingMode, Operand src, int rd, bool absolute, bool negate) { if (dstType == IDstFmt.U64) { context.Config.GpuAccessor.Log("Unimplemented 64-bits F2I."); return; } Instruction fpType = srcType.ToInstFPType(); bool isSignedInt = dstType == IDstFmt.S16 || dstType == IDstFmt.S32 || dstType == IDstFmt.S64; bool isSmallInt = dstType == IDstFmt.U16 || dstType == IDstFmt.S16; Operand srcB = context.FPAbsNeg(src, absolute, negate, fpType); srcB = roundingMode switch { RoundMode2.Round => context.FPRound(srcB, fpType), RoundMode2.Floor => context.FPFloor(srcB, fpType), RoundMode2.Ceil => context.FPCeiling(srcB, fpType), RoundMode2.Trunc => context.FPTruncate(srcB, fpType), _ => srcB }; if (!isSignedInt) { // Negative float to uint cast is undefined, so we clamp the value before conversion. srcB = context.FPMaximum(srcB, ConstF(0), fpType); } if (srcType == DstFmt.F64) { srcB = isSignedInt ? context.FP64ConvertToS32(srcB) : context.FP64ConvertToU32(srcB); } else { srcB = isSignedInt ? context.FP32ConvertToS32(srcB) : context.FP32ConvertToU32(srcB); } if (isSmallInt) { int min = (int)GetIntMin(dstType); int max = (int)GetIntMax(dstType); srcB = isSignedInt ? context.IClampS32(srcB, Const(min), Const(max)) : context.IClampU32(srcB, Const(min), Const(max)); } Operand dest = GetDest(rd); context.Copy(dest, srcB); // TODO: CC. }