Re: generic assembly language available?

Julian Brown <brown@cs.bris.ac.uk>
25 Aug 2004 14:52:58 -0400

          From comp.compilers

Related articles
[3 earlier articles]
Re: generic assembly language available? choksheak@yahoo.com (ChokSheak Lau) (2004-07-14)
Re: generic assembly language available? phil@ultimate.com (2004-07-15)
Re: generic assembly language available? arnold@skeeve.com (2004-07-15)
Re: generic assembly language available? gergoe@math.bme.hu (2004-07-17)
Re: generic assembly language available? bear@sonic.net (Ray Dillinger) (2004-08-09)
Re: generic assembly language available? jacob@jacob.remcomp.fr (jacob navia) (2004-08-23)
Re: generic assembly language available? brown@cs.bris.ac.uk (Julian Brown) (2004-08-25)
| List of all articles for this month |

From: Julian Brown <brown@cs.bris.ac.uk>
Newsgroups: comp.compilers
Date: 25 Aug 2004 14:52:58 -0400
Organization: University of Bristol
References: 04-07-018 04-07-038 04-07-040 04-08-045 04-08-130
Keywords: C, assembler
Posted-Date: 25 Aug 2004 14:52:58 EDT

On 2004-08-23, jacob navia <jacob@jacob.remcomp.fr> wrote:
>
> I would say that an assembler that doesn't know about overflow is
> lacking some features... :-)
>
> I added this missing feature to lcc-win32, a "portable assembler" for
> many languages (Eiffel, objective C, Heron, C++ and maybe others)
>
> All in all I think C should introduce this feture:
>
> a*=b;
> if (_overflow())
> // overflow handling.


This worried me when I saw it before, I seem to remember, and it worries
me even more now. How can you be sure which operation you are testing
overflow from? With that syntax, you can't, especially not with an
optimising compiler. Is code ever inserted to make sure the operation is
"safe"?


What does this do:


    a = b+c+d;
    if (_overflow())
        // something


If (a) the first, (b) the second + operator causes an overflow? For that
matter, which addition is the first?


Overflow handling shouldn't be added to C in this way, since not all
processors look like x86s with condition-code flags which are
calculated unconditionally, etc.


I do quite like the idea of being able to test overflow, though I
can't think of a sensible C-like syntax for it. Some processors, eg
SH4, must know ahead-of-time whether overflow (or carry) should be
calculated or not, since then different instructions should be used
(addv, afaicr).


A better solution (thinking on my feet) might be a special built-in
type for overflow- and carry-augmented integers and overloaded
operators to go with them:


oint a, b, c;


    c = a+b;
    if (c.overflow)
        // something


This could probably even be done already (more or less) with inline asm
& C++.


Cheers,


Julian


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.