Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 5 Sep 2013 15:50:34 +0000 (UTC)
From:      "Pedro F. Giffuni" <pfg@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org
Subject:   svn commit: r255252 - in stable/9/contrib: gcc gcc/doc gcclibs/libcpp gcclibs/libcpp/include
Message-ID:  <201309051550.r85FoYlT018223@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: pfg
Date: Thu Sep  5 15:50:34 2013
New Revision: 255252
URL: http://svnweb.freebsd.org/changeset/base/255252

Log:
  MFC	r254326:
  
  Add support for the GCC binary integer constants extension.
  
  This is required to build the i965 backend with newer versions of mesa.
  
  Original patch from Joerg Wunsch in GCC Bug 23479, under the GPLv2;
  also taken from there in OpenBSD.
  
  Obtained from:	gcc 4.3 (rev. 125346; GPLv2)

Modified:
  stable/9/contrib/gcc/ChangeLog.gcc43
  stable/9/contrib/gcc/doc/extend.texi
  stable/9/contrib/gcclibs/libcpp/expr.c
  stable/9/contrib/gcclibs/libcpp/include/cpplib.h
Directory Properties:
  stable/9/contrib/gcc/   (props changed)
  stable/9/contrib/gcclibs/   (props changed)

Modified: stable/9/contrib/gcc/ChangeLog.gcc43
==============================================================================
--- stable/9/contrib/gcc/ChangeLog.gcc43	Thu Sep  5 15:49:51 2013	(r255251)
+++ stable/9/contrib/gcc/ChangeLog.gcc43	Thu Sep  5 15:50:34 2013	(r255252)
@@ -1,3 +1,9 @@
+2007-06-05  Joerg Wunsch  <j.gnu@uriah.heep.sax.de> (r23479)
+
+	PR preprocessor/23479
+	* doc/extend.texi: Document the 0b-prefixed binary integer
+	constant extension.
+	
 2007-05-01  Dwarakanath Rajagopal <dwarak.rajagopal@amd.com> (r124341)
 
 	* doc/invoke.texi: Fix typo, 'AMD Family 10h core' instead of 

Modified: stable/9/contrib/gcc/doc/extend.texi
==============================================================================
--- stable/9/contrib/gcc/doc/extend.texi	Thu Sep  5 15:49:51 2013	(r255251)
+++ stable/9/contrib/gcc/doc/extend.texi	Thu Sep  5 15:50:34 2013	(r255252)
@@ -81,6 +81,7 @@ extensions, accepted by GCC in C89 mode 
 * Pragmas::             Pragmas accepted by GCC.
 * Unnamed Fields::      Unnamed struct/union fields within structs/unions.
 * Thread-Local::        Per-thread variables.
+* Binary constants::    Binary constants using the @samp{0b} prefix.
 @end menu
 
 @node Statement Exprs
@@ -10424,6 +10425,28 @@ Non-@code{static} members shall not be @
 @end quotation
 @end itemize
 
+@node Binary constants
+@section Binary constants using the @samp{0b} prefix
+@cindex Binary constants using the @samp{0b} prefix
+
+Integer constants can be written as binary constants, consisting of a
+sequence of @samp{0} and @samp{1} digits, prefixed by @samp{0b} or
+@samp{0B}.  This is particularly useful in environments that operate a
+lot on the bit-level (like microcontrollers).
+
+The following statements are identical:
+
+@smallexample
+i =       42;
+i =     0x2a;
+i =      052;
+i = 0b101010;
+@end smallexample
+
+The type of these constants follows the same rules as for octal or
+hexadecimal integer constants, so suffixes like @samp{L} or @samp{UL}
+can be applied.
+
 @node C++ Extensions
 @chapter Extensions to the C++ Language
 @cindex extensions, C++ language

Modified: stable/9/contrib/gcclibs/libcpp/expr.c
==============================================================================
--- stable/9/contrib/gcclibs/libcpp/expr.c	Thu Sep  5 15:49:51 2013	(r255251)
+++ stable/9/contrib/gcclibs/libcpp/expr.c	Thu Sep  5 15:50:34 2013	(r255252)
@@ -188,6 +188,11 @@ cpp_classify_number (cpp_reader *pfile, 
 	  radix = 16;
 	  str++;
 	}
