Incorrect bank used in unsigned long multiplication under certain circumstances.
Steps to reproduce:
This has been seen when __mul_32u__0000F_arg_a is in bank 0, and __mul_32u__0000F_arg_b and __mul_32u__0000F_1_i are in bank 1.
In the compiled code, in the calling function, bank 1 is selected, __mul_32u__0000F_arg_b is set up, bank 0 is selected, __mul_32u__0000F_arg_a is set up, and __mul_32u__0000F is called while still in bank 0. __mul_32u__0000F assumes that it is already in bank 1 on calling, clears __mul_32u__0000F_1_i, then clears RP0 (although it is already cleared).
The problem only occurs if the first argument is a constant.
char dummy[ 83 ];
unsigned char test( unsigned char multiplier )
unsigned long result;
//problem only appears when first arg is constant
result = 2000 * (unsigned long)multiplier;
return (unsigned char)result;
dummy = 1;
test( 200 );
dummy = 2;
Bank 1 should be selected before clearing __mul_32u__0000F_1_i, or before entering __mul_32u__0000F.
Is the problem 100% reproduceable:
IDE version: 6.20
Compiler version: 6.21
Target device: PIC16F876