Esempio n. 1
0
        /// <summary>
        /// Multiplies two operands.
        /// </summary>
        /// <returns>Result of operation.</returns>
        public void Mul(Operand in1, Operand in2, Operand outOp)
        {
            if (in1.IsArray || !in1.Equals(in2) || !in1.Equals(outOp) || !outOp.IsWritable)
            {
                throw new IncompatibleOperandsException("Addition operation requires both formats to be the same.");
            }

            // We check if we can precache it, this is copy only op.
            if (in1.IsFixed && in2.IsFixed)
            {
                Operand tmp = CreateFixed(in1.Format, in1.ArraySize, Math.MathHelper.Mul(in1.Value, in2.Value));

                // We must create a mem copy.
                compiler.Mov(tmp.Name, outOp.Name);

                return;
            }

            PinFormat dummy;

            // Special matrix-* or *-matrix multiplication.
            if (PinFormatHelper.IsMatrix(in1.Format, out dummy) ||
                PinFormatHelper.IsMatrix(in2.Format, out dummy))
            {
                compiler.MulEx(in1.Name, in2.Name, outOp.Name);
            }
            else
            {
                compiler.Mul(in1.Name, in2.Name, outOp.Name);
            }
        }
Esempio n. 2
0
        protected override Pin[] CreateOutputs()
        {
            // We search for vector-* and *-vector operations.
            PinFormat scalar;

            if (PinFormatHelper.IsVector(inputs[0].Format, out scalar))
            {
                // The result must be matrix.
                return(new Pin[] { inputs[0].Clone(this) });
            }
            if (PinFormatHelper.IsVector(inputs[1].Format, out scalar))
            {
                return(new Pin[] { inputs[1].Clone(this) });
            }

            // We search for matrix-* and *-matrix operations.
            if (PinFormatHelper.IsMatrix(inputs[0].Format, out scalar))
            {
                // The result must be matrix.
                return(new Pin[] { inputs[0].Clone(this) });
            }
            if (PinFormatHelper.IsMatrix(inputs[1].Format, out scalar))
            {
                // The result must be matrix.
                return(new Pin[] { inputs[1].Clone(this) });
            }

            // Must be equal, we simply output.
            return(new Pin[] { inputs[0].Clone(this) });
        }
Esempio n. 3
0
        /// <summary>
        /// Multiplies two operands.
        /// </summary>
        public Operand Mul(Operand in1, Operand in2)
        {
            // TODO: validation.

            PinFormat outFmt = in1.Format;

            // Same format.
            if (in1.Format == in2.Format)
            {
                outFmt = in1.Format;
            }
            // Matrix x vector.
            else if (in1.Format == PinFormat.Float4x4 && in2.Format == PinFormat.Floatx4)
            {
                outFmt = PinFormat.Floatx4;
            }
            // By scalar.
            else if (in1.Format == PinFormat.Float)
            {
                outFmt = in2.Format;
            }
            else if (in2.Format == PinFormat.Float)
            {
                outFmt = in1.Format;
            }
            else
            {
                throw new NotSupportedException();
            }

            // We check if we can precache it, this is copy only op.
            if (in1.IsFixed && in2.IsFixed)
            {
                return(CreateFixed(outFmt, in1.ArraySize, Math.MathHelper.Mul(in1.Value, in2.Value)));
            }



            // Else create temp and return.
            Operand   tmp = CreateTemporary(outFmt, in1.ArraySize);
            PinFormat dummy;

            // Special matrix-* or *-matrix multiplication.
            if (PinFormatHelper.IsMatrix(in1.Format, out dummy) ||
                PinFormatHelper.IsMatrix(in2.Format, out dummy))
            {
                compiler.MulEx(in1.Name, in2.Name, tmp.Name);
            }
            else
            {
                compiler.Mul(in1.Name, in2.Name, tmp.Name);
            }
            return(tmp);
        }