Software Optimization Guide for AMD64 Processors

25112 Rev. 3.06 September 2005

4.6Short Instruction Encodings

Optimization

Use instruction forms with shorter encodings rather than those with longer encodings. For example, use 8-bit displacements instead of 32-bit displacements, and use the single-byte form of simple integer instructions instead of the 2-byte opcode-ModRM form.

Application

This optimization applies to:

32-bit software

64-bit software

Rationale

Using shorter instructions increases the number of instructions that can fit into the L1 instruction cache and increases the average decode rate.

Example

Avoid the use of instructions with longer encodings, such as those shown here:

81

C0

78

56

34

12

add eax,

12345678h

; 2-byte opcode form (with ModRM)

81

C3

FB FF FF FF

add ebx,

-5

;

32-bit

immediate value

0F

84

05

00

00

00

jz label1

;

2-byte

opcode, 32-bit immediate value

Instead, choose instructions with shorter encodings, like these:

05

78

56

34 12

add

eax, 12345678h

; 1-byte opcode form

83

C3

FB

 

add

ebx, -5

;

8-bit sign-extended immediate value

74

05

 

 

jz

label1

;

1-byte opcode, 8-bit immediate value

80

Instruction-Decoding Optimizations

Chapter 4

Page 96
Image 96
AMD 250 manual Short Instruction Encodings