catrig[fl].c and inexact

Dimitry Andric dimitry at andric.com
Sat May 13 11:01:15 UTC 2017


On 12 May 2017, at 23:56, Steve Kargl <sgk at troutmask.apl.washington.edu> wrote:
> 
> So, I've been making improvements to my implementations of
> the half-cycle trig functions.  In doing so, I decide to
> add WARNS=2 to msun/Makefile.  clang 4.0.0 dies with an
> error about an unused variable in raise_inexact() from
> catrig[fl].c.
> 
> /usr/home/kargl/trunk/math/libm/msun/src/catrigl.c:195:2: error: unused variable
>      'junk' [-Werror,-Wunused-variable]
>        raise_inexact();
>        ^
> /usr/home/kargl/trunk/math/libm/msun/src/catrigl.c:56:45: note: expanded from
>      macro 'raise_inexact'
> #define raise_inexact() do { volatile float junk = 1 + tiny; } while(0)
>                                            ^
> Grepping catrig.o for the variable 'junk' suggests that 'junk' is
> optimized out (with at least -O2).

As far as I can see, this is not the case.  The simplest reduction is
this:

static const volatile float tiny = 0x1p-100;

void f(void)
{
  volatile float junk = 1 + tiny;
}

For i386-freebsd, this results in the following (boilerplate left out):

$ clang-4.0.0 -target i386-freebsd -O2 -S vol1.c -o -
[...]
	pushl	%ebp
	movl	%esp, %ebp
	pushl	%eax
	fld1
	fadds	tiny
	fstps	-4(%ebp)
	addl	$4, %esp
	popl	%ebp
	retl
[...]
tiny:
	.long	226492416               # float 7.88860905E-31

For amd64-freebsd:

$ clang-4.0.0 -target amd64-freebsd -O2 -S vol1.c -o -
[...]
.LCPI0_0:
	.long	1065353216              # float 1
[...]
	pushq	%rbp
	movq	%rsp, %rbp
	movss	tiny(%rip), %xmm0       # xmm0 = mem[0],zero,zero,zero
	addss	.LCPI0_0(%rip), %xmm0
	movss	%xmm0, -4(%rbp)
	popq	%rbp
	retq
[...]
tiny:
	.long	226492416               # float 7.88860905E-31

I also tried -O3, but it doesn't change the result.

-Dimitry

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 194 bytes
Desc: Message signed with OpenPGP
URL: <http://lists.freebsd.org/pipermail/freebsd-numerics/attachments/20170513/58fd166e/attachment.sig>


More information about the freebsd-numerics mailing list