Volume 3: General-Purpose and System Instructions - Stanford ...
Volume 3: General-Purpose and System Instructions - Stanford ... Volume 3: General-Purpose and System Instructions - Stanford ...
AMD64 Technology 24594 Rev. 3.10 February 2005register (rCX). The repetition terminates when the value in rCXreaches 0 or when the zero flag (ZF) is cleared to 0. The REPEand REPZ prefixes can only be used with the CMPS, CMPSB,CMPSD, CMPSW, SCAS, SCASB, SCASD, and SCASWinstructions. Table 1-7 shows the valid REPE and REPZ prefixopcodes.Table 1-7.REPE and REPZ Prefix OpcodesMnemonicREPx CMPS mem8, mem8REPx CMPSBREPx CMPS mem16/32/64, mem16/32/64REPx CMPSWREPx CMPSDREPx CMPSQREPx SCAS mem8REPx SCASBREPx SCAS mem16/32/64REPx SCASWREPx SCASDREPx SCASQOpcodeF3 A6F3 A7F3 AEF3 AFREPNE and REPNZ. REPNE and REPNZ are synonyms and haveidentical opcodes. These prefixes repeat their associated stringinstruction the number of times specified in the counterregister (rCX). The repetition terminates when the value in rCXreaches 0 or when the zero flag (ZF) is set to 1. The REPNE andREPNZ prefixes can only be used with the CMPS, CMPSB,CMPSD, CMPSW, SCAS, SCASB, SCASD, and SCASWinstructions. Table 1-8 on page 13 shows the valid REPNE andREPNZ prefix opcodes.12 Chapter 1: Instruction Formats
24594 Rev. 3.10 February 2005 AMD64 TechnologyTable 1-8.MnemonicREPNE and REPNZ Prefix OpcodesOpcodeREPNx CMPS mem8, mem8REPNx CMPSBREPNx CMPS mem16/32/64, mem16/32/64REPNx CMPSWREPNx CMPSDREPNx CMPSQREPNx SCAS mem8REPNx SCASBREPNx SCAS mem16/32/64REPNx SCASWREPNx SCASDREPNx SCASQF2 A6F2 A7F2 AEF2 AFInstructions that Cannot Use Repeat Prefixes. In general, the repeatprefixes should only be used in the string instructions listed intables 1-6, 1-7, and 1-8, and in 128-bit or 64-bit mediainstructions. When used in media instructions, the F2h and F3hprefixes act in a special way to modify the opcode rather thancause a repeat operation. The result of using a 66h operand-sizeprefix along with an F2h or F3h prefix in 128-bit or 64-bit mediainstructions is unpredictable.Optimization of Repeats. Depending on the hardware implementation,the repeat prefixes can have a setup overhead. If therepeated count is variable, the overhead can sometimes beavoided by substituting a simple loop to move or store the data.Repeated string instructions can be expanded into equivalentsequences of inline loads and stores or a sequence of stores canbe used to emulate a REP STOS.For repeated string moves, performance can be maximized bymoving the largest possible operand size. For example, use REPMOVSD rather than REP MOVSW and REP MOVSW ratherthan REP MOVSB. Use REP STOSD rather than REP STOSWand REP STOSW rather than REP MOVSB.Chapter 1: Instruction Formats 13
- Page 2 and 3: © 2002, 2003, 2004, 2005 Advanced
- Page 4 and 5: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 6 and 7: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 8: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 12 and 13: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 14 and 15: AMD64 Technology 24594—Rev. 3.10
- Page 16 and 17: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 18 and 19: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 20 and 21: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 22 and 23: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 24 and 25: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 26 and 27: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 28 and 29: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 30 and 31: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 32 and 33: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 34 and 35: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 36 and 37: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 38 and 39: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 40 and 41: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 44 and 45: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 46 and 47: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 48 and 49: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 50 and 51: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 52 and 53: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 54 and 55: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 56 and 57: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 58 and 59: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 60 and 61: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 62 and 63: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 64 and 65: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 66 and 67: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 68 and 69: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 70 and 71: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 72 and 73: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 74 and 75: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 76 and 77: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 78 and 79: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 80 and 81: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 82 and 83: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 84 and 85: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 86 and 87: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 88 and 89: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 90 and 91: AMD64 Technology 24594 Rev. 3.10 Fe
24594 Rev. 3.10 February 2005 AMD64 TechnologyTable 1-8.MnemonicREPNE <strong>and</strong> REPNZ Prefix OpcodesOpcodeREPNx CMPS mem8, mem8REPNx CMPSBREPNx CMPS mem16/32/64, mem16/32/64REPNx CMPSWREPNx CMPSDREPNx CMPSQREPNx SCAS mem8REPNx SCASBREPNx SCAS mem16/32/64REPNx SCASWREPNx SCASDREPNx SCASQF2 A6F2 A7F2 AEF2 AF<strong>Instructions</strong> that Cannot Use Repeat Prefixes. In general, the repeatprefixes should only be used in the string instructions listed intables 1-6, 1-7, <strong>and</strong> 1-8, <strong>and</strong> in 128-bit or 64-bit mediainstructions. When used in media instructions, the F2h <strong>and</strong> F3hprefixes act in a special way to modify the opcode rather thancause a repeat operation. The result of using a 66h oper<strong>and</strong>-sizeprefix along with an F2h or F3h prefix in 128-bit or 64-bit mediainstructions is unpredictable.Optimization of Repeats. Depending on the hardware implementation,the repeat prefixes can have a setup overhead. If therepeated count is variable, the overhead can sometimes beavoided by substituting a simple loop to move or store the data.Repeated string instructions can be exp<strong>and</strong>ed into equivalentsequences of inline loads <strong>and</strong> stores or a sequence of stores canbe used to emulate a REP STOS.For repeated string moves, performance can be maximized bymoving the largest possible oper<strong>and</strong> size. For example, use REPMOVSD rather than REP MOVSW <strong>and</strong> REP MOVSW ratherthan REP MOVSB. Use REP STOSD rather than REP STOSW<strong>and</strong> REP STOSW rather than REP MOVSB.Chapter 1: Instruction Formats 13