25112 Rev. 3.06 September 2005

Software Optimization Guide for AMD64 Processors

printf("; dividend: register other than EAX or memory location\n");

printf("\n");

 

 

printf("MOV

EAX, 0%08lXh\n", m);

printf("MUL

dividend\n");

if (s) printf("SHR

EDX, %d\n", s);

printf("\n");

 

 

printf("; quotient now in EDX\n");

}

printed_code:

fprintf(stderr, "\n"); exit(0);

return(0);

}

Signed Integer Division

The utility sdiv.exe was compiled using the following code. The utilities provided in this document are for reference only and are not supported by AMD.

Example Code

/* This program determines the algorithm (a), multiplier (m), and shift factor (s) to be used to accomplish *signed* division by a constant divisor. Compile with MSVC.

*/

#include <stdio.h>

 

typedef unsigned __int64

U64;

typedef unsigned long

U32;

U32

log2(U32 i)

 

{

 

 

 

U32 t = 0;

 

 

i = i >> 1;

 

 

while (i) {

 

 

i = i >> 1;

 

 

t++;

 

 

}

 

 

return(t);

 

}

 

 

long e;

 

U32

res1, res2;

 

U32

oa, os, om;

 

U32

d, l, s, m, a, r, t;

 

U64

m_low, m_high, j, k;

 

Chapter 8

Integer Optimizations

189

Page 205
Image 205
AMD 250 manual Signed Integer Division, Example Code, 189