Bug with shift left greater than 8

Moderator: Benj

Post Reply
ylanchec
Posts: 54
Joined: Mon Jan 14, 2013 10:14 pm
Has thanked: 2 times
Been thanked: 2 times
Contact:

Bug with shift left greater than 8

Post 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

ylanchec
Posts: 54
Joined: Mon Jan 14, 2013 10:14 pm
Has thanked: 2 times
Been thanked: 2 times
Contact:

Re: Bug with shift left greater than 8

Post by ylanchec »

files for testing ...
Attachments
testaffich.zip
fc5 file + proteus 7.10 file
(21.23 KiB) Downloaded 250 times

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: Bug with shift left greater than 8

Post 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.
Enamul
University of Nottingham
enamul4mm@gmail.com

User avatar
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

Post 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

ylanchec
Posts: 54
Joined: Mon Jan 14, 2013 10:14 pm
Has thanked: 2 times
Been thanked: 2 times
Contact:

Re: Bug with shift left greater than 8

Post 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

Post Reply