This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: [ping][patch] Fixed-point patch 4/10


> > 
> > >   This error comes from valid user code that tries to operate on
> > > mixed data types of integers and fractional types.
> > > Ex: 
> > > long long a; /* 63 integral bits + a sign bit. */
> > > long long _Fract b; /* 63 fractional bits + a sign bit.  */
> > > b = a * b; // For this operation (a * b), GCC tries to find 
> > an accum mode
> > > that can support at least 63 integral bits and 63 fractional bits.
> > > But, if the target doesn't have this kind of accum mode, 
> GCC fails.
> > 
> > It appears to me that the result type in N1169 is to be the 
> > fixed-point 
> > type (with the specified overflow rules applied) for 
> > arithmetic between 
> > fixed-point and integer types.
> > 
> > If the problem here is an internal implementation matter - if 
> > you generate 
> > the correct result type, but need this other mode for 
> > internal arithmetic 
> > - then that's a bug in the implementation.  Preferably this 
> > bug should be 
> > fixed (if the target doesn't have the modes, generate 
> > appropriate code 
> > using a libgcc function if necessary), but if that is hard 
> > then file a PR 
> > in Bugzilla, add a comment referencing the PR, and use sorry 
> > (), which 
> > will output a message starting "sorry, unimplemented: ".
> 
>   What you describe is right.  The current implementation may 
> not support
> all kinds of mixed integer and fixed-point types.  I will use
> 
>       sorry ("GCC cannot support operators with integer types 
> and fixed-point \
> types that have too many integral and fractional bits together");
> 
>   About the PR, after all patches are checked in, I will file one bug 
> for this case.
> 
> > 
> > >   Maybe I will use this error message.
> > > ---
> > >       error ("should not use integer types and fixed-point 
> > types that have too\
> > > \nmany integral and fractional bits together");
> > > ---
> > > Is it ok?
> > 
> > Don't put newlines in the middle of messages; just output the 
> > message, 
> > however long it is, and let the user use options to wrap if 
> > it they so 
> > wish.
> > 
> > >   I will change to gcc_assert (0), because these cases 
> > should not happen.
> > 
> > The idiom is gcc_unreachable ().
> 
>   Yes.  Thanks!
> 
> Regards,
> Chao-ying
> 

  Here is the new patch and updated ChangeLog.  The new changes from the last time
include:

1. In "c_common_fixed_point_type_for_size()", we test if the target
can support the mode and use "sorry()".
  if (mode == VOIDmode || !targetm.scalar_mode_supported_p (mode))
    {
      sorry ("GCC cannot support operators with integer types and fixed-point \
types that have too many integral and fractional bits together");
      return 0;
    }

2. In "c_common_type()", use gcc_unreachable ().

3. Update install.texi to mention MIPS is enabled by default.

4. Update ChangeLog.

  Is it ok to check in?  Thanks a lot!

gcc/ChangeLog
2007-08-16  Chao-ying Fu  <fu@mips.com>

	* c-common.h (enum rid): Add new enumeration values of RID_SAT,
	RID_FRACT, and RID_ACCUM.  RID_SAT needs to be inserted before
	RID_ONEWAY, so it can be checked in declspecs_add_type.
	(c_common_fixed_point_type_for_size): Declare.
	* c-parser.c (reswords): Add _Fract, _Accum, and _Sat.
	(c_token_starts_typename): Handle RID_FRACT, RID_ACCUM, and RID_SAT.
	(c_token_starts_declspecs): Likewise.
	(c_parser_declspecs): Likewise.
	(c_parser_attributes): Likewise.
	* c-tree.h (enum c_typespec_keyword): Add cts_fract and cts_accum.
	(c_declspecs): Add saturating_p.
	* c-decl.c (build_null_declspecs): Initialize saturating_p.
	(declspecs_add_type): Avoid using complex with _Fract, _Accum, or _Sat.
	Handle RID_SAT.
	Avoid using void, bool, char, int, float, double, _Decimal32,
	_Decimal64, _Decimal128, and complex with _Sat.
	Handle RID_FRACT and RID_ACCUM.
	Make sure _Sat is used with _Fract or _Accum.
	(finish_declspecs): Handle cts_fract and cts_accum.
	* c-common.c (fixed-value.h): New include.
	(constant_expression_warning): Handle FIXED_CST.
	(overflow_warning): Likewise.
	(warnings_for_convert_and_check): Likewise.
	(c_common_fixed_point_type_for_size): New.
	(c_common_type_for_mode): Handle fixed-point modes to
	return various saturating/non-saturating, signed/unsigned types.
	(c_common_signed_or_unsigned_type): Support fixed-point types.
	(shorten_compare): Check fixed-point zero.
	Handle FIXED_POINT_TYPE.
	(c_common_truthvalue_conversion): Handle FIXED_CST.
	Handle FIXED_POINT_TYPE.
	(c_common_nodes_and_builtins): Record builtin types for fixed-point
	types.
	(handle_mode_attribute): Handle fixed-point modes.  Need to check
	if the signness of base type and fixed-point modes are consistent.
	(handle_vector_size_attribute): Handle fixed-point modes.
	(same_scalar_type_ignoring_signedness): Handle FIXED_POINT_TYPE.
	(warn_for_div_by_zero): Check fixed-point zero.
	* c-typeck.c (c_common_type): Check FIXED_POINT_TYPE.  Build
	a common fixed-point type based on fbit, ibit, sign, and saturation.
	(build_unary_op): Allow FIXED_POINT_TYPE for CONVERT_EXPR,
	NEGATE_EXPR, TRUTH_NOT_EXPR, PREINCREMENT_EXPR, POSTINCREMENT_EXPR,
	PREDECREMENT_EXPR, and POSTDECREMENT_EXPR.
	(convert_for_assignment): Support FIXED_POINT_TYPE.
	(digest_init): Handle FIXED_POINT_TYPE.
	(build_binary_op): Support FIXED_POINT_TYPE in *_DIV_EXPR,
	TRUTH_ANDIF_EXPR, TRUTH_ORIF_EXPR, TRUTH_AND_EXPR, TRUTH_OR_EXPR,
	TRUTH_XOR_EXPR, RSHIFT_EXPR, LSHIFT_EXPR, EQ_EXPR, NE_EXPR, LE_EXPR,
	GE_EXPR, LT_EXPR, GT_EXPR.
	* target-def.h (TARGET_FIXED_POINT_SUPPORTED_P): New.
	(TARGET_INITIALIZER): Add TARGET_FIXED_POINT_SUPPORTED_P.
	* target.h (gcc_target): Add fixed_point_supported_p.
	* targhooks.c (default_scalar_mode_supported_p): Handle MODE_FRACT,
	MODE_UFRACT, MODE_ACCUM, and MODE_UACCUM.
	(default_fixed_point_supported_p): Define.
	* targhooks.h (default_fixed_point_supported_p): Declare.
	* doc/tm.texi (TARGET_FIXED_POINT_SUPPORTED_P): Add.
	* doc/install.texi (Configuration): Add --enable-fixed-point.
	* configure.ac (--enable-fixed-point): New to enable fixed-point
	arithmetic extension to C.  For mips targets, we enable it by default.
	* configure, config.in: Regenerate.



Attachment: c-parser.diff
Description: c-parser.diff


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]