Ejemplo n.º 1
0
        protected override void Compile(CodeContext c)
        {
            var dst = c.IntPtr("dst");
            var src = c.IntPtr("src");
            var cnt = c.UIntPtr("cnt");

            var loop = c.Label();             // Create base labels we use
            var exit = c.Label();             // in our function.

            c.SetArgument(0, dst);
            c.SetArgument(1, src);
            c.SetArgument(2, cnt);

            c.Allocate(dst);             // Allocate all registers now,
            c.Allocate(src);             // because we want to keep them
            c.Allocate(cnt);             // in physical registers only.

            c.Test(cnt, cnt);            // Exit if length is zero.
            c.Jz(exit);

            c.Bind(loop);             // Bind the loop label here.

            var tmp = c.Int32("tmp"); // Copy a single dword (4 bytes).

            c.Mov(tmp, Memory.DWord(src));
            c.Mov(Memory.DWord(dst), tmp);

            c.Add(src, 4);             // Increment dst/src pointers.
            c.Add(dst, 4);

            c.Dec(cnt);             // Loop until cnt isn't zero.
            c.Jnz(loop);

            c.Bind(exit);             // Bind the exit label here.
        }
Ejemplo n.º 2
0
        protected override void Compile(CodeContext c)
        {
            var l1 = c.Label();
            var l2 = c.Label();
            var l3 = c.Label();
            var l4 = c.Label();
            var l5 = c.Label();
            var l6 = c.Label();
            var l7 = c.Label();

            var v0 = c.UInt32("v0");
            var v1 = c.UInt32("v1");

            c.Bind(l2);
            c.Bind(l3);

            c.Jmp(l1);

            c.Bind(l5);
            c.Mov(v0, 0);

            c.Bind(l6);
            c.Jmp(l3);
            c.Mov(v1, 1);
            c.Jmp(l1);

            c.Bind(l4);
            c.Jmp(l2);
            c.Bind(l7);
            c.Add(v0, v1);

            c.Align(AligningMode.Code, 16);
            c.Bind(l1);
            c.Ret();
        }
Ejemplo n.º 3
0
        protected override void Compile(CodeContext c)
        {
            var v1 = c.Int32("v1");
            var v2 = c.Int32("v2");

            c.SetArgument(0, v1);
            c.SetArgument(1, v2);

            var l1 = c.Label();
            var l2 = c.Label();
            var l3 = c.Label();
            var l4 = c.Label();

            c.Jmp(l1);
            c.Bind(l2);
            c.Jmp(l4);
            c.Bind(l1);

            c.Cmp(v1, v2);
            c.Jg(l3);

            c.Mov(v1, 1);
            c.Jmp(l2);

            c.Bind(l3);
            c.Mov(v1, 2);
            c.Jmp(l2);

            c.Bind(l4);

            c.Ret(v1);
        }
Ejemplo n.º 4
0
        protected override void Compile(CodeContext c)
        {
            var v1 = c.Int32("v1");
            var v2 = c.Int32("v2");

            c.SetArgument(0, v1);
            c.SetArgument(1, v2);

            var counter = c.Int32("counter");

            var l1   = c.Label();
            var loop = c.Label();
            var exit = c.Label();

            c.Cmp(v1, v2);
            c.Jg(l1);

            c.Mov(counter, 0);

            c.Bind(loop);
            c.Mov(v1, counter);

            c.Inc(counter);
            c.Cmp(counter, 1);
            c.Jle(loop);
            c.Jmp(exit);

            c.Bind(l1);
            c.Mov(v1, 2);

            c.Bind(exit);
            c.Ret(v1);
        }
Ejemplo n.º 5
0
        protected override void Compile(CodeContext c)
        {
            var fn = c.IntPtr("fn");
            var a  = c.Int32("a");

            var fp = Memory.Fn(new Func <int, int, int, int, int, int, int, int, int, int, int>(CalledFunction));

            c.Mov(fn, fp);
            c.Mov(a, 3);

            var call = c.Call(fn, fp);

            call.SetArgument(0, a);
            call.SetArgument(1, a);
            call.SetArgument(2, a);
            call.SetArgument(3, a);
            call.SetArgument(4, a);
            call.SetArgument(5, a);
            call.SetArgument(6, a);
            call.SetArgument(7, a);
            call.SetArgument(8, a);
            call.SetArgument(9, a);
            call.SetReturn(0, a);

            c.Ret(a);
        }
