code review and optimizations
[picodrive.git] / cpu / Cyclone / OpLogic.cpp
index 33be8c9..3389a8e 100644 (file)
@@ -23,7 +23,7 @@ int OpBtstReg(int op)
     if (EaCanWrite(tea)==0) return 1;\r
   }\r
 \r
-  use=OpBase(op);\r
+  use=OpBase(op,size);\r
   use&=~0x0e00; // Use same handler for all registers\r
   if (op!=use) { OpUse(op,use); return 0; } // Use existing handler\r
 \r
@@ -36,13 +36,9 @@ int OpBtstReg(int op)
     if(size>=2) Cycles+=2;\r
   }\r
 \r
-  EaCalc (10,0x0e00,sea,0,0,0);\r
-  EaRead (10,    10,sea,0,0x0e00,0,0);\r
+  EaCalcReadNoSE(-1,10,sea,0,0x0e00);\r
 \r
-  EaCalc ( 0,0x003f,tea,size,0,0);\r
-  if (type>0)\r
-    ot("  mov r11,r0\n");\r
-  EaRead ( 0,     0,tea,size,0x003f,0,0);\r
+  EaCalcReadNoSE((type>0)?11:-1,0,tea,size,0x003f);\r
 \r
   if (tea>=0x10)\r
        ot("  and r10,r10,#7  ;@ mem - do mod 8\n");  // size always 0\r
@@ -89,14 +85,13 @@ int OpBtstImm(int op)
     if (EaCanWrite(tea)==0) return 1;\r
   }\r
 \r
-  use=OpBase(op);\r
+  use=OpBase(op,size);\r
   if (op!=use) { OpUse(op,use); return 0; } // Use existing handler\r
 \r
   OpStart(op,sea,tea);\r
 \r
   ot("\n");\r
-  EaCalc ( 0,0x0000,sea,0,0,0);\r
-  EaRead ( 0,     0,sea,0,0,0,0);\r
+  EaCalcReadNoSE(-1,0,sea,0,0);\r
   ot("  mov r10,#1\n");\r
   ot("  bic r9,r9,#0x40000000 ;@ Blank Z flag\n");\r
   if (tea>=0x10)\r
@@ -112,8 +107,7 @@ int OpBtstImm(int op)
     if(size>=2) Cycles+=2;\r
   }\r
 \r
-  EaCalc (11,0x003f,tea,size,0,0);\r
-  EaRead (11,     0,tea,size,0x003f,0,0);\r
+  EaCalcReadNoSE((type>0)?11:-1,0,tea,size,0x003f);\r
   ot("  tst r0,r10 ;@ Do arithmetic\n");\r
   ot("  orreq r9,r9,#0x40000000 ;@ Get Z flag\n");\r
   ot("\n");\r
@@ -146,7 +140,7 @@ int OpNeg(int op)
   if (EaCanRead (ea,size)==0||EaAn(ea)) return 1;\r
   if (EaCanWrite(ea     )==0) return 1;\r
 \r
-  use=OpBase(op);\r
+  use=OpBase(op,size);\r
   if (op!=use) { OpUse(op,use); return 0; } // Use existing handler\r
 \r
   OpStart(op,ea);   Cycles=size<2?4:6;\r
@@ -162,7 +156,7 @@ int OpNeg(int op)
 \r
   EaCalc (10,0x003f,ea,size,0,0);\r
 \r
-  if (type!=1) EaRead (10,0,ea,size,0x003f,0,0); // Don't need to read for 'clr' (or do we, for dummy read?)\r
+  if (type!=1) EaRead (10,0,ea,size,0x003f,0,0); // Don't need to read for 'clr' (or do we, for dummy read?)\r
   if (type==1) ot("\n");\r
 \r
   if (type==0)\r
@@ -260,7 +254,7 @@ int OpTst(int op)
   // See if we can do this opcode:\r
   if (EaCanWrite(sea)==0||EaAn(sea)) return 1;\r
 \r
-  use=OpBase(op);\r
+  use=OpBase(op,size);\r
   if (op!=use) { OpUse(op,use); return 0; } // Use existing handler\r
 \r
   OpStart(op,sea); Cycles=4;\r
@@ -288,7 +282,7 @@ int OpExt(int op)
   size=(op>>6)&1;\r
   shift=32-(8<<size);\r
 \r
-  use=OpBase(op);\r
+  use=OpBase(op,size);\r
   if (op!=use) { OpUse(op,use); return 0; } // Use existing handler\r
 \r
   OpStart(op); Cycles=4;\r
@@ -328,7 +322,7 @@ int OpSet(int op)
   // See if we can do this opcode:\r
   if (EaCanWrite(ea)==0) return 1;\r
 \r
-  use=OpBase(op);\r
+  use=OpBase(op,size);\r
   if (op!=use) { OpUse(op,use); return 0; } // Use existing handler\r
 \r
   OpStart(op,ea); Cycles=8;\r
