some optimizations
[picodrive.git] / cpu / Cyclone / OpArith.cpp
index c6f0bc8..9e956c0 100644 (file)
@@ -8,6 +8,7 @@ int OpArith(int op)
   int type=0,size=0;\r
   int sea=0,tea=0;\r
   int use=0;\r
+  char *shiftstr="";\r
 \r
   // Get source and target EA\r
   type=(op>>9)&7; if (type==4 || type>=7) return 1;\r
@@ -26,17 +27,20 @@ int OpArith(int op)
 \r
   EaCalc(10,0x0000, sea,size,1);\r
   EaCalc(11,0x003f, tea,size,1);\r
-  EaRead(10,    10, sea,size,0,1);\r
+  EaRead(10,    10, sea,size,0,0,0);\r
   EaRead(11,     0, tea,size,0x003f,1);\r
 \r
+  if (size==0) shiftstr=",asl #24";\r
+  else if (size==1) shiftstr=",asl #16";\r
+\r
   ot(";@ Do arithmetic:\n");\r
 \r
-  if (type==0) ot("  orr r1,r0,r10\n");\r
-  if (type==1) ot("  and r1,r0,r10\n");\r
-  if (type==2) ot("  subs r1,r0,r10 ;@ Defines NZCV\n");\r
-  if (type==3) ot("  adds r1,r0,r10 ;@ Defines NZCV\n");\r
-  if (type==5) ot("  eor r1,r0,r10\n");\r
-  if (type==6) ot("  cmp r0,r10 ;@ Defines NZCV\n");\r
+  if (type==0) ot("  orr r1,r0,r10%s\n",shiftstr);\r
+  if (type==1) ot("  and r1,r0,r10%s\n",shiftstr);\r
+  if (type==2) ot("  subs r1,r0,r10%s ;@ Defines NZCV\n",shiftstr);\r
+  if (type==3) ot("  adds r1,r0,r10%s ;@ Defines NZCV\n",shiftstr);\r
+  if (type==5) ot("  eor r1,r0,r10%s\n",shiftstr);\r
+  if (type==6) ot("  cmp r0,r10%s ;@ Defines NZCV\n",shiftstr);\r
 \r
   if (type<2 || type==5) ot("  adds r1,r1,#0 ;@ Defines NZ, clears CV\n"); // 0,1,5\r
 \r
@@ -523,19 +527,20 @@ int OpAritha(int op)
   if(type==1) Cycles=6;\r
 \r
   \r
-  EaCalc ( 0,0x003f, sea,size);\r
-  EaRead ( 0,    10, sea,size,0x003f);\r
+  // must calculate reg EA first, because of situations like: suba.w (A0)+, A0\r
+  EaCalc (10,0x0e00, dea,2,1);\r
+  EaRead (10,    11, dea,2,0x0e00);\r
 \r
-  EaCalc ( 0,0x0e00, dea,2,1);\r
-  EaRead ( 0,     1, dea,2,0x0e00);\r
+  EaCalc ( 0,0x003f, sea,size);\r
+  EaRead ( 0,     0, sea,size,0x003f);\r
 \r
-  if (type==0) ot("  sub r1,r1,r10\n");\r
-  if (type==1) ot("  cmp r1,r10 ;@ Defines NZCV\n");\r
+  if (type==0) ot("  sub r11,r11,r0\n");\r
+  if (type==1) ot("  cmp r11,r0 ;@ Defines NZCV\n");\r
   if (type==1) OpGetFlags(1,0); // Get Cmp flags\r
-  if (type==2) ot("  add r1,r1,r10\n");\r
+  if (type==2) ot("  add r11,r11,r0\n");\r
   ot("\n");\r
   \r
-  if (type!=1) EaWrite( 0,     1, dea,2,0x0e00,1);\r
+  if (type!=1) EaWrite(10,    11, dea,2,0x0e00,1);\r
 \r
   OpEnd(sea);\r
 \r