here are my results
I set an interrupt timer to go off after 0x8000 cycles, and when the interrupt fired, each of these code blocks (which perform the exact task) performed as follows.
i = 0;
int j = 5;
int quotient = 0;
int remainder = 0;
int this_op_represents_how_long_it_takes_to_access_quot = 0;
int this_op_represents_how_long_it_takes_to_access_rem = 0;
TMR1 = 0;
while(1){
i++;
quotient = j / 2;
remainder = j % 2;
this_op_represents_how_long_it_takes_to_access_quot = quotient;
this_op_represents_how_long_it_takes_to_access_rem = remainder;
}
0x024A (decimal 586) times performed
56 cycles per loop
i = 0;
int j = 5;
div_t divresult;
int this_op_represents_how_long_it_takes_to_access_quot = 0;
int this_op_represents_how_long_it_takes_to_access_rem = 0;
TMR1 = 0;
while(1){
i++;
divresult = div(j,2);
this_op_represents_how_long_it_takes_to_access_quot = divresult.quot;
this_op_represents_how_long_it_takes_to_access_rem = divresult.rem;
}
0x02E9 (decimal 745) times performed
44 cycles per loop
i = 0;
this_op_represents_how_long_it_takes_to_access_quot = 0;
this_op_represents_how_long_it_takes_to_access_rem = 0;
TMR1 = 0;
while(1){
i++;
asm volatile("MOV _j, w4");
asm volatile("MOV #2, w5");
asm volatile("REPEAT #0x11");
asm volatile("DIV.SW w4, w5");
asm volatile("MOV w0, _this_op_represents_how_long_it_takes_to_access_quot");
asm volatile("MOV w1, _this_op_represents_how_long_it_takes_to_access_rem");
}
0x0493 (decimal 1171) times performed
28 cycles per loop
This is a demonstration of how the inline assembly can do it. I am just asking if C has a "perfectly" streamlined/optimized operator for this.