Divide 32-bit by 16-bit number on a dsPIC
I managed to find a solution. Apparently, there is a dozen of __bultin functions used to force the compiler (xc16) to use specific assembly instructions or series of instructions. For example, to force the compiler to use specific DIV instructions, one can use one of the following __builtin functions:

signed int __builtin_divf(signed int num, signed int den);
signed int __builtin_divmodsd(signed long dividend, signed int divisor, signed int *remainder);
unsigned int __builtin_divmodud(unsigned long dividend, unsigned int divisor, unsigned int *remainder);
int __builtin_divsd(const long num, const int den);
unsigned int __builtin_divud(const unsigned long num, const unsigned int den);


However, one must be certain that the result (i.e., the quotient) fits to a 16-bit register, otherwise, results are unexpected. All these builtin_div functions execute within 18 clock cycles, while ___divsi3 function which compiler normally uses for 32/16-bit division takes up to 500 clock cycles.

To go back to my example from the beginning, the C code would look like this:

volatile int32_t num = 65537;
volatile int16_t den = 16384;
volatile int16_t res = __builtin_divsd(num, den);


The compiler produces the following assembly code:

MOV [W15-16], W0
MOV [W15-20], W1
MOV [W15-18], W2
REPEAT #0x11
DIV.SD W4, W2
MOV W0, [W15-14]


Case closed.