@@ -383,7 +377,7 @@ static int EmitAsr(int op,int type,int dir,int count,int size,int usereg)
   if (usereg)\r
   {\r
     ot(";@ Use Dn for count:\n");\r
-    ot("  and r2,r8,#7<<9\n");\r
+    ot("  and r2,r8,#0x0e00\n");\r
     ot("  ldr r2,[r7,r2,lsr #7]\n");\r
     ot("  and r2,r2,#63\n");\r
     ot("\n");\r
@@ -426,12 +420,10 @@ static int EmitAsr(int op,int type,int dir,int count,int size,int usereg)
     if (usereg) { // store X only if count is not 0\r
       ot("  cmp %s,#0 ;@ shifting by 0?\n",pct);\r
       ot("  biceq r9,r9,#0x20000000 ;@ if so, clear carry\n");\r
-      ot("  movne r1,r9,lsr #28\n");\r
-      ot("  strneb r1,[r7,#0x45] ;@ else Save X bit\n");\r
+      ot("  strne r9,[r7,#0x4c] ;@ else Save X bit\n");\r
     } else {\r
       // count will never be 0 if we use immediate\r
-      ot("  mov r1,r9,lsr #28\n");\r
-      ot("  strb r1,[r7,#0x45] ;@ Save X bit\n");\r
+      ot("  str r9,[r7,#0x4c] ;@ Save X bit\n");\r
     }\r
 \r
     if (type==0 && dir) {\r
@@ -462,10 +454,10 @@ static int EmitAsr(int op,int type,int dir,int count,int size,int usereg)
         ot("  movs r0,r0,rrx\n");\r
         OpGetFlags(0,1);\r
       } else {\r
-        ot("  ldrb r3,[r7,#0x45]\n");\r
+        ot("  ldr r3,[r7,#0x4c]\n");\r
         ot("  movs r0,r0,lsl #1\n");\r
         OpGetFlags(0,1);\r
-        ot("  tst r3,#2\n");\r
+        ot("  tst r3,#0x20000000\n");\r
         ot("  orrne r0,r0,#0x%x\n", 1<<(32-wide));\r
         ot("  bicne r9,r9,#0x40000000 ;@ clear Z in case it got there\n");\r
       }\r
@@ -503,10 +495,10 @@ static int EmitAsr(int op,int type,int dir,int count,int size,int usereg)
     ot("  orr r0,r3,r0 ;@ r0=Rotated value\n");\r
 \r
     ot(";@ Insert X bit into r2-1:\n");\r
-    ot("  ldrb r3,[r7,#0x45]\n");\r
+    ot("  ldr r3,[r7,#0x4c]\n");\r
     ot("  sub r2,r2,#1\n");\r
-    ot("  and r3,r3,#2\n");\r
-    ot("  mov r3,r3,lsr #1\n");\r
+    ot("  and r3,r3,#0x20000000\n");\r
+    ot("  mov r3,r3,lsr #29\n");\r
     ot("  orr r0,r0,r3,lsl r2\n");\r
     ot("\n");\r
 \r
@@ -517,15 +509,14 @@ static int EmitAsr(int op,int type,int dir,int count,int size,int usereg)
       ot("  bicne r9,r9,#0x40000000 ;@ make sure we didn't mess Z\n");\r
     }\r
     if (usereg) { // store X only if count is not 0\r
-      ot("  mov r2,r9,lsr #28\n");\r
-      ot("  strb r2,[r7,#0x45] ;@ if not 0, Save X bit\n");\r
+      ot("  str r9,[r7,#0x4c] ;@ if not 0, Save X bit\n");\r
       ot("  b nozerox%.4x\n",op);\r
       ot("norotx%.4x%s\n",op,ms?"":":");\r
-      ot("  ldrb r2,[r7,#0x45]\n");\r
+      ot("  ldr r2,[r7,#0x4c]\n");\r
       ot("  adds r0,r0,#0 ;@ Defines NZ, clears CV\n");\r
       OpGetFlags(0,0);\r
-      ot("  and r2,r2,#2\n");\r
-      ot("  orr r9,r9,r2,lsl #28 ;@ C = old_X\n");\r
+      ot("  and r2,r2,#0x20000000\n");\r
+      ot("  orr r9,r9,r2 ;@ C = old_X\n");\r
       ot("nozerox%.4x%s\n",op,ms?"":":");\r
     }\r
 \r
@@ -642,7 +633,7 @@ int OpAsrEa(int op)
   if (EaCanRead(ea,0)==0) return 1;\r
   if (EaCanWrite(ea)==0) return 1;\r
 \r
-  use=OpBase(op);\r
+  use=OpBase(op,size);\r
   if (op!=use) { OpUse(op,use); return 0; } // Use existing handler\r
 \r
   OpStart(op,ea); Cycles=6; // EmitAsr() will add 2\r
@@ -668,7 +659,7 @@ int OpTas(int op, int gen_special)
   // See if we can do this opcode:\r
   if (EaCanWrite(ea)==0 || EaAn(ea)) return 1;\r
 \r
-  use=OpBase(op);\r
+  use=OpBase(op,0);\r
   if (op!=use) { OpUse(op,use); return 0; } // Use existing handler\r
 \r
   if (!gen_special) OpStart(op,ea);\r