Subtraction + comparison in one asm instruction?

"Vincent Lefevre" <vincent+news@vinc17.org>
10 Aug 2002 02:12:44 -0400

          From comp.compilers

Related articles
Subtraction + comparison in one asm instruction? vincent+news@vinc17.org (Vincent Lefevre) (2002-08-10)
Re: Subtraction + comparison in one asm instruction? Peter-Lawrence.Montgomery@cwi.nl (Peter L. Montgomery) (2002-08-14)
Re: Subtraction + comparison in one asm instruction? iddw@hotmail.com (Dave Hansen) (2002-08-14)
Re: Subtraction + comparison in one asm instruction? walter@bytecraft.com (Walter Banks) (2002-08-23)
Re: Subtraction + comparison in one asm instruction? vincent+news@vinc17.org (Vincent Lefevre) (2002-08-23)
Re: Subtraction + comparison in one asm instruction? gdr@soliton.integrable-solutions.net (Gabriel Dos Reis) (2002-09-03)
Re: Subtraction + comparison in one asm instruction? vincent+news@vinc17.org (Vincent Lefevre) (2002-09-08)
[12 later articles]
| List of all articles for this month |

From: "Vincent Lefevre" <vincent+news@vinc17.org>
Newsgroups: comp.compilers
Date: 10 Aug 2002 02:12:44 -0400
Organization: a training zoo
Keywords: architecture, question
Posted-Date: 10 Aug 2002 02:12:44 EDT

Several processors (e.g. ARM, Sparc) can do a subtraction and the
associated comparison in only one instruction. Basically, this is done
by performing the subtraction and setting the flags.


However, it seems that some/most C compilers don't take advantage of
this and do both a subtraction and a comparison. This can be seen on
the code


int d;
int f(int c)
{
    d = c - 1;
    return c > 1;
}


or when writing c - 1 > 0 instead of c > 1. Each time, a comparison
is performed separately. A practical use would be a loop of the form:


    while (--c > 0)
        { ... }


(where c is a signed integer).


Are there compilers that do the subtraction and the comparison in
the same asm instruction (for the processors for which there is a
difference)? For the other compilers, have there been discussions,
plans to add such an optimization, etc?


Post a followup to this message

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