code review and optimizations
[picodrive.git] / cpu / Cyclone / Main.cpp
index 80bbfd8..96de268 100644 (file)
@@ -10,6 +10,7 @@ char *Narm[4]={ "b", "h","",""}; // Normal ARM Extensions for operand sizes 0,1,
 char *Sarm[4]={"sb","sh","",""}; // Sign-extend ARM Extensions for operand sizes 0,1,2\r
 int Cycles; // Current cycles for opcode\r
 int pc_dirty; // something changed PC during processing\r
+static int arm_op_count;\r
 \r
 \r
 void ot(const char *format, ...)\r
@@ -22,6 +23,9 @@ void ot(const char *format, ...)
   for(i=0, len=strlen(format); i < len && format[i] != '\n'; i++);\r
   if(i < len-1 && format[len-1] != '\n') printf("\nWARNING: possible improper newline placement:\n%s\n", format);\r
 \r
+  if (format[0] == ' ' && format[1] == ' ' && format[2] != ' ' && format[2] != '.')\r
+    arm_op_count++;\r
+\r
   va_start(valist,format);\r
   if (AsmFile) vfprintf(AsmFile,format,valist);\r
   va_end(valist);\r
@@ -273,6 +277,7 @@ static void PrintFramework()
     ot("  bx lr\n");\r
     ot("\n");\r
 #endif\r
+  // 68k: XNZVC, ARM: NZCV\r
   if (ms) ot("CycloneSetSr\n");\r
   else    ot("CycloneSetSr:\n");\r
   ot("  mov r2,r1,lsr #8\n");\r
@@ -287,8 +292,8 @@ static void PrintFramework()
   ot("  str r3,[r0,#0x3C]\n");\r
   ot("  str r2,[r0,#0x48]\n");\r
   ot("setsr_noswap%s\n",ms?"":":");\r
-  ot("  mov r2,r1,lsr #3\n");\r
-  ot("  strb r2,[r0,#0x45] ;@ the X flag\n");\r
+  ot("  mov r2,r1,lsl #25\n");\r
+  ot("  str r2,[r0,#0x4c] ;@ the X flag\n");\r
   ot("  bic r2,r1,#0xf3\n");\r
   ot("  tst r1,#1\n");\r
   ot("  orrne r2,r2,#2\n");\r
@@ -306,8 +311,8 @@ static void PrintFramework()
   ot("  orrne r2,r2,#2\n");\r
   ot("  tst r1,#2\n");\r
   ot("  orrne r2,r2,#1\n");\r
-  ot("  ldrb r1,[r0,#0x45] ;@ the X flag\n");\r
-  ot("  tst r1,#2\n");\r
+  ot("  ldr r1,[r0,#0x4c] ;@ the X flag\n");\r
+  ot("  tst r1,#0x20000000\n");\r
   ot("  orrne r2,r2,#0x10\n");\r
   ot("  ldrb r1,[r0,#0x44] ;@ the SR high\n");\r
   ot("  orr r0,r2,r1,lsl #8\n");\r
@@ -414,8 +419,12 @@ int MemHandler(int type,int size,int addrreg)
   addrreg=0;\r
 #endif\r
   if (addrreg != 0)\r
+  {\r
+    ot("  add lr,pc,#4\n"); // helps to prevent interlocks\r
     ot("  mov r0,r%i\n", addrreg);\r
-  ot("  mov lr,pc\n");\r
+  }\r
+  else\r
+    ot("  mov lr,pc\n");\r
   ot("  ldr pc,[r7,#0x%x] ;@ Call ",func);\r
 \r
   // Document what we are calling:\r
@@ -441,7 +450,7 @@ int MemHandler(int type,int size,int addrreg)
 static void PrintOpcodes()\r
 {\r
   int op=0;\r
\r
+\r
   printf("Creating Opcodes: [");\r
 \r
   ot(";@ ---------------------------- Opcodes ---------------------------\n");\r
@@ -469,6 +478,7 @@ static void PrintOpcodes()
   ot("  mov r0,#0x10\n");\r
   ot("  bl Exception\n");\r
 #endif\r
+  ot("\n");\r
   Cycles=34;\r
   OpEnd();\r
 \r
@@ -495,6 +505,7 @@ static void PrintOpcodes()
   ot("  mov r0,#0x28\n");\r
   ot("  bl Exception\n");\r
 #endif\r
+  ot("\n");\r
   Cycles=4;\r
   OpEnd();\r
 \r
@@ -520,6 +531,7 @@ static void PrintOpcodes()
   ot("  mov r0,#0x2c\n");\r
   ot("  bl Exception\n");\r
 #endif\r
+  ot("\n");\r
   Cycles=4;\r
   OpEnd();\r
 \r
@@ -713,7 +725,9 @@ static int CycloneMake()
   ot("\n");\r
 \r
   PrintFramework();\r
+  arm_op_count = 0;\r
   PrintOpcodes();\r
+  printf("~%i ARM instructions used for opcode handlers\n", arm_op_count);\r
   PrintJumpTable();\r
 \r
   if (ms) ot("  END\n");\r