Ejemplo n.º 6
0
        private static void GetBranchTarget(Instruction instruction, CodeContext context, GpRegister target)
        {
            var operand = instruction.Operands.First();

            switch (operand.Type)
            {
            case ud_type.UD_OP_REG:
                var maybeRegister = SdToAsm.SdToAsmJit(context, operand.Base);
                if (!maybeRegister.Present)
                {
                    throw new Exception("could not map register");
                }
                switch (maybeRegister.Type)
                {
                case RegisterType.GpRegister:
                    context.Mov(target, (GpRegister)maybeRegister.Register);
                    break;

                case RegisterType.SegRegister:
                    context.Mov(target, (SegRegister)maybeRegister.Register);
                    break;

                default:
                    throw new Exception("unsupported register");
                }
                break;

            case ud_type.UD_OP_MEM:
                CreateLea(context, target, instruction);
                break;

            case ud_type.UD_OP_JIMM:
                ulong immediate;
                ulong truncMask = 0xffffffffffffffff >> (64 - instruction.opr_mode);
                // Console.WriteLine($"opr_mode: {instruction.opr_mode}");
                switch (operand.Size)
                {
                case 8:
                    immediate = (instruction.PC + (ulong)operand.LvalSByte) & truncMask;
                    break;

                case 16:
                    immediate = (instruction.PC + (ulong)operand.LvalSWord) & truncMask;
                    break;

                case 32:
                    immediate = (instruction.PC + (ulong)operand.LvalSDWord) & truncMask;
                    break;

                default:
                    throw new Exception("invalid relative offset size.");
                }
                // in our emulator we are going to keep RIP in target (RAX)
                context.Lea(target, Memory.QWord(target, (int)immediate));
                break;

            default:
                throw new Exception("unsupported operand type");
            }
        }
Ejemplo n.º 7
0
        protected override void Compile(CodeContext c)
        {
            var v0 = c.Int32("v0");
            var v1 = c.Int32("v1");

            var c0 = c.Int32Const(ConstantScope.Local, 200);
            var c1 = c.Int32Const(ConstantScope.Local, 33);

            c.Mov(v0, c0);
            c.Mov(v1, c1);
            c.Add(v0, v1);

            c.Ret(v0);
        }
Ejemplo n.º 8
0
        protected override void Compile(CodeContext c)
        {
            const int count = 8;

            var a0 = c.IntPtr("a0");
            var a1 = c.IntPtr("a1");

            c.SetArgument(0, a0);
            c.SetArgument(1, a1);

            // Create some variables.
            var t = c.Int32("t");
            var x = new GpVariable[count];

            int i;

            for (i = 0; i < count; i++)
            {
                x[i] = c.Int32("x" + i);
            }

            // Setup variables (use mov with reg/imm to se if register allocator works).
            for (i = 0; i < count; i++)
            {
                c.Mov(x[i], i + 1);
            }

            // Make sum (addition).
            c.Xor(t, t);
            for (i = 0; i < count; i++)
            {
                c.Add(t, x[i]);
            }

            // Store result to a given pointer in first argument.
            c.Mov(Memory.DWord(a0), t);

            // Clear t.
            c.Xor(t, t);

            // Make sum (subtraction).
            for (i = 0; i < count; i++)
            {
                c.Sub(t, x[i]);
            }

            // Store result to a given pointer in second argument.
            c.Mov(Memory.DWord(a1), t);
        }
Ejemplo n.º 9
0
        protected override void Compile(CodeContext c)
        {
            var fn = c.IntPtr("fn");
            var rv = c.Int32("rv");

            var fp = Memory.Fn(new Func <IntPtr, IntPtr, IntPtr, IntPtr, IntPtr, IntPtr, IntPtr, IntPtr, IntPtr, IntPtr, int>(CalledFunction));

            c.Mov(fn, fp);

            var call = c.Call(fn, fp);

            call.SetArgument(0, 1);
            call.SetArgument(1, 2);
            call.SetArgument(2, 3);
            call.SetArgument(3, 4);
            call.SetArgument(4, 5);
            call.SetArgument(5, 6);
            call.SetArgument(6, 7);
            call.SetArgument(7, 8);
            call.SetArgument(8, 9);
            call.SetArgument(9, 10);
            call.SetReturn(0, rv);

            c.Ret(rv);
        }
