Re: How to force an ADD asm instruction (x64)?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Jeffrey Walton <noloader@xxxxxxxxx> 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 of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux