Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > lccwin fails to generate NOPs

Reply
Thread Tools

lccwin fails to generate NOPs

 
 
Marcin Grzegorczyk
Guest
Posts: n/a
 
      01-07-2011
BartC wrote:
> "Antoine Leca" <(E-Mail Removed)> wrote in message
> news:4d275068$0$19114$(E-Mail Removed)...
>> Since the C standard requires the full evaluation of constant
>> expressions, every compiler includes constant folding,

>
> I don't know about that; with cross-compilers, for example, it might not
> be possible for the machine running the compiler to perform arithmetic
> exactly the same way as the target machine.


If a compiler knows how to generate code for the target platform, I
think it can know how that platform performs integer arithmetic, and
emulate that if necessary. C99 requires that even for the preprocessor,
anyway.

For floating-point constant expressions, compile-time evaluation is not
required; but if done, there is a minimum requirement about the
precision (N1256 6.6p5).
--
Marcin Grzegorczyk
 
Reply With Quote
 
 
 
 
glen herrmannsfeldt
Guest
Posts: n/a
 
      01-07-2011
In comp.compilers.lcc BartC <(E-Mail Removed)> wrote:
(snip, someone wrote)

>> Since the C standard requires the full evaluation of constant
>> expressions, every compiler includes constant folding,


> I don't know about that; with cross-compilers, for example, it might not be
> possible for the machine running the compiler to perform arithmetic exactly
> the same way as the target machine.


It might be that floating point constant expressions are not
required to be evaluated at compile time. In any case, it isn't
unusual to get different results at compile time than run time
for floating point expressions. I do remember at the time of the
Pentiam FDIV bug some test programs used a constant expression
that was evaluated in software emulated floating point at compile
time, and didn't test at all for the bug. More generally, you
don't always get equality for test between constant and variable
floating point expressions.

-- glen
 
Reply With Quote
 
 
 
 
glen herrmannsfeldt
Guest
Posts: n/a
 
      01-07-2011
In comp.compilers.lcc Marcin Grzegorczyk <(E-Mail Removed)> wrote:
(snip)

> If a compiler knows how to generate code for the target platform, I
> think it can know how that platform performs integer arithmetic, and
> emulate that if necessary. C99 requires that even for the preprocessor,
> anyway.


Another that I learned some years ago that isn't required is string
subscripts, such as "abcd"[2], which I tried to use in a case statement.

> For floating-point constant expressions, compile-time evaluation is not
> required; but if done, there is a minimum requirement about the
> precision (N1256 6.6p5).


-- glen
 
Reply With Quote
 
Niklas Holsti
Guest
Posts: n/a
 
      01-08-2011
Ian Collins wrote:
> On 01/ 6/11 10:44 AM, Keith Thompson wrote:
>> BGB<(E-Mail Removed)> writes:
>> [...]
>>> a __nop keyword almost makes sense, since if-anything, it can tell the
>>> compiler not to optimize it away... (vs the compiler doing its best to
>>> figure out that "some function in another compilation unit accessed via
>>> a function pointer and performing a few global variable assignments" is
>>> in-fact no-op...).

>>
>> I'm still trying to understand why this, or anything like it, would make
>> sense. What would be the benefit of forcing NOP instructions in the
>> object code generated by a C compiler?

>
> Poor man's delay? Sometimes hardware devices require a minimum delay
> between being written and being read.


That is indeed a fairly common need for C programs on small processors.

The IAR C compilers for (at least) the 8051 and AVR support an
"intrinsic" instruction written "__no_operation" that is defined to
generate a NOP instruction.

For the AVR, the IAR C compiler also has an intrinsic "__delay_cycles"
which takes as parameter a positive number and generates code, probably
using NOPs, that takes that number of cycles to execute but has no other
effect on the computation.

These effects can of course be achieved by assembly-language insertions.
Still, I think the C language could reasonably include a standard syntax
for creating a small delay of an implementation-defined and possibly
variable length.

--
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
. @ .
 
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
MIDI files in C(lccwin/WIN XP) ravi C Programming 4 08-02-2010 05:44 PM
Failed to generate a user instance of SQL Server. Only an integratedconnection can generate a user instance. Harlan Messinger ASP .Net 2 03-28-2010 06:51 PM
Status of lccwin sandeep C Programming 9 02-08-2010 05:48 PM
How to generate warnings when How generate a warning when int is converted to bool or vice versa? PengYu.UT@gmail.com C++ 3 04-06-2006 11:24 PM
How to generate variable labels for same component within a generate loop Weng Tianxiang VHDL 5 02-16-2006 01:45 PM



Advertisments