1
0
mirror of https://github.com/bitdefender/bddisasm.git synced 2024-12-22 05:58:07 +00:00

Merge pull request #96 from turol/optimize

Optimizations
This commit is contained in:
vlutas 2024-08-29 17:38:46 +03:00 committed by GitHub
commit c877b5007f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 71 additions and 11 deletions

View File

@ -1298,7 +1298,7 @@ NdParseMemoryOperand16(
// Store the displacement.
Operand->Info.Memory.HasDisp = !!Instrux->HasDisp;
Operand->Info.Memory.DispSize = Instrux->DispLength;
Operand->Info.Memory.Disp = ND_SIGN_EX(Instrux->DispLength, Instrux->Displacement);
Operand->Info.Memory.Disp = Instrux->HasDisp ? ND_SIGN_EX(Instrux->DispLength, Instrux->Displacement) : 0;
return ND_STATUS_SUCCESS;
}
@ -1416,7 +1416,7 @@ NdParseMemoryOperand3264(
Operand->Info.Memory.HasDisp = Instrux->HasDisp;
Operand->Info.Memory.DispSize = Instrux->DispLength;
Operand->Info.Memory.Disp = ND_SIGN_EX(Instrux->DispLength, Instrux->Displacement);
Operand->Info.Memory.Disp = Instrux->HasDisp ? ND_SIGN_EX(Instrux->DispLength, Instrux->Displacement) : 0;
return ND_STATUS_SUCCESS;
}
@ -1441,14 +1441,14 @@ NdParseOperand(
ND_UINT8 opt, ops, opf, opa, opd, opb;
ND_REG_SIZE vsibRegSize;
ND_UINT8 vsibIndexSize, vsibIndexCount;
ND_OPERAND_SIZE size, bcstSize;
ND_OPERAND_SIZE size;
ND_BOOL width;
// pre-init
status = ND_STATUS_SUCCESS;
vsibRegSize = 0;
vsibIndexSize = vsibIndexCount = 0;
size = bcstSize = 0;
size = 0;
// Get actual width.
width = Instrux->Exs.w && !(Instrux->Attributes & ND_FLAG_WIG);
@ -1877,7 +1877,7 @@ NdParseOperand(
}
// Store operand info.
operand->Size = bcstSize = size;
operand->Size = size;
//
// Fill in the operand type.
@ -2242,7 +2242,7 @@ NdParseOperand(
break;
case ND_OPT_LSTAR:
// The operand is implicit and is the IA32_STAR.
// The operand is implicit and is the IA32_LSTAR.
operand->Type = ND_OP_REG;
operand->Info.Register.Type = ND_REG_MSR;
operand->Info.Register.Size = ND_SIZE_64BIT;
@ -2778,6 +2778,7 @@ memory:
// bcstSize / rawSize.
if (Instrux->HasBroadcast)
{
ND_OPERAND_SIZE bcstSize = size;
operand->Info.Memory.HasBroadcast = ND_TRUE;
if (opd & ND_OPD_B32)

60
benchmark.sh Executable file
View File

@ -0,0 +1,60 @@
#!/bin/sh
set -e
if [ "$#" -ne 4 ] ; then
echo "Compare the speed of two different disasmtool versions"
echo "Usage $0 <first disasmtool> <second disasmtool> <input file> <iterations>"
exit 0
fi
FIRST=$1
SECOND=$2
INPUT=$3
COUNT=$4
if [ ! -x "$FIRST" ] ; then
echo "First program $FIRST does not exist or is not executable"
exit 1
fi
if [ ! -x "$SECOND" ] ; then
echo "Second program $SECOND does not exist or is not executable"
exit 1
fi
if [ ! -f "$INPUT" ] ; then
echo "Input file $INPUT does not exist"
exit 1
fi
case $COUNT in
''|*[!0-9]*) echo "Iteration count $COUNT is not a number" ; exit 1 ;;
*) ;;
esac
if [ "$COUNT" -lt 3 ] ; then
echo "ministat requires at least 3 samples"
exit 1
fi
FIRSTRESULT="$FIRST.result"
SECONDRESULT="$SECOND.result"
truncate -s 0 $FIRSTRESULT
truncate -s 0 $SECONDRESULT
# Make sure all necessary files are in cache
$FIRST -f $INPUT -nv > /dev/null
$SECOND -f $INPUT -nv > /dev/null
for n in `seq 1 $COUNT` ; do
echo "$n"
$FIRST -f $INPUT -nv -iv | tee -a $FIRSTRESULT
$SECOND -f $INPUT -nv -iv | tee -a $SECONDRESULT
done
ministat -C 6 $FIRSTRESULT $SECONDRESULT
echo 'Instructions/second, higher is better'
if [ "$COUNT" -lt 30 ] ; then
echo "Sample count $COUNT was less than 30, results might be unreliable"
fi

View File

@ -353,15 +353,14 @@ typedef ND_UINT32 ND_REG_SIZE;
#define ND_SIGN_EX_16(x) (((x) & 0x00008000) ? (0xFFFFFFFFFFFF0000 | (x)) : ((x) & 0xFFFF))
// Sign extend 32 bit to 64 bit.
#define ND_SIGN_EX_32(x) (((x) & 0x80000000) ? (0xFFFFFFFF00000000 | (x)) : ((x) & 0xFFFFFFFF))
// Wrapper for for ND_SIGN_EX_8/ND_SIGN_EX_16/ND_SIGN_EX_32. Sign extend sz bytes to 64 bits.
#define ND_SIGN_EX(sz, x) ((sz) == 1 ? ND_SIGN_EX_8(x) : (sz) == 2 ? ND_SIGN_EX_16(x) : \
(sz) == 4 ? ND_SIGN_EX_32(x) : (x))
// Sign extend to 64 bit, with minimal branches
#define ND_SIGN_EX(sz, x) (((x) & ND_SIZE_TO_MASK(sz)) | (~ND_SIZE_TO_MASK(sz) * ND_GET_SIGN(sz, x)))
// Trim 64 bits to sz bytes.
#define ND_TRIM(sz, x) ((sz) == 1 ? (x) & 0xFF : (sz) == 2 ? (x) & 0xFFFF : \
(sz) == 4 ? (x) & 0xFFFFFFFF : (x))
// Returns most significant bit, given size in bytes sz.
#define ND_MSB(sz, x) ((sz) == 1 ? ((x) >> 7) & 1 : (sz) == 2 ? ((x) >> 15) & 1 : \
(sz) == 4 ? ((x) >> 31) & 1 : ((x) >> 63) & 1)
#define ND_MSB(sz, x) (((x) >> ( (sz) * 8 - 1)) & 1)
// Returns least significant bit.
#define ND_LSB(sz, x) ((x) & 1)
// Convert a size in bytes to a bitmask.