Ejemplo n.º 10
0
        protected override void Compile(CodeContext c)
        {
            var fn = c.IntPtr("fn");
            var rv = c.Int32("rv");

            var fp = Memory.Fn(new Func <int, int, int, int, int, int, int, int, int, int, int>(CalledFunction));

            c.Mov(fn, fp);

            var call = c.Call(fn, fp);

            call.SetArgument(0, 0x03);
            call.SetArgument(1, 0x12);
            call.SetArgument(2, 0xA0);
            call.SetArgument(3, 0x0B);
            call.SetArgument(4, 0x2F);
            call.SetArgument(5, 0x02);
            call.SetArgument(6, 0x0C);
            call.SetArgument(7, 0x12);
            call.SetArgument(8, 0x18);
            call.SetArgument(9, 0x1E);
            call.SetReturn(0, rv);

            c.Ret(rv);
        }
Ejemplo n.º 11
0
        protected override void Compile(CodeContext c)
        {
            var v0 = c.Int32("v0");
            var v1 = c.Int32("v1");
            var v2 = c.Int32("v2");

            c.SetArgument(0, v0);
            c.SetArgument(1, v1);
            c.SetArgument(2, v2);

            var fp = Memory.Fn(new Func <int, int, int, int>(CalledFunction));

            // Just do something.
            c.Shl(v0, 1);
            c.Shl(v1, 1);
            c.Shl(v2, 1);

            var fn = c.IntPtr("fn");

            c.Mov(fn, fp);

            var call = c.Call(fn, fp);

            call.SetArgument(0, v2);
            call.SetArgument(1, v1);
            call.SetArgument(2, v0);
            call.SetReturn(0, v0);

            c.Ret(v0);
        }
Ejemplo n.º 12
0
        protected override void Compile(CodeContext c)
        {
            var stack = c.Stack(256, 1).SetSize(1);
            var i     = c.IntPtr("i");
            var a     = c.Int32("a");
            var b     = c.Int32("b");

            var l1 = c.Label();
            var l2 = c.Label();

            // Fill stack by sequence [0, 1, 2, 3 ... 255].
            c.Xor(i, i);

            c.Bind(l1);
            c.Mov(stack.Clone().SetIndex(i), i.As8());
            c.Inc(i);
            c.Cmp(i, 255);
            c.Jle(l1);

            // Sum sequence in stack.
            c.Xor(i, i);
            c.Xor(a, a);

            c.Bind(l2);
            c.Movzx(b, stack.Clone().SetIndex(i));
            c.Add(a, b);
            c.Inc(i);
            c.Cmp(i, 255);
            c.Jle(l2);

            c.Ret(a);
        }
Ejemplo n.º 13
0
        protected override void Compile(CodeContext c)
        {
            var dstHi = c.IntPtr("dstHi");
            var dstLo = c.IntPtr("dstLo");
            var vLo   = c.Int32("vLo");
            var src   = c.Int32("src");

            c.SetArgument(0, dstHi);
            c.SetArgument(1, dstLo);
            c.SetArgument(2, vLo);
            c.SetArgument(3, src);

            var vHi = c.Int32("vHi");

            c.Imul(vHi, vLo, src);

            c.Mov(Memory.DWord(dstHi), vHi);
            c.Mov(Memory.DWord(dstLo), vLo);
        }
Ejemplo n.º 14
0
        protected override void Compile(CodeContext c)
        {
            var l1 = c.Label();
            var l2 = c.Label();

            var v0 = c.UInt32("v0");
            var v1 = c.UInt32("v1");

            c.Jmp(l1);
            c.Bind(l2);
            c.Mov(v0, 1);
            c.Mov(v1, 2);
            c.Cmp(v0, v1);
            c.Jz(l2);
            c.Jmp(l1);

            c.Bind(l1);
            c.Ret();
        }
