This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: portable signed right shift


>>>>> "dewar" == dewar  <dewar@gnat.com> writes:

    dewar> <<y = x / (1<< N)
    dewar> And trust the compiler to optimize it into a right-shift if that's
    dewar> appropriate for the architecture?
    >>> 

    dewar> Well in twos complement, that is not most peoples definition of a shift right
    dewar> for example, 

    dewar> Consider that -5 = 11111111111111011
    dewar> And           -4 = 11111111111111100
    dewar> and           -2 = 11111111111111110

    dewar> the result to most people of -5/2 = -2 would not seem like a shift :-)
    dewar> Of course there is no clear definition of what a right shift of a signed
    dewar> quantity means in the first place, and the original author did not give
    dewar> us a definition, so in a sense your definition is as good as another :-)

Sorry, I meant right shift of 2's complement signed number.

So I guess the only efficient thing to do is use autoconf and #ifdefs.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]