Page 1 of 1
Bug with shift left greater than 8
Posted: Tue Jan 15, 2013 6:44 pm
by ylanchec
Hello,
I have seen a problem if i use the operators
"<< 16" or "
<< 32" on a 32bit word. the value become zero.
If i simulate it in flowcode it works, but if i put in a real pic it does not works.
illustration :
- bug1.png
- (52.8 KiB) Downloaded 1168 times
- bug2.png
- (16.9 KiB) Downloaded 2556 times
Is it a problem of the compiler ?
workaround :
If i make a multiplication by
65536 or
16777216 on the same word it works.
Yann
Re: Bug with shift left greater than 8
Posted: Tue Jan 15, 2013 10:30 pm
by ylanchec
files for testing ...
Re: Bug with shift left greater than 8
Posted: Tue Jan 15, 2013 11:27 pm
by Enamul
If you are trying to say FCv5's ULong does simulate but don't work in real world; you can have a look in my post where I have shown the problem and work around.
http://www.matrixmultimedia.com/mmforum ... 4&start=25
You can see test1,2 & 3 where I have shown the issue.
Re: Bug with shift left greater than 8
Posted: Wed Jan 16, 2013 12:23 pm
by JonnyW
Hi. If this is a problem with shifting by constants, it is likely the PIC instruction set only reserves space in its shift instructions for an 8-bit shift (so 3 bits). I have seen this issue on several compilers - it is typically only an issue when shifting by a constant.
Perhaps you could create a global variable (not a constant) initialised to 16 or 32 and try shifting by this. Sometimes this gets around the problem. An alternative is to do the shift in parts:
global int shift8 = 8
.....
result = (value << shift8) << shift8
This might also work OK. If not, then there is a bug in the bit-shifting method of ulong somewhere in the compiler, and I'm afraid you will have to rely on the multiply workaround.
Cheers,
Jonny
Re: Bug with shift left greater than 8
Posted: Wed Jan 16, 2013 11:46 pm
by ylanchec
hello
Thank you for your reply.
I have tested your solution but it does not work.
FCV_OCTET = 0x43;
FCV_MOT32 = FCV_MOT32 | (FCV_OCTET << FCV_SHIFT16);
FCV_OCTET = 0x44;
FCV_MOT32 = FCV_MOT32 | (FCV_OCTET << FCV_SHIFT24);
The strange thing is that the right shift 8 , 16 or 24 works !
For the moment i will use the multiply.
Can you ask bootc to correct this ?
Best regards
Yann