This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
| Other format: | [Raw text] | |
Jeffrey Walton <noloader@gmail.com> writes:
> Any ideas on what knob turning I should perform? The C/C++ source for
> `sadd` is below. There's not much to it - just a test on an x86 flag.
I don't think there is any straightforward way to do this. gcc is not
in the business of letting you pick and choose the assembly instructions
that it generates--that's what the assembler is for. If you really must
have an add instruction, use an asm statement.
> int sadd(int a, int b, int* r)
> {
> int overflow = 0;
> int result = a + b;
>
> asm volatile("jo 1f");
> asm volatile("jmp 2f");
>
> asm volatile("1:");
> overflow = 1;
>
> asm volatile("2:");
> if(r)
> *r = result;
>
> // TRUE (1) if safe to use
> return !overflow;
> }
Note that jumping from one asm statement to another is explicitly not
supported and will fail in some cases. You can jump to a C label, but
not to an asm label.
Ian
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |