@@ -223,35 +223,38 @@ static void AdjustProcessAndThreadPriority(void)
223
223
/* Internal functions */
224
224
/* ============================================================================================== */
225
225
226
+ typedef struct TestContext_
227
+ {
228
+ ZydisDecoderContext context ;
229
+ ZydisDecodedInstruction instruction ;
230
+ ZydisDecodedOperand operands [ZYDIS_MAX_OPERAND_COUNT ];
231
+ char format_buffer [256 ];
232
+ ZyanBool minimal_mode ;
233
+ ZyanBool format ;
234
+ ZyanBool tokenize ;
235
+ } TestContext ;
236
+
226
237
static ZyanU64 ProcessBuffer (const ZydisDecoder * decoder , const ZydisFormatter * formatter ,
227
- /* const ZydisCacheTable* cache, */
228
- const ZyanU8 * buffer , ZyanUSize length , ZyanBool format , ZyanBool tokenize , ZyanBool use_cache )
238
+ TestContext * context , const ZyanU8 * buffer , ZyanUSize length )
229
239
{
230
240
ZyanU64 count = 0 ;
231
241
ZyanUSize offset = 0 ;
232
242
ZyanStatus status ;
233
- ZydisDecodedInstruction instruction_data ;
234
- ZydisDecodedInstruction * instruction ;
235
- char format_buffer [256 ];
236
243
237
244
while (length > offset )
238
245
{
239
- if (use_cache )
240
- {
241
- ZYAN_UNREACHABLE ;
242
- // status = ZydisDecoderDecodeBufferCached(decoder, cache, buffer + offset,
243
- // length - offset, &instruction);
244
- } else
245
- {
246
- status = ZydisDecoderDecodeBuffer (decoder , buffer + offset , length - offset ,
247
- & instruction_data );
248
- instruction = & instruction_data ;
249
- }
246
+ status = ZydisDecoderDecodeInstruction (decoder , & context -> context , buffer + offset ,
247
+ length - offset , & context -> instruction );
250
248
251
249
if (status == ZYDIS_STATUS_NO_MORE_DATA )
252
250
{
253
251
break ;
254
252
}
253
+ if (!context -> minimal_mode && ZYAN_SUCCESS (status ))
254
+ {
255
+ status = ZydisDecoderDecodeOperands (decoder , & context -> context , & context -> instruction ,
256
+ context -> operands , context -> instruction .operand_count );
257
+ }
255
258
if (!ZYAN_SUCCESS (status ))
256
259
{
257
260
ZYAN_FPRINTF (ZYAN_STDERR , "%sUnexpected decoding error. Data: " ,
@@ -266,21 +269,23 @@ static ZyanU64 ProcessBuffer(const ZydisDecoder* decoder, const ZydisFormatter*
266
269
exit (EXIT_FAILURE );
267
270
}
268
271
269
- if (format )
272
+ if (context -> format )
270
273
{
271
- if (tokenize )
274
+ if (context -> tokenize )
272
275
{
273
276
const ZydisFormatterToken * token ;
274
- ZydisFormatterTokenizeInstruction (formatter , instruction , format_buffer ,
275
- sizeof (format_buffer ), offset , & token );
277
+ ZydisFormatterTokenizeInstruction (formatter , & context -> instruction ,
278
+ context -> operands , context -> instruction .operand_count_visible ,
279
+ context -> format_buffer , sizeof (context -> format_buffer ), offset , & token );
276
280
} else
277
281
{
278
- ZydisFormatterFormatInstruction (formatter , instruction , format_buffer ,
279
- sizeof (format_buffer ), offset );
282
+ ZydisFormatterFormatInstruction (formatter , & context -> instruction ,
283
+ context -> operands , context -> instruction .operand_count_visible ,
284
+ context -> format_buffer , sizeof (context -> format_buffer ), offset );
280
285
}
281
286
}
282
287
283
- offset += instruction -> length ;
288
+ offset += context -> instruction . length ;
284
289
++ count ;
285
290
}
286
291
@@ -328,16 +333,20 @@ static void TestPerformance(const ZyanU8* buffer, ZyanUSize length, ZyanBool min
328
333
}
329
334
}
330
335
336
+ TestContext context ;
337
+ context .minimal_mode = minimal_mode ;
338
+ context .format = format ;
339
+ context .tokenize = tokenize ;
340
+
331
341
// Cache warmup
332
- ProcessBuffer (& decoder , & formatter , /* cache, */ buffer , length , format , tokenize , use_cache );
342
+ ProcessBuffer (& decoder , & formatter , & context , buffer , length );
333
343
334
344
// Testing
335
345
ZyanU64 count = 0 ;
336
346
StartCounter ();
337
347
for (ZyanU8 j = 0 ; j < 100 ; ++ j )
338
348
{
339
- count += ProcessBuffer (& decoder , & formatter , /* cache, */ buffer , length , format ,
340
- tokenize , use_cache );
349
+ count += ProcessBuffer (& decoder , & formatter , & context , buffer , length );
341
350
}
342
351
const char * color [4 ];
343
352
color [0 ] = minimal_mode ? CVT100_OUT (COLOR_VALUE_G ) : CVT100_OUT (COLOR_VALUE_B );
@@ -400,7 +409,8 @@ static void GenerateTestData(FILE* file, ZyanU8 encoding)
400
409
default :
401
410
ZYAN_UNREACHABLE ;
402
411
}
403
- if (ZYAN_SUCCESS (ZydisDecoderDecodeBuffer (& decoder , data , sizeof (data ), & instruction )))
412
+ if (ZYAN_SUCCESS (ZydisDecoderDecodeInstruction (& decoder , ZYAN_NULL , data ,
413
+ sizeof (data ), & instruction )))
404
414
{
405
415
ZyanBool b = ZYAN_FALSE ;
406
416
switch (encoding )
@@ -438,7 +448,6 @@ static void GenerateTestData(FILE* file, ZyanU8 encoding)
438
448
last = p ;
439
449
ZYAN_PRINTF ("%3.0d%%\n" , p );
440
450
}
441
-
442
451
}
443
452
}
444
453
}
0 commit comments