|ARM Technical Support Knowledge Articles|
Applies to: C166 C Compiler
Information in this article applies to:
I am using a C167 device, and in my C code I divide a long by an int. When I look at the assembly code generated I expected to see a DIVL instruction to perform the 32x16 division. What I see, however, is a call to ?C_SLDIV.
How do I force the compiler to use a DIVL instruction instead?
In C, there is no operation that performs a 32-bit by 16-bit division. In C, all types used in basic operations must be of the same type. For that reason, when you divide a long by an int, the operation that is actually performed is a long by long division and this is handled by the ?C_SLDIV or ?C_ULDIV library routines.
?C_SLDIV is a library routine that performs signed long division. If you step through your souce code to the line where the division is performed, then open the Disassembly window you can step through the library routine to see what it is doing. You will see that ?C_SLDIV calls ?C_ULDIV which in turn executes the DIVLU instruction, the unsigned version of the DIVL instruction. Use of generic routines allows for range checking and for code re-use.
There is currently no way to force the compiler to generate in-line code using the DIVL/DIVLU instructions. If that is necessary in your application, you must either reduce divisions to 16-bit operations or use in-line assembler to generate the DIV instructions manually.
Article last edited on: 2004-03-05 16:27:28
Did you find this article helpful? Yes No
How can we improve this article?