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 :
Is it a problem of the compiler ?
workaround :
If i make a multiplication by 65536 or 16777216 on the same word it works.
Yann
Bug with shift left greater than 8
Moderator: Benj
Re: Bug with shift left greater than 8
files for testing ...
- Attachments
-
- testaffich.zip
- fc5 file + proteus 7.10 file
- (21.23 KiB) Downloaded 263 times
- Enamul
- Posts: 1772
- Joined: Mon Mar 05, 2012 11:34 pm
- Location: Nottingham, UK
- Has thanked: 271 times
- Been thanked: 814 times
Re: Bug with shift left greater than 8
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.
http://www.matrixmultimedia.com/mmforum ... 4&start=25
You can see test1,2 & 3 where I have shown the issue.
- JonnyW
- Posts: 1230
- Joined: Fri Oct 29, 2010 9:13 am
- Location: Matrix Multimedia Ltd
- Has thanked: 63 times
- Been thanked: 290 times
- Contact:
Re: Bug with shift left greater than 8
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
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
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
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