+      else if ((*str == 'b' || *str == 'B') && (str[1] == '0' || str[1] == '1'))
+	{
+	  radix = 2;
+	  str++;
+	}
     }
 
   /* Now scan for a well-formed integer or float.  */
@@ -226,10 +231,22 @@ cpp_classify_number (cpp_reader *pfile, 
     radix = 10;
 
   if (max_digit >= radix)
-    SYNTAX_ERROR2 ("invalid digit \"%c\" in octal constant", '0' + max_digit);
+    {
+      if (radix == 2)
+	SYNTAX_ERROR2 ("invalid digit \"%c\" in binary constant", '0' + max_digit);
+      else
+	SYNTAX_ERROR2 ("invalid digit \"%c\" in octal constant", '0' + max_digit);
+    }
 
   if (float_flag != NOT_FLOAT)
     {
+      if (radix == 2)
+	{
+	  cpp_error (pfile, CPP_DL_ERROR,
+		     "invalid prefix \"0b\" for floating constant");
+	  return CPP_N_INVALID;
+	}
+
       if (radix == 16 && CPP_PEDANTIC (pfile) && !CPP_OPTION (pfile, c99))
 	cpp_error (pfile, CPP_DL_PEDWARN,
 		   "use of C99 hexadecimal floating constant");
@@ -321,11 +338,16 @@ cpp_classify_number (cpp_reader *pfile, 
   if ((result & CPP_N_IMAGINARY) && CPP_PEDANTIC (pfile))
     cpp_error (pfile, CPP_DL_PEDWARN,
 	       "imaginary constants are a GCC extension");
+  if (radix == 2 && CPP_PEDANTIC (pfile))
+    cpp_error (pfile, CPP_DL_PEDWARN,
+	       "binary constants are a GCC extension");
 
   if (radix == 10)
     result |= CPP_N_DECIMAL;
   else if (radix == 16)
     result |= CPP_N_HEX;
+  else if (radix == 2)
+    result |= CPP_N_BINARY;
   else
     result |= CPP_N_OCTAL;
 
@@ -376,6 +398,11 @@ cpp_interpret_integer (cpp_reader *pfile
 	  base = 16;
 	  p += 2;
 	}
+      else if ((type & CPP_N_RADIX) == CPP_N_BINARY)
+	{
+	  base = 2;
+	  p += 2;
+	}
 
       /* We can add a digit to numbers strictly less than this without
 	 needing the precision and slowness of double integers.  */
@@ -431,12 +458,25 @@ static cpp_num
 append_digit (cpp_num num, int digit, int base, size_t precision)
 {
   cpp_num result;
-  unsigned int shift = 3 + (base == 16);
+  unsigned int shift;
   bool overflow;
   cpp_num_part add_high, add_low;
 
-  /* Multiply by 8 or 16.  Catching this overflow here means we don't
+  /* Multiply by 2, 8 or 16.  Catching this overflow here means we don't
      need to worry about add_high overflowing.  */
+  switch (base)
+    {
+    case 2:
+      shift = 1;
+      break;
+
+    case 16:
+      shift = 4;
+      break;
+
+    default:
+      shift = 3;
+    }
   overflow = !!(num.high >> (PART_PRECISION - shift));
   result.high = num.high << shift;
   result.low = num.low << shift;

Modified: stable/9/contrib/gcclibs/libcpp/include/cpplib.h
==============================================================================
--- stable/9/contrib/gcclibs/libcpp/include/cpplib.h	Thu Sep  5 15:49:51 2013	(r255251)
+++ stable/9/contrib/gcclibs/libcpp/include/cpplib.h	Thu Sep  5 15:50:34 2013	(r255252)
@@ -745,6 +745,7 @@ struct cpp_num
 #define CPP_N_DECIMAL	0x0100
 #define CPP_N_HEX	0x0200
 #define CPP_N_OCTAL	0x0400
+#define CPP_N_BINARY	0x0800
 
 #define CPP_N_UNSIGNED	0x1000	/* Properties.  */
 #define CPP_N_IMAGINARY	0x2000



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