Example #1
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
                    });
                }
            }