Re: code optimization in embedded systems
- From: Stefan Reuther <stefan.news@xxxxxxxx>
- Date: Fri, 16 Nov 2007 19:51:55 +0100
Grant Edwards wrote:
On 2007-11-16, Wilco Dijkstra <Wilco_dot_Dijkstra@xxxxxxxxxxxx> wrote:
The code generated for i/4 goes like this (for 32-bit int):
res = (i + ((unsigned)(i >> 31) >> 30)) >> 2;
ASR cannot be used for division by powers of 2 as it rounds
towards minus infinity rather than zero, so an explicit round
step done to round the result up if it is negative.
Ah. I forgot about the rounding towards zero requirement --
that's fairly new isn't it?
Such a requirement is in the C99 standard, but was not in C90. The more
important problem is that 'z=4; i/z' should yield the same value as
'i/4', and if the processor's divide instruction rounds towards zero,
the ASR replacement code must emulate that.
IIRC, Python and Pascal do it the other way (with a "mod"
operation to match).
Not that I know of. At least, Turbo Pascal uses the same 'div'
instruction as C compilers of the same era.
Stefan
.
- References:
- code optimization in embedded systems
- From: yusibin
- Re: code optimization in embedded systems
- From: Kirk Zurell
- Re: code optimization in embedded systems
- From: Ken Asbury
- Re: code optimization in embedded systems
- From: Jyrki Saarinen
- Re: code optimization in embedded systems
- From: Stefan Reuther
- Re: code optimization in embedded systems
- From: Jyrki Saarinen
- Re: code optimization in embedded systems
- From: Stefan Reuther
- Re: code optimization in embedded systems
- From: Grant Edwards
- Re: code optimization in embedded systems
- From: Wilco Dijkstra
- Re: code optimization in embedded systems
- From: Grant Edwards
- code optimization in embedded systems
- Prev by Date: Re: code optimization in embedded systems
- Next by Date: Re: code optimization in embedded systems
- Previous by thread: Re: code optimization in embedded systems
- Next by thread: Re: code optimization in embedded systems
- Index(es):
Relevant Pages
|