From 68acd42868fb81c4a2d2a0e7f1f0cd243f5f4fb7 Mon Sep 17 00:00:00 2001 From: hap Date: Thu, 25 Oct 2018 19:06:06 +0200 Subject: [PATCH] m68k: improve/simplify chk2cmp2 (nw) --- src/devices/cpu/m68000/m68k_in.cpp | 226 +++++++++-------------------- 1 file changed, 72 insertions(+), 154 deletions(-) diff --git a/src/devices/cpu/m68000/m68k_in.cpp b/src/devices/cpu/m68000/m68k_in.cpp index 8e5e621d19d..e1cfa6e7346 100644 --- a/src/devices/cpu/m68000/m68k_in.cpp +++ b/src/devices/cpu/m68000/m68k_in.cpp @@ -3588,26 +3588,19 @@ M68KMAKE_OP(chk2cmp2, 8, ., pcdi) if(CPU_TYPE_IS_EC020_PLUS()) { uint32_t word2 = OPER_I_16(); - uint32_t compare = REG_DA()[(word2 >> 12) & 15]&0xff; - uint32_t ea = EA_PCDI_8(); - uint32_t lower_bound = m68ki_read_pcrel_8(ea); - uint32_t upper_bound = m68ki_read_pcrel_8(ea + 1); - + int32_t compare = REG_DA()[(word2 >> 12) & 15] & 0xff; if(!BIT_F(word2)) - m_c_flag = MAKE_INT_8(compare) - MAKE_INT_8(lower_bound); - else - m_c_flag = compare - lower_bound; - m_not_z_flag = !((upper_bound==compare) | (lower_bound==compare)); - if(COND_CS()) - { - if(BIT_B(word2)) - m68ki_exception_trap(EXCEPTION_CHK); - return; - } + compare = (int32_t)(int8_t)compare; + + uint32_t ea = EA_PCDI_8(); + int32_t lower_bound = (int32_t)(int8_t)m68ki_read_pcrel_8(ea); + int32_t upper_bound = (int32_t)(int8_t)m68ki_read_pcrel_8(ea + 1); + + m_not_z_flag = !((upper_bound==compare) | (lower_bound==compare)); + m_c_flag = (compare >= lower_bound && compare <= upper_bound) ? CFLAG_CLEAR : CFLAG_SET; - m_c_flag = upper_bound - compare; if(COND_CS() && BIT_B(word2)) - m68ki_exception_trap(EXCEPTION_CHK); + m68ki_exception_trap(EXCEPTION_CHK); return; } m68ki_exception_illegal(); @@ -3619,26 +3612,19 @@ M68KMAKE_OP(chk2cmp2, 8, ., pcix) if(CPU_TYPE_IS_EC020_PLUS()) { uint32_t word2 = OPER_I_16(); - uint32_t compare = REG_DA()[(word2 >> 12) & 15]&0xff; - uint32_t ea = EA_PCIX_8(); - uint32_t lower_bound = m68ki_read_pcrel_8(ea); - uint32_t upper_bound = m68ki_read_pcrel_8(ea + 1); - + int32_t compare = REG_DA()[(word2 >> 12) & 15] & 0xff; if(!BIT_F(word2)) - m_c_flag = MAKE_INT_8(compare) - MAKE_INT_8(lower_bound); - else - m_c_flag = compare - lower_bound; - m_not_z_flag = !((upper_bound==compare) | (lower_bound==compare)); - if(COND_CS()) - { - if(BIT_B(word2)) - m68ki_exception_trap(EXCEPTION_CHK); - return; - } + compare = (int32_t)(int8_t)compare; + + uint32_t ea = EA_PCIX_8(); + int32_t lower_bound = (int32_t)(int8_t)m68ki_read_pcrel_8(ea); + int32_t upper_bound = (int32_t)(int8_t)m68ki_read_pcrel_8(ea + 1); + + m_not_z_flag = !((upper_bound==compare) | (lower_bound==compare)); + m_c_flag = (compare >= lower_bound && compare <= upper_bound) ? CFLAG_CLEAR : CFLAG_SET; - m_c_flag = upper_bound - compare; if(COND_CS() && BIT_B(word2)) - m68ki_exception_trap(EXCEPTION_CHK); + m68ki_exception_trap(EXCEPTION_CHK); return; } m68ki_exception_illegal(); @@ -3650,26 +3636,19 @@ M68KMAKE_OP(chk2cmp2, 8, ., .) if(CPU_TYPE_IS_EC020_PLUS()) { uint32_t word2 = OPER_I_16(); - uint32_t compare = REG_DA()[(word2 >> 12) & 15]&0xff; - uint32_t ea = M68KMAKE_GET_EA_AY_8; - uint32_t lower_bound = m68ki_read_8(ea); - uint32_t upper_bound = m68ki_read_8(ea + 1); - + int32_t compare = REG_DA()[(word2 >> 12) & 15] & 0xff; if(!BIT_F(word2)) - m_c_flag = MAKE_INT_8(compare) - MAKE_INT_8(lower_bound); - else - m_c_flag = compare - lower_bound; - m_not_z_flag = !((upper_bound==compare) | (lower_bound==compare)); - if(COND_CS()) - { - if(BIT_B(word2)) - m68ki_exception_trap(EXCEPTION_CHK); - return; - } + compare = (int32_t)(int8_t)compare; + + uint32_t ea = M68KMAKE_GET_EA_AY_8; + int32_t lower_bound = (int32_t)(int8_t)m68ki_read_8(ea); + int32_t upper_bound = (int32_t)(int8_t)m68ki_read_8(ea + 1); + + m_not_z_flag = !((upper_bound==compare) | (lower_bound==compare)); + m_c_flag = (compare >= lower_bound && compare <= upper_bound) ? CFLAG_CLEAR : CFLAG_SET; - m_c_flag = upper_bound - compare; if(COND_CS() && BIT_B(word2)) - m68ki_exception_trap(EXCEPTION_CHK); + m68ki_exception_trap(EXCEPTION_CHK); return; } m68ki_exception_illegal(); @@ -3681,31 +3660,19 @@ M68KMAKE_OP(chk2cmp2, 16, ., pcdi) if(CPU_TYPE_IS_EC020_PLUS()) { uint32_t word2 = OPER_I_16(); - uint32_t compare = REG_DA()[(word2 >> 12) & 15]&0xffff; + int32_t compare = REG_DA()[(word2 >> 12) & 15] & 0xffff; + if(!BIT_F(word2)) + compare = (int32_t)(int16_t)compare; + uint32_t ea = EA_PCDI_16(); - uint32_t lower_bound = m68ki_read_pcrel_16(ea); - uint32_t upper_bound = m68ki_read_pcrel_16(ea + 2); + int32_t lower_bound = (int32_t)(int16_t)m68ki_read_pcrel_16(ea); + int32_t upper_bound = (int32_t)(int16_t)m68ki_read_pcrel_16(ea + 2); - if(!BIT_F(word2)) - m_c_flag = MAKE_INT_16(compare) - MAKE_INT_16(lower_bound); - else - m_c_flag = compare - lower_bound; m_not_z_flag = !((upper_bound==compare) | (lower_bound==compare)); - m_c_flag = CFLAG_16(m_c_flag); - if(COND_CS()) - { - if(BIT_B(word2)) - m68ki_exception_trap(EXCEPTION_CHK); - return; - } + m_c_flag = (compare >= lower_bound && compare <= upper_bound) ? CFLAG_CLEAR : CFLAG_SET; - if(!BIT_F(word2)) - m_c_flag = MAKE_INT_16(upper_bound) - MAKE_INT_16(compare); - else - m_c_flag = upper_bound - compare; - m_c_flag = CFLAG_16(m_c_flag); if(COND_CS() && BIT_B(word2)) - m68ki_exception_trap(EXCEPTION_CHK); + m68ki_exception_trap(EXCEPTION_CHK); return; } m68ki_exception_illegal(); @@ -3717,31 +3684,19 @@ M68KMAKE_OP(chk2cmp2, 16, ., pcix) if(CPU_TYPE_IS_EC020_PLUS()) { uint32_t word2 = OPER_I_16(); - uint32_t compare = REG_DA()[(word2 >> 12) & 15]&0xffff; + int32_t compare = REG_DA()[(word2 >> 12) & 15] & 0xffff; + if(!BIT_F(word2)) + compare = (int32_t)(int16_t)compare; + uint32_t ea = EA_PCIX_16(); - uint32_t lower_bound = m68ki_read_pcrel_16(ea); - uint32_t upper_bound = m68ki_read_pcrel_16(ea + 2); + int32_t lower_bound = (int32_t)(int16_t)m68ki_read_pcrel_16(ea); + int32_t upper_bound = (int32_t)(int16_t)m68ki_read_pcrel_16(ea + 2); - if(!BIT_F(word2)) - m_c_flag = MAKE_INT_16(compare) - MAKE_INT_16(lower_bound); - else - m_c_flag = compare - lower_bound; m_not_z_flag = !((upper_bound==compare) | (lower_bound==compare)); - m_c_flag = CFLAG_16(m_c_flag); - if(COND_CS()) - { - if(BIT_B(word2)) - m68ki_exception_trap(EXCEPTION_CHK); - return; - } + m_c_flag = (compare >= lower_bound && compare <= upper_bound) ? CFLAG_CLEAR : CFLAG_SET; - if(!BIT_F(word2)) - m_c_flag = MAKE_INT_16(upper_bound) - MAKE_INT_16(compare); - else - m_c_flag = upper_bound - compare; - m_c_flag = CFLAG_16(m_c_flag); if(COND_CS() && BIT_B(word2)) - m68ki_exception_trap(EXCEPTION_CHK); + m68ki_exception_trap(EXCEPTION_CHK); return; } m68ki_exception_illegal(); @@ -3753,32 +3708,19 @@ M68KMAKE_OP(chk2cmp2, 16, ., .) if(CPU_TYPE_IS_EC020_PLUS()) { uint32_t word2 = OPER_I_16(); - uint32_t compare = REG_DA()[(word2 >> 12) & 15]&0xffff; - uint32_t ea = M68KMAKE_GET_EA_AY_16; - uint32_t lower_bound = m68ki_read_16(ea); - uint32_t upper_bound = m68ki_read_16(ea + 2); - + int32_t compare = REG_DA()[(word2 >> 12) & 15] & 0xffff; if(!BIT_F(word2)) - m_c_flag = MAKE_INT_16(compare) - MAKE_INT_16(lower_bound); - else - m_c_flag = compare - lower_bound; + compare = (int32_t)(int16_t)compare; + + uint32_t ea = M68KMAKE_GET_EA_AY_16; + int32_t lower_bound = (int32_t)(int16_t)m68ki_read_16(ea); + int32_t upper_bound = (int32_t)(int16_t)m68ki_read_16(ea + 2); m_not_z_flag = !((upper_bound==compare) | (lower_bound==compare)); - m_c_flag = CFLAG_16(m_c_flag); - if(COND_CS()) - { - if(BIT_B(word2)) - m68ki_exception_trap(EXCEPTION_CHK); - return; - } - if(!BIT_F(word2)) - m_c_flag = MAKE_INT_16(upper_bound) - MAKE_INT_16(compare); - else - m_c_flag = upper_bound - compare; + m_c_flag = (compare >= lower_bound && compare <= upper_bound) ? CFLAG_CLEAR : CFLAG_SET; - m_c_flag = CFLAG_16(m_c_flag); if(COND_CS() && BIT_B(word2)) - m68ki_exception_trap(EXCEPTION_CHK); + m68ki_exception_trap(EXCEPTION_CHK); return; } m68ki_exception_illegal(); @@ -3790,25 +3732,17 @@ M68KMAKE_OP(chk2cmp2, 32, ., pcdi) if(CPU_TYPE_IS_EC020_PLUS()) { uint32_t word2 = OPER_I_16(); - uint32_t compare = REG_DA()[(word2 >> 12) & 15]; + int32_t compare = (int32_t)REG_DA()[(word2 >> 12) & 15]; + uint32_t ea = EA_PCDI_32(); - uint32_t lower_bound = m68ki_read_pcrel_32(ea); - uint32_t upper_bound = m68ki_read_pcrel_32(ea + 4); + int32_t lower_bound = (int32_t)m68ki_read_pcrel_32(ea); + int32_t upper_bound = (int32_t)m68ki_read_pcrel_32(ea + 4); - m_c_flag = compare - lower_bound; m_not_z_flag = !((upper_bound==compare) | (lower_bound==compare)); - m_c_flag = CFLAG_SUB_32(lower_bound, compare, m_c_flag); - if(COND_CS()) - { - if(BIT_B(word2)) - m68ki_exception_trap(EXCEPTION_CHK); - return; - } + m_c_flag = (compare >= lower_bound && compare <= upper_bound) ? CFLAG_CLEAR : CFLAG_SET; - m_c_flag = upper_bound - compare; - m_c_flag = CFLAG_SUB_32(compare, upper_bound, m_c_flag); if(COND_CS() && BIT_B(word2)) - m68ki_exception_trap(EXCEPTION_CHK); + m68ki_exception_trap(EXCEPTION_CHK); return; } m68ki_exception_illegal(); @@ -3820,25 +3754,17 @@ M68KMAKE_OP(chk2cmp2, 32, ., pcix) if(CPU_TYPE_IS_EC020_PLUS()) { uint32_t word2 = OPER_I_16(); - uint32_t compare = REG_DA()[(word2 >> 12) & 15]; + int32_t compare = (int32_t)REG_DA()[(word2 >> 12) & 15]; + uint32_t ea = EA_PCIX_32(); - uint32_t lower_bound = m68ki_read_pcrel_32(ea); - uint32_t upper_bound = m68ki_read_pcrel_32(ea + 4); + int32_t lower_bound = (int32_t)m68ki_read_pcrel_32(ea); + int32_t upper_bound = (int32_t)m68ki_read_pcrel_32(ea + 4); - m_c_flag = compare - lower_bound; m_not_z_flag = !((upper_bound==compare) | (lower_bound==compare)); - m_c_flag = CFLAG_SUB_32(lower_bound, compare, m_c_flag); - if(COND_CS()) - { - if(BIT_B(word2)) - m68ki_exception_trap(EXCEPTION_CHK); - return; - } + m_c_flag = (compare >= lower_bound && compare <= upper_bound) ? CFLAG_CLEAR : CFLAG_SET; - m_c_flag = upper_bound - compare; - m_c_flag = CFLAG_SUB_32(compare, upper_bound, m_c_flag); if(COND_CS() && BIT_B(word2)) - m68ki_exception_trap(EXCEPTION_CHK); + m68ki_exception_trap(EXCEPTION_CHK); return; } m68ki_exception_illegal(); @@ -3850,25 +3776,17 @@ M68KMAKE_OP(chk2cmp2, 32, ., .) if(CPU_TYPE_IS_EC020_PLUS()) { uint32_t word2 = OPER_I_16(); - uint32_t compare = REG_DA()[(word2 >> 12) & 15]; + int32_t compare = (int32_t)REG_DA()[(word2 >> 12) & 15]; + uint32_t ea = M68KMAKE_GET_EA_AY_32; - uint32_t lower_bound = m68ki_read_32(ea); - uint32_t upper_bound = m68ki_read_32(ea + 4); + int32_t lower_bound = (int32_t)m68ki_read_32(ea); + int32_t upper_bound = (int32_t)m68ki_read_32(ea + 4); - m_c_flag = compare - lower_bound; m_not_z_flag = !((upper_bound==compare) | (lower_bound==compare)); - m_c_flag = CFLAG_SUB_32(lower_bound, compare, m_c_flag); - if(COND_CS()) - { - if(BIT_B(word2)) - m68ki_exception_trap(EXCEPTION_CHK); - return; - } + m_c_flag = (compare >= lower_bound && compare <= upper_bound) ? CFLAG_CLEAR : CFLAG_SET; - m_c_flag = upper_bound - compare; - m_c_flag = CFLAG_SUB_32(compare, upper_bound, m_c_flag); if(COND_CS() && BIT_B(word2)) - m68ki_exception_trap(EXCEPTION_CHK); + m68ki_exception_trap(EXCEPTION_CHK); return; } m68ki_exception_illegal();