Ejemplo n.º 15
0
 protected override void Compile(CodeContext c)
 {
     c.Push(c.Ebp);
     c.Mov(c.Ebp, c.Esp);
     c.Sub(c.Esp, 192);
     c.Push(c.Ebx);
     c.Push(c.Esi);
     c.Push(c.Edi);
     c.Lea(c.Edi, Memory.DWord(c.Ebp, -192));
     c.Mov(c.Ecx, 48);
     c.Mov(c.Eax, -858993460);
     c.RepStosd();
     c.Mov(c.Eax, Memory.DWord(c.Ebp, 8));
     c.Add(c.Eax, Memory.DWord(c.Ebp, 12));
     c.Pop(c.Edi);
     c.Pop(c.Esi);
     c.Pop(c.Ebx);
     c.Mov(c.Esp, c.Ebp);
     c.Pop(c.Ebp);
     c.Ret(8);
 }
Ejemplo n.º 16
0
        protected override void Compile(CodeContext c)
        {
            var rPtr = c.UIntPtr("rPtr");
            var rSum = c.UInt32("rSum");

            c.SetArgument(0, rPtr);

            var rVar = new GpVariable[Cnt];
            int i;

            for (i = 0; i < Cnt; i++)
            {
                rVar[i] = c.UInt32("x" + i);
            }
            // Init pseudo-regs with values from our array.
            for (i = 0; i < Cnt; i++)
            {
                c.Mov(rVar[i], Memory.DWord(rPtr, i * 4));
            }

            for (i = 2; i < Cnt; i++)
            {
                // Add and truncate to 8 bit; no purpose, just mess with jit.
                c.Add(rVar[i], rVar[i - 1]);
                c.Movzx(rVar[i], rVar[i].As8());
                c.Movzx(rVar[i - 2], rVar[i - 1].As8());
                c.Movzx(rVar[i - 1], rVar[i - 2].As8());
            }

            // Sum up all computed values.
            c.Mov(rSum, 0);
            for (i = 0; i < Cnt; i++)
            {
                c.Add(rSum, rVar[i]);
            }

            // Return the sum.
            c.Ret(rSum);
        }
Ejemplo n.º 17
0
        protected override void Compile(CodeContext c)
        {
            var v0 = c.Int32("v0");
            var v1 = c.Int32("v1");
            var v2 = c.Int32("v2");
            var v3 = c.Int32("v3");
            var v4 = c.Int32("v4");

            c.Xor(v0, v0);

            c.Mov(v1, 1);
            c.Mov(v2, 2);
            c.Mov(v3, 3);
            c.Mov(v4, 4);

            c.Add(v0, v1);
            c.Add(v0, v2);
            c.Add(v0, v3);
            c.Add(v0, v4);

            c.Ret(v0);
        }
Ejemplo n.º 18
0
        protected override void Compile(CodeContext c)
        {
            var var = new GpVariable[32];

            var a = c.IntPtr("a");

            c.SetArgument(0, a);

            int i;

            for (i = 0; i < var.Length; i++)
            {
                var[i] = c.Int32("var" + i);
            }

            for (i = 0; i < var.Length; i++)
            {
                c.Xor(var[i], var[i]);
            }

            var v0 = c.Int32("v0");
            var l  = c.Label();

            c.Mov(v0, 32);
            c.Bind(l);

            for (i = 0; i < var.Length; i++)
            {
                c.Add(var[i], i);
            }

            c.Dec(v0);
            c.Jnz(l);

            for (i = 0; i < var.Length; i++)
            {
                c.Mov(Memory.DWord(a, i * 4), var[i]);
            }
        }
Ejemplo n.º 19
0
        protected override void Compile(CodeContext c)
        {
            var dst = c.IntPtr("dst");
            var src = c.IntPtr("src");

            c.SetArgument(0, dst);
            c.SetArgument(1, src);

            for (var i = 0; i < 4; i++)
            {
                var x  = c.Int32("x");
                var y  = c.Int32("y");
                var hi = c.Int32("hi");

                c.Mov(x, Memory.DWord(src, 0));
                c.Mov(y, Memory.DWord(src, 4));

                c.Imul(hi, x, y);
                c.Add(Memory.DWord(dst, 0), hi);
                c.Add(Memory.DWord(dst, 4), x);
            }
        }
