Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Re: ARM7, DSP and mobile phone, how and why?

Reply
Thread Tools

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

 
 
glen herrmannsfeldt
Guest
Posts: n/a
 
      06-15-2004

(comp.lang.c added)

Wilco Dijkstra wrote:
> "42Bastian Schick" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...


>>On Thu, 10 Jun 2004 16:50:47 -0400, Jerry Avins <(E-Mail Removed)> 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

 
Reply With Quote
 
 
 
 
Jack Klein
Guest
Posts: n/a
 
      06-15-2004
On Tue, 15 Jun 2004 03:27:55 GMT, glen herrmannsfeldt
<(E-Mail Removed)> wrote in comp.lang.c:

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

>
> >>On Thu, 10 Jun 2004 16:50:47 -0400, Jerry Avins <(E-Mail Removed)> 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/~a...FAQ-acllc.html
 
Reply With Quote
 
 
 
 
Stephen Clarke
Guest
Posts: n/a
 
      06-16-2004
"Jack Klein" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.


 
Reply With Quote
 
Al Grant
Guest
Posts: n/a
 
      06-18-2004
Jack Klein <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>. ..
> 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
DR10. 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
iPhone4,iPhone3,Ipad,Apple Mobile,Blackberry Mobile,HTC Mobile,LGMobile,Motorola Mobile,Nokia Mobile,Samsung Mobile chen selina C++ 0 07-13-2010 08:53 AM
WTS APX-SL-DSP-3 288 port Voice/Data DSP cards isptrader VOIP 0 08-29-2005 04:32 PM
WTS APX-SL-DSP-3 288 port Voice/Data DSP cards isptrader VOIP 0 08-15-2005 05:40 PM
WTS APX-SL-DSP-3 288 port Voice/Data DSP cards isptrader VOIP 0 08-15-2005 05:32 PM
WTS: APX-SL-DSP-3 288 port Voice/Data DSP cards isptrader VOIP 0 08-03-2005 04:20 PM



Advertisments