Division/Modulus Operations

<< Click to Display Table of Contents >>

Navigation:  ETEC 'C' Compiler Information >

Division/Modulus Operations

Previous pageReturn to chapter overviewNext page

The eTPU architecture includes unsigned 24-bit division hardware. Although expensive in terms of clocks cycles (13 instruction cycles), an unsigned division/modulus can be performed with a single opcode. ETEC also supports signed division and modulus (note that other eTPU code generation tools do not support this, and in fact do not warn users about the issue if they perform division/modulus on signed operands), although it is expensive in terms of both computation time and code size. It is recommended that signed division/modulus only be used when it is absolutely necessary. When the compiler comes across such a construct, it warns the user that it is expensive. If users know they only require unsigned divison (or modulus), yet the types of the operands happen to be signed, users can write code such as the below in order to get tighter code:

int a, b, c; 

// ... 

// user knows both a and b must be positive at this point 

// force more efficient unsigned division 

c = (unsigned int)a / (unsigned int)b;