Ejemplo n.º 20
0
        protected override void Compile(CodeContext c)
        {
            var l1 = c.Label();

            var iIdx = c.Int32("iIdx");
            var iEnd = c.Int32("iEnd");

            var aIdx = c.Int32("aIdx");
            var aEnd = c.Int32("aEnd");

            c.SetArgument(0, aIdx);
            c.SetArgument(1, aEnd);

            c.Mov(iIdx, aIdx);
            c.Mov(iEnd, aEnd);
            c.Spill(iEnd);

            c.Bind(l1);
            c.Inc(iIdx);
            c.Cmp(iIdx, iEnd.ToMemory());
            c.Jne(l1);

            c.Ret(iIdx);
        }
Ejemplo n.º 21
0
//		[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
//		delegate int CalledFunctionDel(int x, int y);

        protected override void Compile(CodeContext c)
        {
            var x  = c.Int32("x");
            var y  = c.Int32("y");
            var op = c.Int32("op");

            c.SetArgument(0, x);
            c.SetArgument(1, y);
            c.SetArgument(2, op);

            var opAdd = c.Label();
            var opMul = c.Label();

            c.Cmp(op, 0);
            c.Jz(opAdd);
            c.Cmp(op, 1);
            c.Jz(opMul);

            var result = c.Int32("result_0");

            c.Mov(result, 0);
            c.Ret(result);

            c.Bind(opAdd);
            result = c.Int32("result_1");

//			CalledFunctionDel f = CalledFunctionAdd;
//			var call = c.Call(Memory.Fn(f));
            var call = c.Call(Memory.Fn(new Func <int, int, int>(CalledFunctionAdd)));

            call.SetArgument(0, x);
            call.SetArgument(1, y);
            call.SetReturn(0, result);
            c.Ret(result);

            c.Bind(opMul);
            result = c.Int32("result_2");

//			f = CalledFunctionMul;
//			call = c.Call(Memory.Fn(f));
            call = c.Call(Memory.Fn(new Func <int, int, int>(CalledFunctionMul)));
            call.SetArgument(0, x);
            call.SetArgument(1, y);
            call.SetReturn(0, result);

            c.Ret(result);
        }
Ejemplo n.º 22
0
        protected override void Compile(CodeContext c)
        {
            var dst       = c.IntPtr("dst");
            var var       = c.Int32("var");
            var vShlParam = c.Int32("vShlParam");
            var vRorParam = c.Int32("vRorParam");

            c.SetArgument(0, dst);
            c.SetArgument(1, var);
            c.SetArgument(2, vShlParam);
            c.SetArgument(3, vRorParam);

            c.Shl(var, vShlParam);
            c.Ror(var, vRorParam);

            c.Mov(Memory.DWord(dst), var);
        }
Ejemplo n.º 23
0
        protected override void Compile(CodeContext c)
        {
            var p  = c.IntPtr("p");
            var fn = c.IntPtr("fn");

            var arg = c.XmmSd("arg");
            var ret = c.XmmSd("ret");

            var fp = Memory.Fn(new Func <double, double>(CalledFunction));

            c.SetArgument(0, p);
            c.Movsd(arg, Memory.Ptr(p));
            c.Mov(fn, fp);

            var call = c.Call(fn, fp);

            call.SetArgument(0, arg);
            call.SetReturn(0, ret);

            c.Ret(ret);
        }
Ejemplo n.º 24
0
        protected override void Compile(CodeContext c)
        {
            var fn  = c.IntPtr("fn");
            var a   = c.XmmSd("a");
            var b   = c.XmmSd("b");
            var ret = c.XmmSd("ret");

            c.SetArgument(0, a);
            c.SetArgument(1, b);

            var fp = Memory.Fn(new Func <double, double, double>(CalledFunction));

            c.Mov(fn, fp);

            var call = c.Call(fn, fp);

            call.SetArgument(0, a);
            call.SetArgument(1, b);
            call.SetReturn(0, ret);

            c.Ret(ret);
        }
