DynamoRIO / DynamoRIO/drmemory

optimizing reps string instructions instrumentation

Open
#891 0 comments 0 reactions 0 assignees View on GitHub
Migrated Performance Priority-Medium Type-Feature
Dominant language
C
Stars
2.7k
Forks
290
PR merge metrics
No merged PRs in 30d

Description

_From [zhao...@google.com](https://code.google.com/u/106321947286816917100/) on May 15, 2012 23:37:04_

split from issue #750 ,

string instructions with reps prefix will be expanded to a sequence of instructions for instrumentation. By knowing the exact sequence, we should be able to perform certain instrumentation optimization.

For example, in pattern mode, instruction
rep movs %ds:(%esi) %esi %edi %ecx -> %es:(%edi) %esi %edi %ecx
will be instrumented as:

+0 m4 @0x4f3ac9a0 64 a3 6c 00 00 00 mov %eax -> %fs:0x0000006c
+6 m4 @0x4f3abed4 9f lahf -> %ah
+7 m4 @0x4f3ab854 0f 90 c0 seto -> %al
+10 m4 @0x4f3ace50 64 a3 64 00 00 00 mov %eax -> %fs:0x00000064
+16 m4 @0x4f3ad630 64 a1 6c 00 00 00 mov %fs:0x0000006c -> %eax
+22 m4 @0x4f3a70e4 e3 fe jecxz @0x4f3ac6fc %ecx
+24 m4 @0x4f3acf9c eb fe jmp @0x4f3a7490
+26 L4 @0x4f3ac6fc b9 01 00 00 00 mov $0x00000001 -> %ecx
+31 m4 @0x4f3ad4d8 e9 fb ff ff ff jmp @0x4f3adb20
+36 m4 @0x4f3a7490
+36 m4 @0x4f3a717c 3e 81 3e 21 43 21 43 cmp %ds:(%esi) $0x43214321
+43 m4 @0x4f3abdd4 75 fe jnz @0x4f3ab954
+45 m4 @0x4f3ad670 0f 0b ud2a
+47 m4 @0x4f3ab954
+47 m4 @0x4f3ada60 26 81 3f 21 43 21 43 cmp %es:(%edi) $0x43214321
+54 m4 @0x4f3ad8c8 75 fe jnz @0x4f3abe54
+56 m4 @0x4f3ab3e8 0f 0b ud2a
+58 m4 @0x4f3abe54
+58 L4 @0x4f3ad908 a5 movs %ds:(%esi) %esi %edi -> %es:(%edi) %esi %edi
+59 m4 @0x4f3adb20
+59 m4 @0x4f3ad34c 64 a3 6c 00 00 00 mov %eax -> %fs:0x0000006c
+65 m4 @0x4f3adae0 64 a1 64 00 00 00 mov %fs:0x00000064 -> %eax
+71 m4 @0x4f3ad0f4 04 7f add $0x7f %al -> %al
+73 m4 @0x4f3abc14 9e sahf %ah
+74 m4 @0x4f3abc94 64 a1 6c 00 00 00 mov %fs:0x0000006c -> %eax
+80 L4 @0x4f3acb2c e2 dc loop $0x080aad36 %ecx -> %ecx

There are several optimization we can do:
1. removes the eax app value save/restore
2. use cmp/jcc instead of jecxz
3. remove eflags save if the instr after original apps destroyed eflags.

_Original issue: http://code.google.com/p/drmemory/issues/detail?id=891_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.