예제 #1
0
  virtual void compile(X86Compiler& c)
  {
    c.newFunc(kX86FuncConvCompatFastCall, FuncBuilder1<int, int*>());
    c.getFunc()->setHint(kFuncHintNaked, true);

    GpVar buf(c.getGpArg(0));
    GpVar acc0(c.newGpVar(kX86VarTypeGpd));
    GpVar acc1(c.newGpVar(kX86VarTypeGpd));

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

    uint i;
    for (i = 0; i < 4; i++)
    {
      {
        GpVar ret = c.newGpVar(kX86VarTypeGpd);
        GpVar ptr = c.newGpVar(kX86VarTypeGpz);
        GpVar idx = c.newGpVar(kX86VarTypeGpd);

        c.mov(ptr, buf);
        c.mov(idx, imm(i));

        X86CompilerFuncCall* fCall = c.call((void*)calledFunc);
        fCall->setPrototype(kX86FuncConvCompatFastCall, FuncBuilder2<int, int*, int>());
        fCall->setArgument(0, ptr);
        fCall->setArgument(1, idx);
        fCall->setReturn(ret);

        c.add(acc0, ret);
      }

      {
        GpVar ret = c.newGpVar(kX86VarTypeGpd);
        GpVar ptr = c.newGpVar(kX86VarTypeGpz);
        GpVar idx = c.newGpVar(kX86VarTypeGpd);

        c.mov(ptr, buf);
        c.mov(idx, imm(i));

        X86CompilerFuncCall* fCall = c.call((void*)calledFunc);
        fCall->setPrototype(kX86FuncConvCompatFastCall, FuncBuilder2<int, int*, int>());
        fCall->setArgument(0, ptr);
        fCall->setArgument(1, idx);
        fCall->setReturn(ret);

        c.sub(acc1, ret);
      }
    }

    GpVar ret(c.newGpVar());
    c.mov(ret, acc0);
    c.add(ret, acc1);
    c.ret(ret);
    c.endFunc();
  }
예제 #2
0
  virtual void compile(X86Compiler& c)
  {
    c.newFunc(kX86FuncConvDefault, FuncBuilder2<Void, int*, int*>());

    // Function arguments.
    GpVar a1(c.getGpArg(0));
    GpVar a2(c.getGpArg(1));

    // Create some variables.
    GpVar x1(c.newGpVar(kX86VarTypeGpd));
    GpVar x2(c.newGpVar(kX86VarTypeGpd));
    GpVar x3(c.newGpVar(kX86VarTypeGpd));
    GpVar x4(c.newGpVar(kX86VarTypeGpd));
    GpVar x5(c.newGpVar(kX86VarTypeGpd));
    GpVar x6(c.newGpVar(kX86VarTypeGpd));
    GpVar x7(c.newGpVar(kX86VarTypeGpd));
    GpVar x8(c.newGpVar(kX86VarTypeGpd));

    GpVar t(c.newGpVar(kX86VarTypeGpd));

    // Setup variables (use mov with reg/imm to se if register allocator works).
    c.mov(x1, 1);
    c.mov(x2, 2);
    c.mov(x3, 3);
    c.mov(x4, 4);
    c.mov(x5, 5);
    c.mov(x6, 6);
    c.mov(x7, 7);
    c.mov(x8, 8);

    // Make sum (addition).
    c.xor_(t, t);
    c.add(t, x1);
    c.add(t, x2);
    c.add(t, x3);
    c.add(t, x4);
    c.add(t, x5);
    c.add(t, x6);
    c.add(t, x7);
    c.add(t, x8);

    // Store result to a given pointer in first argument.
    c.mov(dword_ptr(a1), t);

    // Make sum (subtraction).
    c.xor_(t, t);
    c.sub(t, x1);
    c.sub(t, x2);
    c.sub(t, x3);
    c.sub(t, x4);
    c.sub(t, x5);
    c.sub(t, x6);
    c.sub(t, x7);
    c.sub(t, x8);

    // Store result to a given pointer in second argument.
    c.mov(dword_ptr(a2), t);

    // End of function.
    c.endFunc();
  }