Exemplo n.º 1
0
static bool
storeGeneric(PPCEmuAssembler& a, Instruction instr)
{
   if (flags & StoreConditional) {
      // Early out for if statement below.
      return jit_fallback(a, instr);
   }

   if ((flags & StoreZeroRA) && instr.rA == 0) {
      if (flags & StoreIndexed) {
         a.mov(a.ecx, a.ppcgpr[instr.rB]);
      } else {
         a.mov(a.ecx, sign_extend<16, int32_t>(instr.d));
      }
   } else {
      a.mov(a.ecx, a.ppcgpr[instr.rA]);

      if (flags & StoreIndexed) {
         a.add(a.ecx, a.ppcgpr[instr.rB]);
      } else {
         a.add(a.ecx, sign_extend<16, int32_t>(instr.d));
      }
   }

   if (flags & StoreConditional) {
      /*
      state->cr.cr0 = state->xer.so ? ConditionRegisterFlag::SummaryOverflow : 0;

      if (state->reserve) {
      // Store is succesful, clear reserve bit and set CR0[EQ]
      state->cr.cr0 |= ConditionRegisterFlag::Equal;
      state->reserve = false;
      } else {
      // Reserve bit is not set, do not write.
      return;
      }
      */
   }

   a.mov(a.zdx, a.zcx);
   a.add(a.zdx, a.membase);

   if (flags & StoreFloatAsInteger) {
      assert(sizeof(Type) == 4);
      a.mov(a.eax, a.ppcfprps[instr.rS][0]);
   } else if (std::is_floating_point<Type>::value) {
      if (flags & StoreSingle) {
         assert(sizeof(Type) == 4);
         a.mov(a.eax, a.ppcfprps[instr.rS][0]);
      }
      else {
         assert(sizeof(Type) == 8);
         a.mov(a.zax, a.ppcfpr[instr.rS]);
      }
   } else {
      if (sizeof(Type) == 1) {
         a.mov(a.eax.r8(), a.ppcgpr[instr.rS]);
      } else if (sizeof(Type) == 2) {
         a.mov(a.eax.r16(), a.ppcgpr[instr.rS]);
      } else if (sizeof(Type) == 4) {
         a.mov(a.eax, a.ppcgpr[instr.rS]);
      } else {
         assert(0);
      }
   }

   if (!(flags & StoreByteReverse)) {
      if (sizeof(Type) == 1) {
         // Inverted reverse logic means we have
         //    to check for this but do nothing.
      } else if (sizeof(Type) == 2) {
         a.xchg(a.eax.r8Hi(), a.eax.r8Lo());
      } else if (sizeof(Type) == 4) {
         a.bswap(a.eax);
      } else if (sizeof(Type) == 8) {
         a.bswap(a.zax);
      } else {
         assert(0);
      }
   }

   if (sizeof(Type) == 1) {
      a.mov(asmjit::X86Mem(a.zdx, 0), a.eax.r8());
   } else if (sizeof(Type) == 2) {
      a.mov(asmjit::X86Mem(a.zdx, 0), a.eax.r16());
   } else if (sizeof(Type) == 4) {
      a.mov(asmjit::X86Mem(a.zdx, 0), a.eax);
   } else if (sizeof(Type) == 8) {
      a.mov(asmjit::X86Mem(a.zdx, 0), a.zax);
   } else {
      assert(0);
   }

   if (flags & StoreUpdate) {
      a.mov(a.ppcgpr[instr.rA], a.ecx);
   }

   return true;
}
Exemplo n.º 2
0
static bool
loadGeneric(PPCEmuAssembler& a, Instruction instr)
{
   if ((flags & LoadZeroRA) && instr.rA == 0) {
      a.mov(a.ecx, 0u);
   }
   else {
      a.mov(a.ecx, a.ppcgpr[instr.rA]);
   }

   if (flags & LoadIndexed) {
      a.add(a.ecx, a.ppcgpr[instr.rB]);
   }
   else {
      a.add(a.ecx, sign_extend<16, int32_t>(instr.d));
   }

   a.mov(a.zdx, a.zcx);
   a.add(a.zdx, a.membase);
   if (sizeof(Type) == 1) {
      a.mov(a.eax, 0);
      a.mov(a.eax.r8(), asmjit::X86Mem(a.zdx, 0));
   } else if (sizeof(Type) == 2) {
      a.mov(a.eax, 0);
      a.mov(a.eax.r16(), asmjit::X86Mem(a.zdx, 0));
      if (!(flags & LoadByteReverse)) {
         a.xchg(a.eax.r8Hi(), a.eax.r8Lo());
      }
   } else if (sizeof(Type) == 4) {
      a.mov(a.eax, asmjit::X86Mem(a.zdx, 0));
      if (!(flags & LoadByteReverse)) {
         a.bswap(a.eax);
      }
   } else if (sizeof(Type) == 8) {
      a.mov(a.zax, asmjit::X86Mem(a.zdx, 0));
      if (!(flags & LoadByteReverse)) {
         a.bswap(a.zax);
      }
   } else {
      assert(0);
   }

   if (std::is_floating_point<Type>::value) {
      if (flags & LoadPairedSingles) {
         a.mov(a.ppcfprps[instr.rD][0], a.eax);
         a.mov(a.ppcfprps[instr.rD][1], a.eax);
      }
      else {
         assert(sizeof(Type) == 8);
         a.mov(a.ppcfpr[instr.rD], a.zax);
      }
   }
   else {
      if (flags & LoadSignExtend) {
         assert(sizeof(Type) == 2);
         a.movsx(a.eax, a.eax.r16());
      }

      a.mov(a.ppcgpr[instr.rD], a.eax);
   }

   if (flags & LoadReserve) {
      a.mov(a.ppcreserve, 1u);
      a.mov(a.ppcreserveAddress, a.ecx);
   }

   if (flags & LoadUpdate) {
      a.mov(a.ppcgpr[instr.rA], a.ecx);
   }
   return true;
}