Re: mspgcc "undefines" too-many-bits shifts in weird way

David Brown <[email protected]>
Newsgroups gmane.comp.hardware.texas-instruments.msp430.gcc.user
Message-ID <[email protected]>
On 22/04/13 19:32, Paul Sokolovsky wrote:
> Hello,
>
> On Mon, 22 Apr 2013 17:39:27 +0200
> David Brown <[email protected]> wrote:
>
>> Hi,
>>
>> When I compile the code you gave below (using gcc 4.6.3 from
>> 20120406), I get:
>>
>> warning: left shift count >= width of type [enabled by default]
>>
>> That is even without any sort of warning flags - and you should
>> normally enable lots of warnings.
>>
>> So here you have undefined code, and the compiler tells you of the
>> problem.  You really cannot get better than that by trying to invent
>> your own ideas about how you want to define this undefined behaviour.
>
> Yeah, but can get better by leveraging generally accepted ideas (math
> def of shift) and ideas put by more than just "you" into similar cases
> (other well known gcc ports, like x86) ;-).
>

Defining

	(x << n) = (x * 2^(n % 16)) & 0xffff

is just as good a mathematical definition as your desired

	(x << n) = (x * 2^n) & 0xffff

(for 16-bit ints)


Neither definition is "normal" mathematics.


And note that gcc on the x86 has exactly the same effect - it's just 
that with 32-bit ints, you get it with shifts of 32-bits or more.


> Thanks for all the flame, guys! ;-).
>

You're welcome :-)  It's important to think about these things and get 
the correct.




------------------------------------------------------------------------------
Precog is a next-generation analytics platform capable of advanced
analytics on semi-structured data. The platform includes APIs for building
apps and a phenomenal toolset for data science. Developers can use
our toolset for easy data analysis & visualization. Get a free account!
http://www2.precog.com/precogplatform/slashdotnewsletter
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.