Ejemplo n.º 25
0
        protected override void Compile(CodeContext c)
        {
            var var = c.Int32("var");
            var fn  = c.IntPtr("fn");

            c.SetArgument(0, var);

            var fp = Memory.Fn(new Func <int, int>(CalledFunction) /*, CallingConvention.HostDefaultFast*/);

            c.Mov(fn, fp);

            var call = c.Call(fn, fp);

            call.SetArgument(0, var);
            call.SetReturn(0, var);

            call = c.Call(fn, fp);
            call.SetArgument(0, var);
            call.SetReturn(0, var);

            c.Ret(var);
        }
Ejemplo n.º 26
0
        protected override void Compile(CodeContext c)
        {
            var v0  = c.Int32("v0");
            var v1  = c.Int32("v1");
            var cnt = c.Int32("cnt");

            c.Xor(v0, v0);
            c.Xor(v1, v1);
            c.Spill(v0);
            c.Spill(v1);

            var l = c.Label();

            c.Mov(cnt, 32);
            c.Bind(l);

            c.Inc(v1);
            c.Add(v0, v1);

            c.Dec(cnt);
            c.Jnz(l);

            c.Ret(v0);
        }
Ejemplo n.º 27
0
        protected override void Compile(CodeContext c)
        {
            int i;

            var buf  = c.IntPtr("buf");
            var acc0 = c.Int32("acc0");
            var acc1 = c.Int32("acc1");

            c.SetArgument(0, buf);

            c.Mov(acc0, 0);
            c.Mov(acc1, 0);

            for (i = 0; i < 4; i++)
            {
                var ret = c.Int32("ret");
                var ptr = c.IntPtr("ptr");
                var idx = c.Int32("idx");

                c.Mov(ptr, buf);
                c.Mov(idx, i);

                var call = c.Call(Memory.Fn(new Func <IntPtr, int, int>(CalledFunction) /*, CallingConvention.HostDefaultFast*/));
                call.SetArgument(0, ptr);
                call.SetArgument(1, idx);
                call.SetReturn(0, ret);

                c.Add(acc0, ret);

                c.Mov(ptr, buf);
                c.Mov(idx, i);

                call = c.Call(Memory.Fn(new Func <IntPtr, int, int>(CalledFunction) /*, CallingConvention.HostDefaultFast*/));
                call.SetArgument(0, ptr);
                call.SetArgument(1, idx);
                call.SetReturn(0, ret);

                c.Sub(acc1, ret);
            }

            c.Add(acc0, acc1);
            c.Ret(acc0);
        }
