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); }
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); }