Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 13 Mar 2012 16:14:25 +1100 (EST)
From:      Bruce Evans <brde@optusnet.com.au>
To:        Dimitry Andric <dim@freebsd.org>
Cc:        svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org
Subject:   Re: svn commit: r232894 - head/contrib/llvm/tools/clang/lib/Basic
Message-ID:  <20120313153902.Y1611@besplex.bde.org>
In-Reply-To: <201203122107.q2CL7MYo086974@svn.freebsd.org>
References:  <201203122107.q2CL7MYo086974@svn.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, 12 Mar 2012, Dimitry Andric wrote:

> Log:
>  Pull in r145194 from upstream clang trunk:
>
>    Make our handling of MMX x SSE closer to what gcc does:
>
>    * Enabling sse enables mmx.
>    * Disabling (-mno-mmx) mmx, doesn't disable sse (we got this right already).
>    * The order in not important. -msse -mno-mmx is the same as -mno-mmx -msse.
>
>  Some configure scripts depend on this.
>
>  PR:		i386/165968
>  MFC after:	3 days

Can you turn off use of SSE[2] for float and double precision on i386?
This use might break the ABI, and FreeBSD headers don't support it.

I use the following to hack around the brokenness:

% Index: math.h
% ===================================================================
% RCS file: /home/ncvs/src/lib/msun/src/math.h,v
% retrieving revision 1.82
% diff -u -2 -r1.82 math.h
% --- math.h	12 Nov 2011 19:55:48 -0000	1.82
% +++ math.h	4 Jan 2012 05:09:51 -0000
% @@ -125,4 +130,10 @@
%      : __signbitl(x))
% 
% +#ifdef __SSE_MATH__
% +#define	__float_t	float
% +#endif
% +#ifdef __SSE2_MATH__
% +#define	__double_t	double
% +#endif
%  typedef	__double_t	double_t;
%  typedef	__float_t	float_t;

Parts of my libm make critical (at least for optimality) use of float_t
and double_t, and break when clang doesn't match either gcc's behaviour
or what the headers say they are.  The above changes the header to
match clang's behaviour.  There is still an ABI problem.  Although
the ABI isn't strictly broken (since clang uses the normal ABI for
function calls), programs and libraries should be able to assume that
float_t and double_t are independent of the compiler; but with clang,
they even depend on the compiler flags.  Also, converting to the normal
ABI across function calls is a slow operation.  clang on most of libm
ends up being slower on i386 with the SSE "optimization" than gcc
without this optimization.  clang doesn't really understand the i387
so it is even slower without this opimization.

FLT_EVAL_METHOD is also quite broken (it is -1, which is only correct
for clang with SSE because -1 can mean anything and what it actually
means is undocumented).  My libm also makes critical use of
FLT_EVAL_METHOD, but I havn't tested the parts that do as much as
the parts that use float_t etc., and it turns out that use of float_t
etc. makes FLT_EVAL_METHOD unimportant.

clang and gcc define __FLT_EVAL_METHOD__, but get it wrong in different
ways, so this definition is unusuable.  For example, it is always 0 for
clang; this is correct with SSE, but without SSE, -1 is correct.  Thus
__FLT_EVAL_METHOD__ is unusable for defining FLT_EVAL_METHOD.

The SSE defines work better and can be used to define FLT_EVAL_METHOD
as well as float_t and double_t.  You just have to know that clang has
the same compiler bugs^Wfeatures as gcc, so that FLT_EVAL_METHOD must
be define as -1 if the i387 is used.

Note that __SSE[2]_MATH__ are quite different from __SSE[2]__.  My
libm also uses the latter in critical ways without problems.

Bruce



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20120313153902.Y1611>