コード例 #1
0
        private static void EmitI2F(
            EmitterContext context,
            ISrcFmt srcType,
            DstFmt dstType,
            Operand src,
            ByteSel byteSelection,
            int rd,
            bool absolute,
            bool negate)
        {
            bool isSignedInt =
                srcType == ISrcFmt.S8 ||
                srcType == ISrcFmt.S16 ||
                srcType == ISrcFmt.S32 ||
                srcType == ISrcFmt.S64;
            bool isSmallInt =
                srcType == ISrcFmt.U16 ||
                srcType == ISrcFmt.S16 ||
                srcType == ISrcFmt.U8 ||
                srcType == ISrcFmt.S8;

            // TODO: Handle S/U64.

            Operand srcB = context.IAbsNeg(src, absolute, negate);

            if (isSmallInt)
            {
                int size = srcType == ISrcFmt.U16 || srcType == ISrcFmt.S16 ? 16 : 8;

                srcB = isSignedInt
                    ? context.BitfieldExtractS32(srcB, Const((int)byteSelection * 8), Const(size))
                    : context.BitfieldExtractU32(srcB, Const((int)byteSelection * 8), Const(size));
            }

            if (dstType == DstFmt.F64)
            {
                srcB = isSignedInt
                    ? context.IConvertS32ToFP64(srcB)
                    : context.IConvertU32ToFP64(srcB);
            }
            else
            {
                srcB = isSignedInt
                    ? context.IConvertS32ToFP32(srcB)
                    : context.IConvertU32ToFP32(srcB);
            }

            WriteFP(context, dstType, srcB, rd);

            // TODO: CC.
        }
コード例 #2
0
        private static Operand UnpackImm(EmitterContext context, DstFmt floatType, bool h, int imm)
        {
            if (floatType == DstFmt.F32)
            {
                return(GetSrcImm(context, imm));
            }
            else if (floatType == DstFmt.F16)
            {
                return(GetHalfUnpacked(context, GetSrcImm(context, imm), HalfSwizzle.F16)[h ? 1 : 0]);
            }
            else if (floatType == DstFmt.F64)
            {
                return(GetSrcImm(context, imm, isFP64: true));
            }

            throw new ArgumentException($"Invalid floating point type \"{floatType}\".");
        }
コード例 #3
0
        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.
        }
コード例 #4
0
        private static void WriteFP(EmitterContext context, DstFmt type, Operand srcB, int rd)
        {
            Operand dest = GetDest(rd);

            if (type == DstFmt.F32)
            {
                context.Copy(dest, srcB);
            }
            else if (type == DstFmt.F16)
            {
                context.Copy(dest, context.PackHalf2x16(srcB, ConstF(0)));
            }
            else /* if (type == FPType.FP64) */
            {
                Operand dest2 = GetDest2(rd);

                context.Copy(dest, context.UnpackDouble2x32Low(srcB));
                context.Copy(dest2, context.UnpackDouble2x32High(srcB));
            }
        }
コード例 #5
0
 private static Instruction ToInstFPType(this DstFmt type)
 {
     return(type == DstFmt.F64 ? Instruction.FP64 : Instruction.FP32);
 }
コード例 #6
0
        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.
        }