Exemplo n.º 1
0
 public static bool CopySource(Mov src, ref InstructionWithDestinationAndSourceAndSize ins, bool assrc)
 {
     if (assrc && !src.DestinationEmpty)
     {
         ins.SourceReg   = src.SourceReg;
         ins.SourceValue = src.SourceValue;
         ins.SourceRef   = src.SourceRef;
         if (src.SourceReg.HasValue)
         {
             ins.Size = Registers.GetSize(src.SourceReg.Value);
         }
         ins.SourceDisplacement = src.SourceDisplacement;
         ins.SourceIsIndirect   = src.SourceIsIndirect;
         return(true);
     }
     else if (!src.DestinationEmpty)
     {
         ins.DestinationReg   = src.SourceReg;
         ins.DestinationValue = src.SourceValue;
         ins.DestinationRef   = src.SourceRef;
         if (src.SourceReg.HasValue)
         {
             ins.Size = Registers.GetSize(src.SourceReg.Value);
         }
         ins.DestinationDisplacement = src.SourceDisplacement;
         ins.DestinationIsIndirect   = src.SourceIsIndirect;
         return(true);
     }
     return(false);
 }
Exemplo n.º 2
0
 public static bool IsImmediate(InstructionWithDestinationAndSourceAndSize a, bool src)
 {
     if (src)
     {
         return(a.SourceValue.HasValue || (!a.SourceIsIndirect && a.SourceRef != null));
     }
     else
     {
         return(a.DestinationValue.HasValue || (!a.DestinationIsIndirect && a.DestinationRef != null));
     }
 }
Exemplo n.º 3
0
 public static bool BothIndirect(InstructionWithDestinationAndSourceAndSize a, InstructionWithDestinationAndSourceAndSize b, bool src)
 {
     if (src)
     {
         return(a.SourceIsIndirect && b.SourceIsIndirect);
     }
     else
     {
         return(b.DestinationIsIndirect && a.DestinationIsIndirect);
     }
 }
Exemplo n.º 4
0
        public bool Optimize(ref List <Instruction> src)
        {
            if (CurrentIndex < 1)
            {
                return(false);
            }
            if (!(src[CurrentIndex] is InstructionWithDestinationAndSourceAndSize))
            {
                return(false);
            }
            InstructionWithDestinationAndSourceAndSize Operator = src[CurrentIndex] as InstructionWithDestinationAndSourceAndSize;


            Move       = OptimizeUtils.GetLastMove(src, CurrentIndex - 1, ref MoveIdx);
            SecondMove = OptimizeUtils.GetLastMove(src, MoveIdx - 1, ref SecondMoveIdx);

            if (Move != null && SecondMove == null) // just a single mov
            {
                // optimize
                src[MoveIdx].Emit = false;           // eliminate mov
                OptimizeUtils.CopySource(Move, ref Operator, true);

                Optimizer.Optimizations     += 1;
                Optimizer.OptimizationsSize += 3;
                Optimizations++;
            }
            else if (Move != null && !OptimizeUtils.BothIndirect(Move, SecondMove, true) && !OptimizeUtils.IsImmediate(SecondMove, true)) // just a single mov (s
            {
                // optimize
                src[MoveIdx].Emit       = false; // eliminate mov
                src[SecondMoveIdx].Emit = false; // eliminate mov

                OptimizeUtils.CopySource(Move, ref Operator, true);
                OptimizeUtils.CopySource(SecondMove, ref Operator, false);

                Optimizer.Optimizations     += 2;
                Optimizer.OptimizationsSize += 6;
                Optimizations++;
            }
            else
            {
                return(false);
            }


            return(true);
        }