* switch question in recog.c
@ 2003-10-07 18:54 Andrew MacLeod
2003-10-07 18:59 ` Daniel Jacobowitz
2003-10-07 19:09 ` Dale Johannesen
0 siblings, 2 replies; 14+ messages in thread
From: Andrew MacLeod @ 2003-10-07 18:54 UTC (permalink / raw)
To: gcc mailing list
Is this really valid? Sure seems screwy to me.
in the function asm_operand_ok(), the code looks like:
<...>
case 'X':
result = 1;
case 'g':
if (general_operand (op, VOIDmode))
result = 1;
break;
default:
/* For all other letters, we first check for a register class,
otherwise it is an EXTRA_CONSTRAINT. */
if (REG_CLASS_FROM_CONSTRAINT (c, constraint) != NO_REGS)
{
case 'r':
if (GET_MODE (op) == BLKmode)
break;
if (register_operand (op, VOIDmode))
result = 1;
}
#ifdef EXTRA_CONSTRAINT_STR
if (EXTRA_CONSTRAINT_STR (op, c, constraint))
result = 1;
if (EXTRA_MEMORY_CONSTRAINT (c, constraint))
<...>
Look at where the case 'r' is.. its inside the 'default:' case. Is that
really kosher?
Andrew
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: switch question in recog.c
2003-10-07 18:54 switch question in recog.c Andrew MacLeod
@ 2003-10-07 18:59 ` Daniel Jacobowitz
2003-10-07 19:16 ` Andrew MacLeod
2003-10-07 19:09 ` Dale Johannesen
1 sibling, 1 reply; 14+ messages in thread
From: Daniel Jacobowitz @ 2003-10-07 18:59 UTC (permalink / raw)
To: gcc mailing list
On Tue, Oct 07, 2003 at 02:54:40PM -0400, Andrew MacLeod wrote:
> Is this really valid? Sure seems screwy to me.
>
>
> in the function asm_operand_ok(), the code looks like:
>
> <...>
> case 'X':
> result = 1;
>
> case 'g':
> if (general_operand (op, VOIDmode))
> result = 1;
> break;
>
> default:
> /* For all other letters, we first check for a register class,
> otherwise it is an EXTRA_CONSTRAINT. */
> if (REG_CLASS_FROM_CONSTRAINT (c, constraint) != NO_REGS)
> {
> case 'r':
> if (GET_MODE (op) == BLKmode)
> break;
> if (register_operand (op, VOIDmode))
> result = 1;
> }
> #ifdef EXTRA_CONSTRAINT_STR
> if (EXTRA_CONSTRAINT_STR (op, c, constraint))
> result = 1;
> if (EXTRA_MEMORY_CONSTRAINT (c, constraint))
> <...>
>
> Look at where the case 'r' is.. its inside the 'default:' case. Is that
> really kosher?
Yep. It acts basically as a label, they're only scoped by additional
switch statements. At least that's my reading of the standard.
--
Daniel Jacobowitz
MontaVista Software Debian GNU/Linux Developer
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: switch question in recog.c
2003-10-07 18:59 ` Daniel Jacobowitz
@ 2003-10-07 19:16 ` Andrew MacLeod
2003-10-07 19:32 ` Joe Buck
2003-10-07 22:27 ` Michael Matz
0 siblings, 2 replies; 14+ messages in thread
From: Andrew MacLeod @ 2003-10-07 19:16 UTC (permalink / raw)
To: Daniel Jacobowitz; +Cc: gcc mailing list
On Tue, 2003-10-07 at 14:59, Daniel Jacobowitz wrote:
> On Tue, Oct 07, 2003 at 02:54:40PM -0400, Andrew MacLeod wrote:
> > default:
> > /* For all other letters, we first check for a register class,
> > otherwise it is an EXTRA_CONSTRAINT. */
> > if (REG_CLASS_FROM_CONSTRAINT (c, constraint) != NO_REGS)
> > {
> > case 'r':
> > if (GET_MODE (op) == BLKmode)
> > break;
> > if (register_operand (op, VOIDmode))
> > result = 1;
> > }
> > #ifdef EXTRA_CONSTRAINT_STR
> > if (EXTRA_CONSTRAINT_STR (op, c, constraint))
> > result = 1;
> > if (EXTRA_MEMORY_CONSTRAINT (c, constraint))
> > <...>
> >
> > Look at where the case 'r' is.. its inside the 'default:' case. Is that
> > really kosher?
>
> Yep. It acts basically as a label, they're only scoped by additional
> switch statements. At least that's my reading of the standard.
>
Huh. I would have failed that question miserably after using the
language for 20 years. It would never occur to me to put a case after
the default label, let alone inside a control structure of some sort.
How miserable :-) But you are right, the standard doesnt appear to
disallow it that I can see.
Thanks
Andrew
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: switch question in recog.c
2003-10-07 19:16 ` Andrew MacLeod
@ 2003-10-07 19:32 ` Joe Buck
2003-10-07 22:27 ` Michael Matz
1 sibling, 0 replies; 14+ messages in thread
From: Joe Buck @ 2003-10-07 19:32 UTC (permalink / raw)
To: Andrew MacLeod; +Cc: Daniel Jacobowitz, gcc mailing list
On Tue, Oct 07, 2003 at 03:15:49PM -0400, Andrew MacLeod wrote:
> On Tue, 2003-10-07 at 14:59, Daniel Jacobowitz wrote:
> > > Look at where the case 'r' is.. its inside the 'default:' case. Is that
> > > really kosher?
> >
> > Yep. It acts basically as a label, they're only scoped by additional
> > switch statements. At least that's my reading of the standard.
> >
> Huh. I would have failed that question miserably after using the
> language for 20 years.
Unfortunately, C doesn't have a high-level switch statement, just a
prettified computed goto. There's an argument for warning about
code like this.
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: switch question in recog.c
2003-10-07 19:16 ` Andrew MacLeod
2003-10-07 19:32 ` Joe Buck
@ 2003-10-07 22:27 ` Michael Matz
2003-10-07 22:33 ` DJ Delorie
2003-10-07 22:34 ` Zack Weinberg
1 sibling, 2 replies; 14+ messages in thread
From: Michael Matz @ 2003-10-07 22:27 UTC (permalink / raw)
To: Andrew MacLeod; +Cc: Daniel Jacobowitz, gcc mailing list
Hi,
On 7 Oct 2003, Andrew MacLeod wrote:
> Huh. I would have failed that question miserably after using the
> language for 20 years.
Then you never used a variant of the holy, mighty device from Tom Duff ;-)
Constructed useless example (i.e. not the usual memcpy() unrolling):
------------------
extern void abort ();
int f(int i)
{
switch (i & 1) {
while (1) {
if (i > 32) {
abort ();
case 0: return 1;
} else {
abort ();
case 1: return 2;
}
default: break;
}
}
}
int main()
{
if (f (42) != 1)
abort ();
return 0;
}
------------------
"case x" is a normal label (with the exception that it's scoped to the
enclosing case statement) introducing a labeled statement, hence it can be
placed everywhere as long as it's inside a switch. Sometimes I love C ;-)
Ciao,
Michael.
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: switch question in recog.c
2003-10-07 22:27 ` Michael Matz
@ 2003-10-07 22:33 ` DJ Delorie
2003-10-07 22:38 ` Michael Matz
2003-10-07 22:34 ` Zack Weinberg
1 sibling, 1 reply; 14+ messages in thread
From: DJ Delorie @ 2003-10-07 22:33 UTC (permalink / raw)
To: matz; +Cc: gcc
> Constructed useless example (i.e. not the usual memcpy() unrolling):
Duff's device wasn't a memcpy() unrolling.
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: switch question in recog.c
2003-10-07 22:33 ` DJ Delorie
@ 2003-10-07 22:38 ` Michael Matz
2003-10-07 22:46 ` Erik Trulsson
0 siblings, 1 reply; 14+ messages in thread
From: Michael Matz @ 2003-10-07 22:38 UTC (permalink / raw)
To: DJ Delorie; +Cc: gcc
Hi,
On Tue, 7 Oct 2003, DJ Delorie wrote:
> > Constructed useless example (i.e. not the usual memcpy() unrolling):
>
> Duff's device wasn't a memcpy() unrolling.
See again http://www.lysator.liu.se/c/duffs-device.html commenting from
Tom himself. His initial posting was about the loop
send(short *to, short *from, int count)
{ do *to = *from++; while(--count>0); }
That's basically a memcpy(). I'm not old enough to know if Tom really is
the inventor of this "use" of C features, but not even Tom remembers ;-)
Ciao,
Michael.
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: switch question in recog.c
2003-10-07 22:38 ` Michael Matz
@ 2003-10-07 22:46 ` Erik Trulsson
2003-10-07 23:03 ` Michael Matz
0 siblings, 1 reply; 14+ messages in thread
From: Erik Trulsson @ 2003-10-07 22:46 UTC (permalink / raw)
To: Michael Matz; +Cc: DJ Delorie, gcc
On Wed, Oct 08, 2003 at 12:38:54AM +0200, Michael Matz wrote:
> Hi,
>
> On Tue, 7 Oct 2003, DJ Delorie wrote:
>
> > > Constructed useless example (i.e. not the usual memcpy() unrolling):
> >
> > Duff's device wasn't a memcpy() unrolling.
>
> See again http://www.lysator.liu.se/c/duffs-device.html commenting from
> Tom himself. His initial posting was about the loop
> send(short *to, short *from, int count)
> { do *to = *from++; while(--count>0); }
>
> That's basically a memcpy(). I'm not old enough to know if Tom really is
> the inventor of this "use" of C features, but not even Tom remembers ;-)
It is not a memcpy(), but similar in structure. If it had been memcpy()
it would have been '*to++ = from++' instead of '*to = *from++'. Note
that the address written to never changes.
What the code does is write a buffer to some memory-mapped
I/O-register (pointed to by 'to').
--
<Insert your favourite quote here.>
Erik Trulsson
ertr1013@student.uu.se
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: switch question in recog.c
2003-10-07 22:27 ` Michael Matz
2003-10-07 22:33 ` DJ Delorie
@ 2003-10-07 22:34 ` Zack Weinberg
2003-10-13 2:15 ` Nix
1 sibling, 1 reply; 14+ messages in thread
From: Zack Weinberg @ 2003-10-07 22:34 UTC (permalink / raw)
To: Michael Matz; +Cc: Andrew MacLeod, Daniel Jacobowitz, gcc mailing list
Michael Matz <matz@suse.de> writes:
> Hi,
>
> On 7 Oct 2003, Andrew MacLeod wrote:
>
>> Huh. I would have failed that question miserably after using the
>> language for 20 years.
>
> Then you never used a variant of the holy, mighty device from Tom Duff ;-)
>
> Constructed useless example (i.e. not the usual memcpy() unrolling):
"For maximum obfuscation, the outer braces can be removed":
extern void abort ();
int f(int i)
{
switch (i & 1)
while (1)
if (i > 32) {
abort ();
case 0: return 1;
} else {
abort ();
case 1: return 2;
}
}
> "case x" is a normal label (with the exception that it's scoped to
> the enclosing case statement) introducing a labeled statement, hence
> it can be placed everywhere as long as it's inside a switch.
Except you can't goto a case label. Occasionally I want to be able to
write "goto default;".
zw
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: switch question in recog.c
2003-10-07 22:34 ` Zack Weinberg
@ 2003-10-13 2:15 ` Nix
0 siblings, 0 replies; 14+ messages in thread
From: Nix @ 2003-10-13 2:15 UTC (permalink / raw)
To: Zack Weinberg; +Cc: gcc mailing list
On Tue, 7 Oct 2003, Zack Weinberg moaned:
> "For maximum obfuscation, the outer braces can be removed":
The most extreme example of this I've ever seen came from the
UNIX-HATERS archives, attributed to Harbison and Steele's "C: A
Reference Manual".. I'm sure that everyone looking at this will
agree that it is a nice clear and sensible micro-optimization:
switch (x)
default:
if (prime(x))
case 2: case 3: case 5: case 7:
process_prime(x);
else
case 4: case 6: case 8: case 9: case 10:
process_composite(x);
--
`If you want a vision of the future, it is a wireless broadband network
feeding requests for foreign money-laundering assistance into a human
temporal lobe, forever. With banner ads.' --- John M. Ford
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: switch question in recog.c
2003-10-07 18:54 switch question in recog.c Andrew MacLeod
2003-10-07 18:59 ` Daniel Jacobowitz
@ 2003-10-07 19:09 ` Dale Johannesen
2003-10-07 21:08 ` Richard Henderson
1 sibling, 1 reply; 14+ messages in thread
From: Dale Johannesen @ 2003-10-07 19:09 UTC (permalink / raw)
To: Andrew MacLeod; +Cc: Dale Johannesen, gcc mailing list
> in the function asm_operand_ok(), the code looks like:
>
> <...>
> case 'X':
> result = 1;
>
> case 'g':
> if (general_operand (op, VOIDmode))
> result = 1;
> break;
>
> default:
> /* For all other letters, we first check for a register
> class,
> otherwise it is an EXTRA_CONSTRAINT. */
> if (REG_CLASS_FROM_CONSTRAINT (c, constraint) != NO_REGS)
> {
> case 'r':
> if (GET_MODE (op) == BLKmode)
> break;
> if (register_operand (op, VOIDmode))
> result = 1;
> }
> #ifdef EXTRA_CONSTRAINT_STR
> if (EXTRA_CONSTRAINT_STR (op, c, constraint))
> result = 1;
> if (EXTRA_MEMORY_CONSTRAINT (c, constraint))
That is valid, but it looks like this code got munged since 3.3. All
those
"result=1"s used to be "return 1", so the control flow is now weird, for
example after 'X", I expect most of them should be "result=1; break" .
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: switch question in recog.c
2003-10-07 19:09 ` Dale Johannesen
@ 2003-10-07 21:08 ` Richard Henderson
0 siblings, 0 replies; 14+ messages in thread
From: Richard Henderson @ 2003-10-07 21:08 UTC (permalink / raw)
To: Dale Johannesen; +Cc: Andrew MacLeod, gcc mailing list
On Tue, Oct 07, 2003 at 12:08:07PM -0700, Dale Johannesen wrote:
> That is valid, but it looks like this code got munged since 3.3. All
> those
> "result=1"s used to be "return 1", so the control flow is now weird, for
> example after 'X", I expect most of them should be "result=1; break" .
Indeed. Patches solicited... ;-)
r~
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: switch question in recog.c
@ 2003-10-07 19:31 Chris Lattner
0 siblings, 0 replies; 14+ messages in thread
From: Chris Lattner @ 2003-10-07 19:31 UTC (permalink / raw)
To: gcc
> Huh. I would have failed that question miserably after using the
> language for 20 years. It would never occur to me to put a case after
> the default label, let alone inside a control structure of some sort.
> How miserable :-) But you are right, the standard doesnt appear to
> disallow it that I can see.
If you like this, you might like "Duff's Device", which abuses switch
statements even worse:
http://www.lysator.liu.se/c/duffs-device.html
I'm happy LLVM doesn't have to worry about this stuff. :)
-Chris
--
http://llvm.cs.uiuc.edu/
http://www.nondot.org/~sabre/Projects/
^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2003-10-12 23:58 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-10-07 18:54 switch question in recog.c Andrew MacLeod
2003-10-07 18:59 ` Daniel Jacobowitz
2003-10-07 19:16 ` Andrew MacLeod
2003-10-07 19:32 ` Joe Buck
2003-10-07 22:27 ` Michael Matz
2003-10-07 22:33 ` DJ Delorie
2003-10-07 22:38 ` Michael Matz
2003-10-07 22:46 ` Erik Trulsson
2003-10-07 23:03 ` Michael Matz
2003-10-07 22:34 ` Zack Weinberg
2003-10-13 2:15 ` Nix
2003-10-07 19:09 ` Dale Johannesen
2003-10-07 21:08 ` Richard Henderson
2003-10-07 19:31 Chris Lattner
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).