Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Thu, 28 Feb 2019 03:09:54 +1100 (AEDT)
From: Damian McGuckin <damianm@....com.au>
To: musl@...ts.openwall.com
Subject: Re: FE Exception triggered by comparison


Thanks for the feedback.

On Wed, 27 Feb 2019, Alexander Monakov wrote:

> On Thu, 28 Feb 2019, Damian McGuckin wrote:
>
>> I tried the code below, I was just shocked.
>>
>> 	#include	<math.h>
>> 	#include	<stdio.h>
>>
>> 	main()
>> 	{
>> 		double x = 5.0;
>>
>> 		x -= x, x /= x;
>> 		printf("what %s\n", isnan(x) ? "yes" : "no!");
>> 		return(0);
>> 	}
>>
>> Looking at the assembler, there is a subroutine call to __isnan. Awful!
>
> Hm, no, for x86 with GCC you should not see that: the compiler knows how 
> to expand isnan efficiently.  Are you perhaps on OS X and the 'gcc' 
> command actually invokes Clang/LLVM?

No.

> If not, can you show output of 'gcc -v', command-line flags you used, 
> and the assembly you're seeing?

 	gcc -O3 -S -msse4.2 -mfma mynan.c

Here is the assembler:

 	.file	"mynan.c"
 	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
 	.string	"yes"
.LC1:
 	.string	"no!"
.LC3:
 	.string	"what %s\n"
 	.section	.text.startup,"ax",@progbits
 	.p2align 4,,15
 	.globl	main
 	.type	main, @function
main:
.LFB14:
 	.cfi_startproc
 	vxorpd	%xmm0, %xmm0, %xmm0
 	subq	$8, %rsp
 	.cfi_def_cfa_offset 16
 	vdivsd	%xmm0, %xmm0, %xmm0
 	call	__isnan
 	movl	$.LC0, %esi
 	testl	%eax, %eax
 	movl	$.LC1, %eax
 	cmove	%rax, %rsi
 	movl	$.LC3, %edi
 	xorl	%eax, %eax
 	call	printf
 	xorl	%eax, %eax
 	addq	$8, %rsp
 	.cfi_def_cfa_offset 8
 	ret
 	.cfi_endproc
.LFE14:
 	.size	main, .-main
 	.ident	"GCC: (GNU) 4.8.5 20150623 (Red Hat 4.8.5-36)"
 	.section	.note.GNU-stack,"",@progbits

Regards - Damian

Pacific Engineering Systems International, 277-279 Broadway, Glebe NSW 2037
Ph:+61-2-8571-0847 .. Fx:+61-2-9692-9623 | unsolicited email not wanted here
Views & opinions here are mine and not those of any past or present employer

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.