Skip to content

Commit

Permalink
Clear F3/F2 bits
Browse files Browse the repository at this point in the history
  • Loading branch information
wtfsck committed Mar 19, 2021
1 parent 660927c commit 8c88ee3
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 18 deletions.
10 changes: 2 additions & 8 deletions src/csharp/Intel/Iced/Intel/Decoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -454,16 +454,10 @@ public void Decode(out Instruction instruction) {
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal ulong GetCurrentInstructionPointer64() => instructionPointer + state.instructionLength;

[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal void ClearMandatoryPrefix(ref Instruction instruction) {
Debug.Assert(state.Encoding == EncodingKind.Legacy);
switch (state.mandatoryPrefix) {
case MandatoryPrefixByte.PF3:
instruction.InternalClearHasRepePrefix();
break;
case MandatoryPrefixByte.PF2:
instruction.InternalClearHasRepnePrefix();
break;
}
instruction.InternalClearHasRepeRepnePrefix();
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
Expand Down
2 changes: 2 additions & 0 deletions src/csharp/Intel/Iced/Intel/Instruction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,8 @@ public bool HasRepePrefix {
internal void InternalSetHasRepePrefix() => codeFlags = (codeFlags & ~(uint)CodeFlags.RepnePrefix) | (uint)CodeFlags.RepePrefix;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal void InternalClearHasRepePrefix() => codeFlags &= ~(uint)CodeFlags.RepePrefix;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal void InternalClearHasRepeRepnePrefix() => codeFlags &= ~((uint)CodeFlags.RepePrefix | (uint)CodeFlags.RepnePrefix);

/// <summary>
/// <see langword="true"/> if the instruction has the <c>REPNE</c> prefix (<c>F2</c>)
Expand Down
12 changes: 4 additions & 8 deletions src/rust/iced-x86/src/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1345,16 +1345,10 @@ impl<'a> Decoder<'a> {
((self.data_ptr - self.instr_start_data_ptr) as u64).wrapping_add(self.ip)
}

// It's not possible to use 'as u32' on the left side in a match arm
const PF3: u32 = MandatoryPrefixByte::PF3 as u32;
const PF2: u32 = MandatoryPrefixByte::PF2 as u32;
#[inline]
fn clear_mandatory_prefix(&mut self, instruction: &mut Instruction) {
debug_assert_eq!(self.state.encoding(), EncodingKind::Legacy);
match self.state.mandatory_prefix {
Decoder::PF3 => instruction_internal::internal_clear_has_repe_prefix(instruction),
Decoder::PF2 => instruction_internal::internal_clear_has_repne_prefix(instruction),
_ => {}
}
instruction_internal::internal_clear_has_repe_repne_prefix(instruction);
}

#[inline(always)]
Expand All @@ -1364,6 +1358,8 @@ impl<'a> Decoder<'a> {
}
}

const PF3: u32 = MandatoryPrefixByte::PF3 as u32;
const PF2: u32 = MandatoryPrefixByte::PF2 as u32;
fn set_xacquire_xrelease_core(&mut self, instruction: &mut Instruction, flags: u32) {
debug_assert!(!((flags & HandlerFlags::XACQUIRE_XRELEASE_NO_LOCK) == 0 && !instruction.has_lock_prefix()));
match self.state.mandatory_prefix {
Expand Down
4 changes: 2 additions & 2 deletions src/rust/iced-x86/src/decoder/handlers_legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,13 +441,13 @@ impl OpCodeHandler_MandatoryPrefix4 {
}
this.handler_f3
}
3 => {
_ => {
debug_assert_eq!(decoder.state.mandatory_prefix, 3);
if (this.flags & 8) != 0 {
decoder.clear_mandatory_prefix_f2(instruction);
}
this.handler_f2
}
_ => unreachable!(),
};
if handler.has_modrm && (this.flags & 0x10) != 0 {
decoder.read_modrm();
Expand Down
6 changes: 6 additions & 0 deletions src/rust/iced-x86/src/instruction_internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ pub(crate) fn internal_has_op_mask_or_zeroing_masking(this: &Instruction) -> boo
(this.code_flags & ((CodeFlags::OP_MASK_MASK << CodeFlags::OP_MASK_SHIFT) | CodeFlags::ZEROING_MASKING)) != 0
}

#[cfg(feature = "decoder")]
#[inline]
pub(crate) fn internal_clear_has_repe_repne_prefix(this: &mut Instruction) {
this.code_flags &= !(CodeFlags::REPE_PREFIX | CodeFlags::REPNE_PREFIX)
}

#[cfg(feature = "decoder")]
#[inline]
pub(crate) fn internal_clear_has_repe_prefix(this: &mut Instruction) {
Expand Down

0 comments on commit 8c88ee3

Please sign in to comment.