コード例 #1
0
            public static Tile Reg_Const()
            {
                return(new Tile(typeof(AssignmentNode),
                                new[] {
                    makeTile <RegisterNode> (),
                    makeTile <ConstantNode <long> > ()
                },
                                (regNode, node) => {
                    var root = node as AssignmentNode;
                    var target = root.Target as RegisterNode;
                    var valNode = root.Source as ConstantNode <long>;

                    if (valNode.Value == 0L)
                    {
                        return new [] {
                            InstructionFactory.Xor(target, target),
                            InstructionFactory.Move(regNode, target)
                        };
                    }
                    else
                    {
                        return new [] {
                            InstructionFactory.Move(target, valNode),
                            InstructionFactory.Move(regNode, target)
                        };
                    }
                }
                                ));
            }
コード例 #2
0
 public static Tile ConstReg()
 {
     return(makeBinopTile <LogAndOperatorNode, ConstantNode <long>, RegisterNode> (
                (regNode, left, right) => left.Value == 0L
                             ? new[] { InstructionFactory.Xor(regNode, regNode) }   // l == 0 -> all = 0
                             : new[] { InstructionFactory.Move(regNode, right) }    // l != 0 -> all = r
                ));
 }
コード例 #3
0
 public static Tile RegConst()
 {
     return(makeBinopTile <LogAndOperatorNode, RegisterNode, ConstantNode <long> > (
                (regNode, left, right) => right.Value == 0L
                             ? new[] { InstructionFactory.Xor(regNode, regNode) }  // r == 0 -> all = 0
                             : new[] { InstructionFactory.Move(regNode, left) }    // r != 0 -> all = l
                ));
 }
コード例 #4
0
 // -x = 0-x
 public static Tile Minus_Reg()
 {
     return(makeUnopTile <UnaryMinusOperatorNode, RegisterNode> (
                (regNode, root, left) => new [] {
         InstructionFactory.Xor(regNode, regNode),
         InstructionFactory.Sub(regNode, left),
     }
                ));
 }
コード例 #5
0
 public static Tile ConstReg <T>()
 {
     return(makeBinopTile <ModOperatorNode, ConstantNode <T>, RegisterNode> (
                (regNode, left, right) => new[] {
         InstructionFactory.Xor(Target.RDX, Target.RDX),                              // RDX = 0
         InstructionFactory.Move(Target.RAX, left),                                   // RDX:RAX = left
         InstructionFactory.Div(right),                                               // RDX = left % right
         InstructionFactory.Move(regNode, Target.RDX)                                 // result = RDX
     }
                ));
 }
コード例 #6
0
 public static Tile RegReg()
 {
     return(makeBinopTile <DivOperatorNode, RegisterNode, RegisterNode> (
                (regNode, left, right) => new[] {
         InstructionFactory.Xor(Target.RDX, Target.RDX),                              // RDX = 0
         InstructionFactory.Move(Target.RAX, left),                                   // RDX:RAX = left
         InstructionFactory.Div(right),                                               // RAX = left / right
         InstructionFactory.Move(regNode, Target.RAX)                                 // result = RAX
     }
                ));
 }
コード例 #7
0
 public static Tile RegReg()
 {
     // l = 0            ->  first instruction sets reg to 0
     // r = 0 but l > 0  ->  fourth instruction sets reg to 0
     // l > 0 and r > 0  ->  first instruction sets reg = l > 0 and nothing changes
     return(makeBinopTile <LogAndOperatorNode, RegisterNode, RegisterNode> (
                (regNode, left, right) => new[] {
         InstructionFactory.Move(regNode, left),                                // reg = left
         InstructionFactory.Xor(left, left),                                    // left = 0
         InstructionFactory.Cmp(right, left),                                   // if right == 0
         InstructionFactory.Cmove(regNode, left)                                // then reg = 0
     }
                ));
 }
コード例 #8
0
            static IEnumerable <Instruction> EffectiveMultiplication(RegisterNode dst, RegisterNode mul_reg, ConstantNode <long> mul_val)
            {
                switch (mul_val.Value)
                {
                case 2L:
                case 4L:
                case 8L:
                    return(new [] {
                        InstructionFactory.Lea_Mul(dst, mul_reg, mul_val)
                    });

                case 3L:
                case 5L:
                case 9L:
                    var tmp_val = new ConstantNode <long> (mul_val.Value - 1L);
                    return(new [] {
                        InstructionFactory.Lea_MulAdd(dst, mul_reg, tmp_val, mul_reg)
                    });

                case 1L:
                    return(new [] {
                        InstructionFactory.Move(dst, mul_reg)
                    });

                case 0L:
                    return(new [] {
                        InstructionFactory.Xor(dst, dst)
                    });

                default:
                    // dst = mul_reg * mul_val
                    return(new [] {
                        InstructionFactory.Move(Target.RAX, mul_val),                          // RAX = mul_val
                        InstructionFactory.Mul(mul_reg),                                       // RDX:RAX = mul_reg * mul_val
                        InstructionFactory.Move(dst, Target.RAX)                               // dst = RAX
                    });
                }
            }