Re: ARM7, DSP and mobile phone, how and why?

Discussion in 'C Programming' started by glen herrmannsfeldt, Jun 15, 2004.

  1. (comp.lang.c added)

    Wilco Dijkstra wrote:
    > "42Bastian Schick" <> wrote in message
    > news:...


    >>On Thu, 10 Jun 2004 16:50:47 -0400, Jerry Avins <> wrote:


    >>>>This code doesn't look portable to me. shifts are not
    >>>>guaranteed to fill with the sign bit.
    >>>>Of course in the context of ARM compilers this should be OK.


    (snip)

    >>>HLL that doesn't offer both arithmetic and logical shifts when the
    >>>processor supports the is a crippled abomination.


    >>The question is, does the C or C++ standard define whether
    >>right-shifts are signed or unsigned ?

    (snip)

    > However compiler writers agree on most of these things (if they didn't
    > then their customers would force them anyway) so in reality most code
    > is portable across many compilers and architectures with little effort.
    > And yes I've never heard of a compiler that didn't support signed right
    > shifts corectly. The reason C89 didn't define signed arithemetic properly
    > was to allow 1-complements arithmetic. So if you want to make your
    > code compliant think 1-complements whenever you do anything.


    C supports both 1's complement and sign magnitude, though I
    don't know of any current producers of fixed point sign
    magnitude machines. I am told that Unisys still makes
    ones complement machines. As long as that is true, you can't
    rely on the results of signed shift.

    I believe, though, that a conforming C implementation can do
    logical right shift on signed data.

    -- glen
     
    glen herrmannsfeldt, Jun 15, 2004
    #1
    1. Advertising

  2. glen herrmannsfeldt

    Jack Klein Guest

    On Tue, 15 Jun 2004 03:27:55 GMT, glen herrmannsfeldt
    <> wrote in comp.lang.c:

    >
    > (comp.lang.c added)
    >
    > Wilco Dijkstra wrote:
    > > "42Bastian Schick" <> wrote in message
    > > news:...

    >
    > >>On Thu, 10 Jun 2004 16:50:47 -0400, Jerry Avins <> wrote:

    >
    > >>>>This code doesn't look portable to me. shifts are not
    > >>>>guaranteed to fill with the sign bit.
    > >>>>Of course in the context of ARM compilers this should be OK.

    >
    > (snip)
    >
    > >>>HLL that doesn't offer both arithmetic and logical shifts when the
    > >>>processor supports the is a crippled abomination.

    >
    > >>The question is, does the C or C++ standard define whether
    > >>right-shifts are signed or unsigned ?

    > (snip)
    >
    > > However compiler writers agree on most of these things (if they didn't
    > > then their customers would force them anyway) so in reality most code
    > > is portable across many compilers and architectures with little effort.
    > > And yes I've never heard of a compiler that didn't support signed right
    > > shifts corectly. The reason C89 didn't define signed arithemetic properly
    > > was to allow 1-complements arithmetic. So if you want to make your
    > > code compliant think 1-complements whenever you do anything.

    >
    > C supports both 1's complement and sign magnitude, though I
    > don't know of any current producers of fixed point sign
    > magnitude machines. I am told that Unisys still makes
    > ones complement machines. As long as that is true, you can't
    > rely on the results of signed shift.
    >
    > I believe, though, that a conforming C implementation can do
    > logical right shift on signed data.
    >
    > -- glen


    Since you asked, the result of right shifting a signed integer type
    with a negative value is implementation-defined. So yes indeed it can
    be a logical, rather than an arithmetic, right shift. It is certainly
    a QOI (Quality of Implementation) issue if a compiler does an
    arithmetic shift on an processor that provides an arithmetic right
    shift instruction.

    Note however that implementation-defined means that the compiler must
    document whichever it does.

    --
    Jack Klein
    Home: http://JK-Technology.Com
    FAQs for
    comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
    comp.lang.c++ http://www.parashift.com/c -faq-lite/
    alt.comp.lang.learn.c-c++
    http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html
     
    Jack Klein, Jun 15, 2004
    #2
    1. Advertising

  3. "Jack Klein" <> wrote in message
    news:...
    > Since you asked, the result of right shifting a signed integer type
    > with a negative value is implementation-defined. So yes indeed it can
    > be a logical, rather than an arithmetic, right shift. It is certainly
    > a QOI (Quality of Implementation) issue if a compiler does an
    > arithmetic shift on an processor that provides an arithmetic right
    > shift instruction.


    I once worked on a compiler for a processor that could
    do a logical right shift in 1 instruction/1 cycle, but an arithmetic
    right shift took 3 instructions/3 cycles. In that situation there were
    two conflicting quality issues:

    1. we wanted the fastest code for conformant C,
    2. we had to be able to do the right thing for code that assumed
    signed rightshift - there's a lot of it about.

    So we added a command-line option to select between them,
    and had to expend effort explaining to people (who didn't really want
    to hear it) that right-shift on signed types is implementation defined in C.

    Needless to say, later versions of the ISA had a 1 cycle
    arithmetic right-shift.

    Steve.
     
    Stephen Clarke, Jun 16, 2004
    #3
  4. glen herrmannsfeldt

    Al Grant Guest

    Jack Klein <> wrote in message news:<>...
    > Since you asked, the result of right shifting a signed integer type
    > with a negative value is implementation-defined. So yes indeed it can
    > be a logical, rather than an arithmetic, right shift.


    Worse, the result of _left_ shifting a negative integer is now
    undefined (it was implementation-defined in C89, according to
    DR108). An implementation is of course free to define this or
    any other undefined case, but it is not required to, and GCC
    doesn't - and uses this in optimizations, so that code which
    worked under C89 now breaks.
     
    Al Grant, Jun 18, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Zahoor
    Replies:
    1
    Views:
    847
    Darryl L. Pierce
    Nov 15, 2003
  2. Ken Seehart

    Python for ARM7?

    Ken Seehart, Sep 13, 2005, in forum: Python
    Replies:
    6
    Views:
    1,981
    Sybren Stuvel
    Sep 14, 2005
  3. Mr. SweatyFinger
    Replies:
    2
    Views:
    2,249
    Smokey Grindel
    Dec 2, 2006
  4. chen selina
    Replies:
    0
    Views:
    912
    chen selina
    Jul 7, 2010
  5. chen selina
    Replies:
    0
    Views:
    1,396
    chen selina
    Jul 13, 2010
Loading...

Share This Page