Ejemplo n.º 28
0
        protected override void Compile(CodeContext c)
        {
            var dst = c.IntPtr("dst");
            var src = c.IntPtr("src");

            var i = c.IntPtr("i");
            var j = c.IntPtr("j");
            var t = c.IntPtr("t");

            var cZero    = c.Xmm("cZero");
            var cMul255A = c.Xmm("cMul255A");
            var cMul255M = c.Xmm("cMul255M");

            var x0 = c.Xmm("x0");
            var x1 = c.Xmm("x1");
            var y0 = c.Xmm("y0");
            var a0 = c.Xmm("a0");
            var a1 = c.Xmm("a1");

            var smallLoop = c.Label();
            var smallEnd  = c.Label();

            var largeLoop = c.Label();
            var largeEnd  = c.Label();

            var data = c.Label();

            c.SetArgument(0, dst);
            c.SetArgument(1, src);
            c.SetArgument(2, i);

            c.Allocate(dst);
            c.Allocate(src);
            c.Allocate(i);

            // How many pixels have to be processed to make the loop aligned.
            c.Lea(t, Memory.Ptr(data));
            c.Xor(j, j);
            c.Xorps(cZero, cZero);

            c.Sub(j, dst);
            c.Movaps(cMul255A, Memory.Ptr(t, 0));

            c.And(j, 15);
            c.Movaps(cMul255M, Memory.Ptr(t, 16));

            c.Shr(j, 2);
            c.Jz(smallEnd);

            // j = min(i, j).
            c.Cmp(j, i);
            c.Cmovg(j, i);

            // i -= j.
            c.Sub(i, j);

            // Small loop.
            c.Bind(smallLoop);

            c.Pcmpeqb(a0, a0);
            c.Movd(y0, Memory.Ptr(src));

            c.Pxor(a0, y0);
            c.Movd(x0, Memory.Ptr(dst));

            c.Psrlw(a0, 8);
            c.Punpcklbw(x0, cZero);

            c.Pshuflw(a0, a0, AsmJit.Common.Utils.Shuffle(1, 1, 1, 1));
            c.Punpcklbw(y0, cZero);

            c.Pmullw(x0, a0);
            c.Paddsw(x0, cMul255A);
            c.Pmulhuw(x0, cMul255M);

            c.Paddw(x0, y0);
            c.Packuswb(x0, x0);

            c.Movd(Memory.Ptr(dst), x0);

            c.Add(dst, 4);
            c.Add(src, 4);

            c.Dec(j);
            c.Jnz(smallLoop);

            // Second section, prepare for an aligned loop.
            c.Bind(smallEnd);

            c.Test(i, i);
            c.Mov(j, i);
            c.Jz(c.Exit);

            c.And(j, 3);
            c.Shr(i, 2);
            c.Jz(largeEnd);

            // Aligned loop.
            c.Bind(largeLoop);

            c.Movups(y0, Memory.Ptr(src));
            c.Pcmpeqb(a0, a0);
            c.Movaps(x0, Memory.Ptr(dst));

            c.Xorps(a0, y0);
            c.Movaps(x1, x0);

            c.Psrlw(a0, 8);
            c.Punpcklbw(x0, cZero);

            c.Movaps(a1, a0);
            c.Punpcklwd(a0, a0);

            c.Punpckhbw(x1, cZero);
            c.Punpckhwd(a1, a1);

            c.Pshufd(a0, a0, AsmJit.Common.Utils.Shuffle(3, 3, 1, 1));
            c.Pshufd(a1, a1, AsmJit.Common.Utils.Shuffle(3, 3, 1, 1));

            c.Pmullw(x0, a0);
            c.Pmullw(x1, a1);

            c.Paddsw(x0, cMul255A);
            c.Paddsw(x1, cMul255A);

            c.Pmulhuw(x0, cMul255M);
            c.Pmulhuw(x1, cMul255M);

            c.Add(src, 16);
            c.Packuswb(x0, x1);

            c.Paddw(x0, y0);
            c.Movaps(Memory.Ptr(dst), x0);

            c.Add(dst, 16);

            c.Dec(i);
            c.Jnz(largeLoop);

            c.Bind(largeEnd);
            c.Test(j, j);
            c.Jnz(smallLoop);

            // Data
            c.Data(data, 16,
                   Data.Of(0x0080008000800080, 0x0080008000800080),
                   Data.Of(0x0101010101010101, 0x0080008000800080));
        }
Ejemplo n.º 29
0
        protected override void Compile(CodeContext c)
        {
            var fn = c.IntPtr("fn");
            var va = c.Int32("va");
            var vb = c.Int32("vb");
            var vc = c.Int32("vc");
            var vd = c.Int32("vd");
            var ve = c.Int32("ve");
            var vf = c.Int32("vf");
            var vg = c.Int32("vg");
            var vh = c.Int32("vh");
            var vi = c.Int32("vi");
            var vj = c.Int32("vj");

            var fp = Memory.Fn(new Func <int, int, int, int, int, int, int, int, int, int, int>(CalledFunction));

            c.Mov(fn, fp);
            c.Mov(va, 0x03);
            c.Mov(vb, 0x12);
            c.Mov(vc, 0xA0);
            c.Mov(vd, 0x0B);
            c.Mov(ve, 0x2F);
            c.Mov(vf, 0x02);
            c.Mov(vg, 0x0C);
            c.Mov(vh, 0x12);
            c.Mov(vi, 0x18);
            c.Mov(vj, 0x1E);

            var call = c.Call(fn, fp);

            call.SetArgument(0, va);
            call.SetArgument(1, vb);
            call.SetArgument(2, vc);
            call.SetArgument(3, vd);
            call.SetArgument(4, ve);
            call.SetArgument(5, vf);
            call.SetArgument(6, vg);
            call.SetArgument(7, vh);
            call.SetArgument(8, vi);
            call.SetArgument(9, vj);
            call.SetReturn(0, va);

            c.Ret(va);
        }