[29/52] target-m68k: factorize flags computing
diff mbox

Message ID 1462392752-17703-30-git-send-email-laurent@vivier.eu
State New
Headers show

Commit Message

Laurent Vivier May 4, 2016, 8:12 p.m. UTC
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 target-m68k/helper.c | 125 +++++++++++++++++----------------------------------
 1 file changed, 42 insertions(+), 83 deletions(-)

Comments

Richard Henderson May 6, 2016, 5:11 p.m. UTC | #1
On 05/04/2016 10:12 AM, Laurent Vivier wrote:
> +
> +#define COMPUTE_CCR(op, x, n, z, v, c) {                                   \
> +    switch (op) {                                                          \
> +    case CC_OP_FLAGS:                                                      \

Please do fold this into the previous patch.


r

Patch
diff mbox

diff --git a/target-m68k/helper.c b/target-m68k/helper.c
index 42a2f1c..e9e7cee 100644
--- a/target-m68k/helper.c
+++ b/target-m68k/helper.c
@@ -531,6 +531,46 @@  void HELPER(mac_set_flags)(CPUM68KState *env, uint32_t acc)
     }
 }
 
+
+#define COMPUTE_CCR(op, x, n, z, v, c) {                                   \
+    switch (op) {                                                          \
+    case CC_OP_FLAGS:                                                      \
+        /* Everything in place.  */                                        \
+        break;                                                             \
+    case CC_OP_ADD:                                                        \
+        res = n;                                                           \
+        src2 = v;                                                          \
+        src1 = res - src2;                                                 \
+        c = x;                                                             \
+        z = n;                                                             \
+        v = (res ^ src1) & ~(src1 ^ src2);                                 \
+        break;                                                             \
+    case CC_OP_SUB:                                                        \
+        res = n;                                                           \
+        src2 = v;                                                          \
+        src1 = res + src2;                                                 \
+        c = x;                                                             \
+        z = n;                                                             \
+        v = (res ^ src1) & (src1 ^ src2);                                  \
+        break;                                                             \
+    case CC_OP_CMP:                                                        \
+        src1 = n;                                                          \
+        src2 = v;                                                          \
+        res = src1 - src2;                                                 \
+        n = res;                                                           \
+        z = res;                                                           \
+        c = src1 < src2;                                                   \
+        v = (res ^ src1) & (src1 ^ src2);                                  \
+        break;                                                             \
+    case CC_OP_LOGIC:                                                      \
+        c = v = 0;                                                         \
+        z = n;                                                             \
+        break;                                                             \
+    default:                                                               \
+        cpu_abort(CPU(m68k_env_get_cpu(env)), "Bad CC_OP %d", op);         \
+    }                                                                      \
+} while (0)
+
 uint32_t cpu_m68k_get_ccr(CPUM68KState *env)
 {
     uint32_t x, c, n, z, v;
@@ -542,47 +582,7 @@  uint32_t cpu_m68k_get_ccr(CPUM68KState *env)
     z = env->cc_z;
     v = env->cc_v;
 
-    switch (env->cc_op) {
-    case CC_OP_FLAGS:
-        /* Everything in place.  */
-        break;
-
-    case CC_OP_ADD:
-        res = n;
-        src2 = v;
-        src1 = res - src2;
-        c = x;
-        z = n;
-        v = (res ^ src1) & ~(src1 ^ src2);
-        break;
-
-    case CC_OP_SUB:
-        res = n;
-        src2 = v;
-        src1 = res + src2;
-        c = x;
-        z = n;
-        v = (res ^ src1) & (src1 ^ src2);
-        break;
-
-    case CC_OP_CMP:
-        src1 = n;
-        src2 = v;
-        res = src1 - src2;
-        n = res;
-        z = res;
-        c = src1 < src2;
-        v = (res ^ src1) & (src1 ^ src2);
-        break;
-
-    case CC_OP_LOGIC:
-        c = v = 0;
-        z = n;
-        break;
-
-    default:
-        cpu_abort(CPU(m68k_env_get_cpu(env)), "Bad CC_OP %d", env->cc_op);
-    }
+    COMPUTE_CCR(env->cc_op, x, n, z, v, c);
 
     n = n >> 31;
     v = v >> 31;
@@ -615,48 +615,7 @@  void HELPER(flush_flags)(CPUM68KState *env, uint32_t cc_op)
 {
     uint32_t res, src1, src2;
 
-    switch (cc_op) {
-    case CC_OP_FLAGS:
-        /* Everything up to date.  */
-        return;
-
-    case CC_OP_ADD:
-        res = env->cc_n;
-        src2 = env->cc_v;
-        src1 = res - src2;
-        env->cc_z = res;
-        env->cc_c = env->cc_x;
-        env->cc_v = (res ^ src1) & ~(src1 ^ src2);
-        break;
-
-    case CC_OP_SUB:
-        res = env->cc_n;
-        src2 = env->cc_v;
-        src1 = res + src2;
-        env->cc_z = res;
-        env->cc_c = env->cc_x;
-        env->cc_v = (res ^ src1) & (src1 ^ src2);
-        break;
-
-    case CC_OP_CMP:
-        src1 = env->cc_n;
-        src2 = env->cc_v;
-        res = src1 - src2;
-        env->cc_n = res;
-        env->cc_z = res;
-        env->cc_c = src1 < src2;
-        env->cc_v = (res ^ src1) & (src1 ^ src2);
-        break;
-
-    case CC_OP_LOGIC:
-        env->cc_c = 0;
-        env->cc_v = 0;
-        env->cc_z = env->cc_n;
-        break;
-
-    default:
-        cpu_abort(CPU(m68k_env_get_cpu(env)), "Bad CC_OP %d", cc_op);
-    }
+    COMPUTE_CCR(cc_op, env->cc_x, env->cc_n, env->cc_z, env->cc_v, env->cc_c);
     env->cc_op = CC_OP_FLAGS;
 }