[PATCH] Support Cell SPU floating point

trevor_smigiel@playstation.sony.com trevor_smigiel@playstation.sony.com
Thu Sep 6 19:57:00 GMT 2007


Here is a new version of the patch which addresses the issues raised.
Changes from the previous patch are:

- rename STANDARD_DENORMS to HONOR_NONIEEE_DENORMS
- move checking of new macros (like DENORM_OPERANDS_ARE_ZERO) from 
  const-fold.c and simplify-rtx.c to real.c, in the new routines
  real_arithmetic_fold, real_compare_fold, and real_convert_fold.
- use a mode argument to ROUND_TOWARDS_ZERO instead of a size argument.
- add FLO_mode to fp-bit.h

Trevor

in gcc/

2007-09-06  Trevor Smigiel <Trevor_Smigiel@playstation.sony.com>

	* doc/tm.texi (DENORM_OPERANDS_ARE_ZERO, DENORM_RESULTS_ARE_ZERO,
	ZERO_RESULTS_ARE_POSITVE, REAL_CONVERT_AS_IEEE): Document new macros.
	(ROUND_TOWARDS_ZERO): Document new mode argument.
	* flags.h (HONOR_NONIEEE_DENORMS): Define.
	* defaults.h (ROUND_TOWARDS_ZERO): Add size argument.
	(MODE_HAS_SIGN_DEPENDENT_ROUNDING): Pass size to ROUND_TOWARDS_ZERO.
	(DENORM_OPERANDS_ARE_ZERO, DENORM_RESULTS_ARE_ZERO,
	ZERO_RESULTS_ARE_POSITVE, REAL_CONVERT_AS_IEEE): Define.
	* fold-const.c (const_binop): Call real_arithmetic_fold.
	(fold_relational_const): Call real_compare_fold.
	(fold_convert_const_real_from_real): Call real_convert_fold.
	(fold_real_zero_addition_p): Return false when HONOR_NONIEEE_DENORMS
	is true.
	(fold_binary): Don't allow certain optimizations when
	HONOR_NONIEEE_DENORMS is true.
	* real.c (real_is_denorm, real_convert_ieee, real_arithmetic_fold,
        real_compare_fold, real_convert_fold): Define.
	(round_for_format): Handle round_towards_zero field.
	(ieee_single_format, mips_single_format, motorola_single_format,
	ieee_double_format, mips_double_format, motorola_double_format,
	ieee_extended_motorola_format, ieee_extended_intel_96_format,
	ieee_extended_intel_128_format,
	ieee_extended_intel_96_round_53_format, ibm_extended_format,
	mips_extended_format, ieee_quad_format, mips_quad_format,
	vax_f_format, vax_d_format, vax_g_format, decimal_single_format,
	decimal_double_format, decimal_quad_format, c4x_single_format,
	c4x_extended_format, real_internal_format): Initialize
	round_towards_zero field.
	(spu_extended_format): Define new real format.
	* real.h (real_format): Add round_towards_zero field.
	(real_arithmetic_fold, real_compare_fold, real_convert_fold,
        spu_extended_format): Declare.
	* simplify-rtx.c (simplify_const_unary_operation): Call
	real_convert_fold for FLOAT_EXTEND when REAL_CONVERT_AS_IEEE is
	true.
	(simplify_binary_operation_1): Don't allow certain optimizations when
	HONOR_NONIEEE_DENORMS is true.
	(simplify_const_binary_operation): Call real_arithmetic_fold.
	(simplify_const_relational_operation): Call real_compare_fold.
	* c-common.c (c_common_truthvalue_conversion): Call real_compare_fold.
	* config/spu/spu.c (spu_override_options):  Initialize
	REAL_MODE_FORMAT for SFmode.
	* config/spu/spu.h (ROUND_TOWARDS_ZERO, DENORM_OPERANDS_ARE_ZERO,
	DENORM_RESULTS_ARE_ZERO, ZERO_RESULTS_ARE_POSITVE,
	REAL_CONVERT_AS_IEEE, LARGEST_EXPONENT_IS_NORMAL): Define.
	(MODE_HAS_NANS, MODE_HAS_INFINITIES,
	MODE_HAS_SIGN_DEPENDENT_ROUNDING): Delete.
	* config/fp-bit.h (FLO_mode): Define.
	* config/fp-bit.c: Include insn-modes.h.
        (pack_d, _fpmul_parts, _fpdiv_parts): Pass FLO_mode as argument to
        ROUND_TOWARDS_ZERO.

in gcc/testsuite/

2007-09-06  Trevor Smigiel <Trevor_Smigiel@playstation.sony.com>
	* gcc.c-torture/execute/ieee/fold.c: Add.

* Trevor Smigiel <Trevor_Smigiel@playstation.sony.com> [2007-08-28 17:11]:
> This patch does three things:
> 
> 1) Add Cell SPU extended single precision format to real.c
> 2) Define macros for constant folding of denormalized numbers
> 3) Define macros to prevent certain optimizations on denorms
> 
> The latter 2 parts are necessary to get proper constant folding and
> optimization on SPU which does not fully support IEEE floats.  A comment
> in real.c describes the differences:
> 
> /*  SPU Single Precision (Extended-Range Mode) format is the same as IEEE
>     single precision with the following differences:
>       - infinities are not supported.  Instead MAX_FLOAT or MIN_FLOAT are
>         generated
>       - NaNs are not supported
>       - the range of non-zero numbers in binary is
>          (001)[1.]000...000 to (255)[1.]111...111
>       - denormals can be represented, but are treated as +0.0 when
>         used as an operand and are never generated as a result
>       - -0.0 can be represented but a zero result is always +0.0
>       - the only supported rounding mode is trunction (towards zero)
> 
>     SPU Double Precision format is the same as IEEE with the following
>     differences:
>       - denorms can be generated as a result, but are treated as zero
>         when used as an operand
> 
>     When converting between float and double, Infinity and NaN patterns
>     are honored.  For example, 0x7f800000 will convert to
>     0x7ff0000000000000, not 0x47f0000000000000;  and 0x7ff0000000000000
>     converts to 0x7f800000, not 0x7fffffff.  */
> 
> A couple of debatable choices are: (of course, it is all debatable)
> 
> - the name STANDARD_DENORM.  Its purpose is to prevent optimization,
> perhaps it would be better named as SAFE_FOR_DENORM, as in "this
> optimization is safe even if an operand is a denorm."  There could be a
> similar macro for negative zero, but handling denorms handles all the -0
> cases too.  In fact, our internal implementation uses only
> SAFE_FOR_MINUS_ZERO.
> 
> - converting denorms to zero in const-fold.c and simplify-rtx.c.  It
> could be done in real.c as part of the format.  The arithmetic in real.c
> is modeless, and I didn't think it was appropriate to add mode arguments
> to most of the functions or to the REAL_VALUE structure.  Compiler
> internal computations might not want real.c to operate in a format
> specific manner.   The advantage of doing it in real.c is that it is
> only done in one place.  In our internal implementation, we did pass a
> mode argument to most functions in real.c.
> 
> The patch was bootstrapped on x86 by Andrew and had no new failures.
> 
> The testsuite results on SPU do change quite a bit, as expected.  Some
> failures become passes, and some passes become failures.  These do need
> to be handled, and I hope to get some help doing so after the basic
> patch is accepted.
> 
> Trevor
> 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: spu-float-2.patch
Type: text/x-diff
Size: 41897 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20070906/448a07b0/attachment.bin>


More information about the Gcc-patches mailing list