From f8f928a4a8285585e50d064e71d10ec29e6dd051 Mon Sep 17 00:00:00 2001 From: flobernd Date: Wed, 5 Jul 2017 16:28:16 +0200 Subject: [PATCH] Added number of decoded instructions to the performance-test tool output --- include/Zydis/DecoderTypes.h | 2 -- src/Decoder.c | 6 +++--- tools/PerfTest.c | 14 ++++++++++---- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/include/Zydis/DecoderTypes.h b/include/Zydis/DecoderTypes.h index fe7c4d3..726dee6 100644 --- a/include/Zydis/DecoderTypes.h +++ b/include/Zydis/DecoderTypes.h @@ -509,8 +509,6 @@ typedef uint64_t ZydisInstructionAttributes; // TODO: Update values -// TODO: Add IsAtomic - /** * @brief The instruction has the ModRM byte. */ diff --git a/src/Decoder.c b/src/Decoder.c index f63da32..47c20ad 100644 --- a/src/Decoder.c +++ b/src/Decoder.c @@ -3140,9 +3140,9 @@ static ZydisStatus ZydisCollectOptionalPrefixes(ZydisDecoderContext* context, * @brief Decodes optional instruction parts like the ModRM byte, the SIB byte and additional * displacements and/or immediate values. * - * @param context A pointer to the @c ZydisDecoderContext struct. - * @param instruction A pointer to the @c ZydisDecodedInstruction struct. - * @param optionalParts A pointer to the @c ZydisInstructionParts struct. + * @param context A pointer to the @c ZydisDecoderContext struct. + * @param instruction A pointer to the @c ZydisDecodedInstruction struct. + * @param info A pointer to the @c ZydisInstructionParts struct. * * @return A zydis status code. */ diff --git a/tools/PerfTest.c b/tools/PerfTest.c index 30dfa23..96bf6f6 100644 --- a/tools/PerfTest.c +++ b/tools/PerfTest.c @@ -79,7 +79,7 @@ double GetCounter() /* Internal functions */ /* ============================================================================================== */ -void processBuffer(const char* buffer, size_t length, ZydisDecodeGranularity granularity, +uint64_t processBuffer(const char* buffer, size_t length, ZydisDecodeGranularity granularity, ZydisBool format) { ZydisDecoder decoder; @@ -103,6 +103,7 @@ void processBuffer(const char* buffer, size_t length, ZydisDecodeGranularity gra } } + uint64_t count = 0; size_t offset = 0; ZydisStatus status; ZydisDecodedInstruction instruction; @@ -116,24 +117,29 @@ void processBuffer(const char* buffer, size_t length, ZydisDecodeGranularity gra puts("Unexpected decoding error"); exit(EXIT_FAILURE); } + ++count; if (format) { ZydisFormatterFormatInstruction( &formatter, &instruction, formatBuffer, sizeof(formatBuffer)); } offset += instruction.length; - } + } + + return count; } void testPerformance(const char* buffer, size_t length, ZydisDecodeGranularity granularity, ZydisBool format) { + uint64_t count = 0; StartCounter(); for (uint8_t j = 0; j < 100; ++j) { - processBuffer(buffer, length, granularity, format); + count += processBuffer(buffer, length, granularity, format); } - printf("Granularity %d, Formatting %d: %8.2f msec\n", granularity, format, GetCounter()); + printf("Granularity %d, Formatting %d, Instructions: ~%6.2fM, Time: %8.2f msec\n", + granularity, format, (double)count / 1000000, GetCounter()); } void generateTestData(FILE* file, uint8_t encoding)