public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Daniel Santos <daniel.santos@pobox.com>
To: Joseph Myers <joseph@codesourcery.com>,
	Jonathan Wakely <jwakely.gcc@gmail.com>
Cc: Allan Sandfeld Jensen <linux@carewolf.com>,
	"gcc@gcc.gnu.org" <gcc@gcc.gnu.org>,
	Richard Henderson <rth@redhat.com>,
	Florian Weimer <fweimer@redhat.com>
Subject: Re: [RFC] GCC 8 Project proposal: Extensions supporting C Metaprogramming, pseudo-templates
Date: Fri, 12 May 2017 20:54:00 -0000	[thread overview]
Message-ID: <57c2e272-dc55-62a5-5984-382867468723@pobox.com> (raw)
In-Reply-To: <alpine.DEB.2.20.1705111434410.4743@digraph.polyomino.org.uk>

Sorry for my delayed response.

On 05/11/2017 09:35 AM, Joseph Myers wrote:
> On Thu, 11 May 2017, Jonathan Wakely wrote:
>
>> On 10 May 2017 at 23:14, Daniel Santos wrote:
>>> Well my primary goal is programming with values that are constant in the
>>> compiler.  There is no language in any C specification (that I'm aware of)
>>> for a "compile-time constant", but the concept is very important.  So just
>>> because some expression is a compile-time constant doesn't mean we morph
>>> into a "constant expression" (as per the spec), even with
>>> __attribute__((const)).
>> The C standard says "An implementation may accept other forms of
>> constant expressions." That means rather than inventing some
>> "constprop" you could just extend GCC to treat more expressions
>> involving constants as constant-expressions.

I would rather not invent terms either.  In regards to the proposed attribute name, I'm leaning towards re-using "const" instead of adding "constprop" because it seems to fall in line with the original purpose of the attribute while  and there doesn't appear to be any overlap between what it currently applies to and what I would like to add the attribute to.  But from a conceptual standpoint, I believe the term "constant-expression" would be incorrect because the C standard defines this constraint: (6.6.3 of C11) "Constant expressions shall not contain assignment, increment, decrement, function-call, or comma operators, except when they are contained within a subexpression that is not evaluated."  I definitely do need to study the C specs more carefully to make sure I fully understand how this is used and how it's changed over different revisions of the spec.

But from what I've done so far, I can tell that around 80-90% of what I hope to achieve will be through simply improving GCC's ability to to constant propagate (I'm focusing on one issue right now where it appears that early SRA might be throwing off later constant propagation).

> Note that while "other forms" might be accepted in initializers, they
> would still not be integer constant expressions (see DR#312).

What is DR#312?

I should probably be more careful and explicit in my language.  I was 
thinking particularly of integer constant expressions that are required 
for the size of non-variable length arrays, bitfields, and such.

If only for the sake of entertainment, there *is* actually a legitimate 
way to transform an expression into an integer constant expression and 
even an integer constant, but is only practical when the range of 
possible values is limited.

#define foo (i) /* Do something here. */
#define bar (expr)		 \
   do {				 \
       ASSERT_CONST (expr);	 \
       switch (expr) {		 \
       case 1:	foo(1); break;	 \
       case 2:	foo(2); break;	 \
       case 4:	foo(4); break;	 \
       case 8:	foo(8); break;	 \
       case 16:	foo(16); break;	 \
       case 32:	foo(32); break;	 \
       case 64:	foo(64); break;	 \
       case 128:	foo(128); break; \
       case 256:	foo(256); break; \
       default:			 \
	ASSERT (0);		 \
     }				 \
   } while (0)


Daniel

  reply	other threads:[~2017-05-12 20:54 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-08 23:32 Daniel Santos
2017-05-09  9:36 ` Florian Weimer
2017-05-10  8:46   ` Daniel Santos
2017-05-09 13:29 ` Allan Sandfeld Jensen
2017-05-10  9:13   ` Daniel Santos
2017-05-10  9:24     ` Jonathan Wakely
2017-05-10 22:09       ` Daniel Santos
2017-05-11 10:12         ` Jonathan Wakely
2017-05-11 10:44           ` Marek Polacek
2017-05-11 14:35           ` Joseph Myers
2017-05-12 20:54             ` Daniel Santos [this message]
2017-05-12 21:03               ` Joseph Myers
2017-05-15 11:31               ` Vincent Lefevre
2017-05-12 15:49         ` Martin Sebor
2017-05-12 21:11           ` Daniel Santos

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=57c2e272-dc55-62a5-5984-382867468723@pobox.com \
    --to=daniel.santos@pobox.com \
    --cc=fweimer@redhat.com \
    --cc=gcc@gcc.gnu.org \
    --cc=joseph@codesourcery.com \
    --cc=jwakely.gcc@gmail.com \
    --cc=linux@carewolf.com \
    --cc=rth@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).