summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/cpu/sh
diff options
context:
space:
mode:
author AJR <ajrhacker@users.noreply.github.com>2022-11-01 15:03:04 -0400
committer AJR <ajrhacker@users.noreply.github.com>2022-11-01 15:06:47 -0400
commit4df2f9d2f904073cd31d4d5db65cdb0d23270aac (patch)
treeb5daa04126fe177061506e467cd312873509b748 /src/devices/cpu/sh
parent7d9ccfa4261a4a836890b9aac9fa81109fd68598 (diff)
coretmpl.h: Add utility function for sign-extending values of arbitrary width
* cpu/ccpu: Simplify code for right-shifting 12-bit values arithmetically * konami/3dom2_te.cpp: Fix probable copy-and-paste error
Diffstat (limited to 'src/devices/cpu/sh')
-rw-r--r--src/devices/cpu/sh/sh.cpp28
-rw-r--r--src/devices/cpu/sh/sh_dasm.cpp14
-rw-r--r--src/devices/cpu/sh/sh_fe.cpp6
3 files changed, 23 insertions, 25 deletions
diff --git a/src/devices/cpu/sh/sh.cpp b/src/devices/cpu/sh/sh.cpp
index 591e7e24a61..97c2c8a6903 100644
--- a/src/devices/cpu/sh/sh.cpp
+++ b/src/devices/cpu/sh/sh.cpp
@@ -265,7 +265,7 @@ void sh_common_execution::BF(uint32_t d)
{
if ((m_sh2_state->sr & SH_T) == 0)
{
- int32_t disp = ((int32_t)d << 24) >> 24;
+ int32_t disp = util::sext(d, 8);
m_sh2_state->pc = m_sh2_state->ea = m_sh2_state->pc + disp * 2 + 2;
m_sh2_state->icount -= 2;
}
@@ -279,7 +279,7 @@ void sh_common_execution::BFS(uint32_t d)
{
if ((m_sh2_state->sr & SH_T) == 0)
{
- int32_t disp = ((int32_t)d << 24) >> 24;
+ int32_t disp = util::sext(d, 8);
m_sh2_state->m_delay = m_sh2_state->ea = m_sh2_state->pc + disp * 2 + 2;
m_sh2_state->icount--;
}
@@ -291,7 +291,7 @@ void sh_common_execution::BFS(uint32_t d)
*/
void sh_common_execution::BRA(uint32_t d)
{
- int32_t disp = ((int32_t)d << 20) >> 20;
+ int32_t disp = util::sext(d, 12);
#if BUSY_LOOP_HACKS
if (disp == -2)
@@ -324,7 +324,7 @@ void sh_common_execution::BRAF(uint32_t m)
*/
void sh_common_execution::BSR(uint32_t d)
{
- int32_t disp = ((int32_t)d << 20) >> 20;
+ int32_t disp = util::sext(d, 12);
m_sh2_state->pr = m_sh2_state->pc + 2;
m_sh2_state->m_delay = m_sh2_state->ea = m_sh2_state->pc + disp * 2 + 2;
@@ -350,7 +350,7 @@ void sh_common_execution::BT(uint32_t d)
{
if ((m_sh2_state->sr & SH_T) != 0)
{
- int32_t disp = ((int32_t)d << 24) >> 24;
+ int32_t disp = util::sext(d, 8);
m_sh2_state->pc = m_sh2_state->ea = m_sh2_state->pc + disp * 2 + 2;
m_sh2_state->icount -= 2;
}
@@ -364,7 +364,7 @@ void sh_common_execution::BTS(uint32_t d)
{
if ((m_sh2_state->sr & SH_T) != 0)
{
- int32_t disp = ((int32_t)d << 24) >> 24;
+ int32_t disp = util::sext(d, 8);
m_sh2_state->m_delay = m_sh2_state->ea = m_sh2_state->pc + disp * 2 + 2;
m_sh2_state->icount--;
}
@@ -736,13 +736,13 @@ void sh_common_execution::DT(uint32_t n)
/* EXTS.B Rm,Rn */
void sh_common_execution::EXTSB(uint32_t m, uint32_t n)
{
- m_sh2_state->r[n] = ((int32_t)m_sh2_state->r[m] << 24) >> 24;
+ m_sh2_state->r[n] = util::sext(m_sh2_state->r[m], 8);
}
/* EXTS.W Rm,Rn */
void sh_common_execution::EXTSW(uint32_t m, uint32_t n)
{
- m_sh2_state->r[n] = ((int32_t)m_sh2_state->r[m] << 16) >> 16;
+ m_sh2_state->r[n] = util::sext(m_sh2_state->r[m], 16);
}
/* EXTU.B Rm,Rn */
@@ -2853,7 +2853,7 @@ bool sh_common_execution::generate_opcode(drcuml_block &block, compiler_state &c
return true;
case 10: // BRA
- disp = ((int32_t)opcode << 20) >> 20;
+ disp = util::sext(opcode, 12);
m_sh2_state->ea = (desc->pc + 2) + disp * 2 + 2; // m_sh2_state->ea = pc+4 + disp*2 + 2
generate_delay_slot(block, compiler, desc, m_sh2_state->ea-2);
@@ -2867,7 +2867,7 @@ bool sh_common_execution::generate_opcode(drcuml_block &block, compiler_state &c
// do this before running the delay slot
UML_ADD(block, mem(&m_sh2_state->pr), desc->pc, 4); // add m_pr, desc->pc, #4 (skip the current insn & delay slot)
- disp = ((int32_t)opcode << 20) >> 20;
+ disp = util::sext(opcode, 12);
m_sh2_state->ea = (desc->pc + 2) + disp * 2 + 2; // m_sh2_state->ea = pc+4 + disp*2 + 2
generate_delay_slot(block, compiler, desc, m_sh2_state->ea-2);
@@ -3401,7 +3401,7 @@ bool sh_common_execution::generate_group_8(drcuml_block &block, compiler_state &
UML_TEST(block, mem(&m_sh2_state->sr), SH_T); // test m_sh2_state->sr, T
UML_JMPc(block, COND_Z, compiler.labelnum); // jz compiler.labelnum
- disp = ((int32_t)opcode << 24) >> 24;
+ disp = util::sext(opcode, 8);
m_sh2_state->ea = (desc->pc + 2) + disp * 2 + 2; // m_sh2_state->ea = destination
generate_update_cycles(block, compiler, m_sh2_state->ea, true); // <subtract cycles>
@@ -3414,7 +3414,7 @@ bool sh_common_execution::generate_group_8(drcuml_block &block, compiler_state &
UML_TEST(block, mem(&m_sh2_state->sr), SH_T); // test m_sh2_state->sr, T
UML_JMPc(block, COND_NZ, compiler.labelnum); // jnz compiler.labelnum
- disp = ((int32_t)opcode << 24) >> 24;
+ disp = util::sext(opcode, 8);
m_sh2_state->ea = (desc->pc + 2) + disp * 2 + 2; // m_sh2_state->ea = destination
generate_update_cycles(block, compiler, m_sh2_state->ea, true); // <subtract cycles>
@@ -3429,7 +3429,7 @@ bool sh_common_execution::generate_group_8(drcuml_block &block, compiler_state &
UML_TEST(block, mem(&m_sh2_state->sr), SH_T); // test m_sh2_state->sr, T
UML_JMPc(block, COND_Z, compiler.labelnum); // jz compiler.labelnum
- disp = ((int32_t)opcode << 24) >> 24;
+ disp = util::sext(opcode, 8);
m_sh2_state->ea = (desc->pc + 2) + disp * 2 + 2; // m_sh2_state->ea = destination
templabel = compiler.labelnum; // save our label
@@ -3450,7 +3450,7 @@ bool sh_common_execution::generate_group_8(drcuml_block &block, compiler_state &
UML_TEST(block, mem(&m_sh2_state->sr), SH_T); // test m_sh2_state->sr, T
UML_JMPc(block, COND_NZ, compiler.labelnum); // jnz compiler.labelnum
- disp = ((int32_t)opcode << 24) >> 24;
+ disp = util::sext(opcode, 8);
m_sh2_state->ea = (desc->pc + 2) + disp * 2 + 2; // m_sh2_state->ea = destination
templabel = compiler.labelnum; // save our label
diff --git a/src/devices/cpu/sh/sh_dasm.cpp b/src/devices/cpu/sh/sh_dasm.cpp
index c7e972385f2..d504be32eab 100644
--- a/src/devices/cpu/sh/sh_dasm.cpp
+++ b/src/devices/cpu/sh/sh_dasm.cpp
@@ -3,8 +3,6 @@
#include "emu.h"
#include "sh_dasm.h"
-#define SIGNX8(x) (((int32_t)(x) << 24) >> 24)
-#define SIGNX12(x) (((int32_t)(x) << 20) >> 20)
#define Rn ((opcode>>8)&15)
#define Rm ((opcode>>4)&15)
@@ -466,16 +464,16 @@ uint32_t sh_disassembler::op1000(std::ostream &stream, uint32_t pc, uint16_t opc
util::stream_format(stream, "CMP/EQ #$%02X,R0", (opcode & 0xff));
break;
case 9:
- util::stream_format(stream, "BT $%08X", pc + SIGNX8(opcode & 0xff) * 2 + 2);
+ util::stream_format(stream, "BT $%08X", pc + int8_t(opcode & 0xff) * 2 + 2);
return STEP_COND;
case 11:
- util::stream_format(stream, "BF $%08X", pc + SIGNX8(opcode & 0xff) * 2 + 2);
+ util::stream_format(stream, "BF $%08X", pc + int8_t(opcode & 0xff) * 2 + 2);
return STEP_COND;
case 13:
- util::stream_format(stream, "BTS $%08X", pc + SIGNX8(opcode & 0xff) * 2 + 2);
+ util::stream_format(stream, "BTS $%08X", pc + int8_t(opcode & 0xff) * 2 + 2);
return STEP_COND | step_over_extra(1);
case 15:
- util::stream_format(stream, "BFS $%08X", pc + SIGNX8(opcode & 0xff) * 2 + 2);
+ util::stream_format(stream, "BFS $%08X", pc + int8_t(opcode & 0xff) * 2 + 2);
return STEP_COND | step_over_extra(1);
default :
util::stream_format(stream, "invalid $%04X", opcode);
@@ -491,13 +489,13 @@ uint32_t sh_disassembler::op1001(std::ostream &stream, uint32_t pc, uint16_t opc
uint32_t sh_disassembler::op1010(std::ostream &stream, uint32_t pc, uint16_t opcode)
{
- util::stream_format(stream, "BRA $%08X", SIGNX12(opcode & 0xfff) * 2 + pc + 2);
+ util::stream_format(stream, "BRA $%08X", util::sext(opcode & 0xfff, 12) * 2 + pc + 2);
return 0;
}
uint32_t sh_disassembler::op1011(std::ostream &stream, uint32_t pc, uint16_t opcode)
{
- util::stream_format(stream, "BSR $%08X", SIGNX12(opcode & 0xfff) * 2 + pc + 2);
+ util::stream_format(stream, "BSR $%08X", util::sext(opcode & 0xfff, 12) * 2 + pc + 2);
return STEP_OVER | step_over_extra(1);
}
diff --git a/src/devices/cpu/sh/sh_fe.cpp b/src/devices/cpu/sh/sh_fe.cpp
index 45f85f46732..6a808429200 100644
--- a/src/devices/cpu/sh/sh_fe.cpp
+++ b/src/devices/cpu/sh/sh_fe.cpp
@@ -91,7 +91,7 @@ bool sh_frontend::describe(opcode_desc &desc, const opcode_desc *prev)
[[fallthrough]]; // BSR is BRA with the addition of PR = the return address
case 10: // BRA
{
- int32_t disp = ((int32_t)opcode << 20) >> 20;
+ int32_t disp = util::sext(opcode, 12);
desc.flags |= OPFLAG_IS_UNCONDITIONAL_BRANCH | OPFLAG_END_SEQUENCE;
desc.targetpc = (desc.pc + 2) + disp * 2 + 2;
@@ -297,7 +297,7 @@ bool sh_frontend::describe_group_8(opcode_desc &desc, const opcode_desc *prev, u
case 11<< 8: // BF(opcode & 0xff);
desc.flags |= OPFLAG_IS_CONDITIONAL_BRANCH;
desc.cycles = 3;
- disp = ((int32_t)opcode << 24) >> 24;
+ disp = util::sext(opcode, 8);
desc.targetpc = (desc.pc + 2) + disp * 2 + 2;
return true;
@@ -305,7 +305,7 @@ bool sh_frontend::describe_group_8(opcode_desc &desc, const opcode_desc *prev, u
case 15<< 8: // BFS(opcode & 0xff);
desc.flags |= OPFLAG_IS_CONDITIONAL_BRANCH;
desc.cycles = 2;
- disp = ((int32_t)opcode << 24) >> 24;
+ disp = util::sext(opcode, 8);
desc.targetpc = (desc.pc + 2) + disp * 2 + 2;
desc.delayslots = 1;
return true;