I'm working with a
dsPIC33EP64GS506, and here you can find its datasheet: link.
In the dsPIC datasheet (page 294) it says that it supports 4 divide instructions:
DIV.S Wm,Wn Signed 16/16-bit integer divide DIV.SD Wm,Wn Signed 32/16-bit integer divide DIV.U Wm,Wn Unsigned 16/16-bit integer divide DIV.UD Wm,Wn Unsigned 32/16-bit integer divide
Now, when I try to divide two variables in C, a 32-bit by a 16-bit variable, compiler for some reason decides not to use these instructions, but the
___divsi3 function instead, which is a software implementation of the divide algorithm. I use Microchip's free xc16 compiler version. Take this simple C code for example:
volatile int32_t num = 65537; volatile int16_t den = 16384; volatile int16_t res = num/den;
compiles to the following assembly code:
MOV [W15-22], W0 MOV [W15-20], W1 MOV [W15-18], W2 ASR W2, #15, W3 RCALL ___divsi3 MOV W0, [W15-16]
How can I convince a compiler to use
DIV.SD instruction to divide these two variables?