From cf6a910630f8a244353a01409f83b6908e2467c8 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Wed, 9 Mar 2022 20:20:32 -0500 Subject: [PATCH] Handle no-base case directly in existing switch. --- InstructionSets/x86/DataPointerResolver.hpp | 52 +++++++++++++-------- 1 file changed, 33 insertions(+), 19 deletions(-) diff --git a/InstructionSets/x86/DataPointerResolver.hpp b/InstructionSets/x86/DataPointerResolver.hpp index c6754ee08..2a2197a25 100644 --- a/InstructionSets/x86/DataPointerResolver.hpp +++ b/InstructionSets/x86/DataPointerResolver.hpp @@ -152,6 +152,7 @@ template class DataPointerR /// Computes the effective address of @c pointer including any displacement applied by @c instruction. /// @c pointer must be of type Source::Indirect. + template static uint32_t effective_address( RegistersT ®isters, const Instruction &instruction, @@ -211,6 +212,7 @@ template void DataPointerResolver:: rw(v, FS, i); rw(v, GS, i); template +template uint32_t DataPointerResolver::effective_address( RegistersT ®isters, const Instruction &instruction, @@ -218,9 +220,11 @@ uint32_t DataPointerResolver::effective_address( using AddressT = typename Instruction::AddressT; AddressT base = 0, index = 0; - switch(pointer.base()) { - default: break; - ALLREGS(base, false); + if constexpr (has_base) { + switch(pointer.base()) { + default: break; + ALLREGS(base, false); + } } switch(pointer.index()) { @@ -257,7 +261,7 @@ template void DataPointerResolver &instruction, DataPointer pointer, DataT &value) { - const Source source = pointer.source(); + const Source source = pointer.source(); switch(source) { default: @@ -279,22 +283,32 @@ template void DataPointerResolver \ + (registers, instruction, pointer); \ + \ + if constexpr (is_write) { \ + memory.template write( \ + instruction.data_segment(), \ + address, \ + value \ + ); \ + } else { \ + value = memory.template read( \ + instruction.data_segment(), \ + address \ + ); \ + } \ +} + case Source::IndirectNoBase: + indirect(false); + break; + + case Source::Indirect: + indirect(true); + break; +#undef indirect - if constexpr (is_write) { - memory.template write( - instruction.data_segment(), - address, - value - ); - } else { - value = memory.template read( - instruction.data_segment(), - address - ); - } - } } } #undef ALLREGS