* Re: i386 and asm jumping
@ 2002-05-07 16:33 Erik Schnetter
2002-05-08 2:43 ` Andreas Schwab
0 siblings, 1 reply; 13+ messages in thread
From: Erik Schnetter @ 2002-05-07 16:33 UTC (permalink / raw)
To: gcc
Peter Barada wrote:
> Jumps in asm statements will create problems since the optimizers have
> no knowledge that there is a possible change in flow caused by the asm
> statement, and hence will not have an accurate flow diagram of the
> function. From there its all downhill.
That is true. However, the same could be said from asm code changing
registers. The solution is to tell the compiler about all possible branch
destinations of a piece of asm code. Possibly with branch probabilities...
The question remains whether someone will think this is worthwhile
implementing, or whether this someone rather fixes the machine description in
question.
Another approach is to postprocess the generated assembler code, before the
assembler sees it.
-erik
--
Erik Schnetter <schnetter@uni-tuebingen.de>
Web: http://www.tat.physik.uni-tuebingen.de/~schnette/
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: i386 and asm jumping
2002-05-07 16:33 i386 and asm jumping Erik Schnetter
@ 2002-05-08 2:43 ` Andreas Schwab
2002-05-09 9:01 ` Erik Schnetter
0 siblings, 1 reply; 13+ messages in thread
From: Andreas Schwab @ 2002-05-08 2:43 UTC (permalink / raw)
To: Erik Schnetter; +Cc: gcc
Erik Schnetter <schnetter@uni-tuebingen.de> writes:
|> Peter Barada wrote:
|>
|> > Jumps in asm statements will create problems since the optimizers have
|> > no knowledge that there is a possible change in flow caused by the asm
|> > statement, and hence will not have an accurate flow diagram of the
|> > function. From there its all downhill.
|>
|> That is true. However, the same could be said from asm code changing
|> registers.
Why? You can accurately describe this to the compiler.
Andreas.
--
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE GmbH, Deutschherrnstr. 15-19, D-90429 Nürnberg
Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: i386 and asm jumping
2002-05-08 2:43 ` Andreas Schwab
@ 2002-05-09 9:01 ` Erik Schnetter
0 siblings, 0 replies; 13+ messages in thread
From: Erik Schnetter @ 2002-05-09 9:01 UTC (permalink / raw)
To: gcc; +Cc: Andreas Schwab
On Wednesday 08 May 2002 10:57, you wrote:
> Erik Schnetter <schnetter@uni-tuebingen.de> writes:
> |> Peter Barada wrote:
> |> > Jumps in asm statements will create problems since the optimizers have
> |> > no knowledge that there is a possible change in flow caused by the asm
> |> > statement, and hence will not have an accurate flow diagram of the
> |> > function. From there its all downhill.
> |>
> |> That is true. However, the same could be said from asm code changing
> |> registers.
>
> Why? You can accurately describe this to the compiler.
My wording was unfortunate. I wanted to say that you could also describe
jumps to the compiler, in a similar way the register changes are described
now.
-erik
--
Erik Schnetter <schnetter@uni-tuebingen.de>
Web: http://www.tat.physik.uni-tuebingen.de/~schnette/
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: i386 and asm jumping
2002-05-07 10:31 ` Johan Rydberg
2002-05-07 15:23 ` Richard Henderson
@ 2002-05-08 4:15 ` Bernd Jendrissek
1 sibling, 0 replies; 13+ messages in thread
From: Bernd Jendrissek @ 2002-05-08 4:15 UTC (permalink / raw)
To: Johan Rydberg; +Cc: Andreas Schwab, Robert Dewar, jh, gcc
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Tue, May 07, 2002 at 07:32:39PM +0200, Johan Rydberg wrote:
> What I would like to do is to replace the following code
> with inline assembler:
>
> if (--cnt == 0)
> goto HANDLER;
> goto NEXT;
>
> The code above will generate; load cnt into register,
> decrement register, store register and jump to HANDLER
> if zero flag is set. I would like to replace this with
> the following assembler code:
>
> decl cnt
> jz HANDLER
> jmp NEXT
>
> Speed is everything :)
[Note I'm using gcc 2.95.3 here - for all I know later version might
optimize foo() to foo() { return 0; }]
$ cat foo.c
int foo(int cnt)
{
int retval = 0;
NEXT:
if(--cnt == 0)
goto HANDLER;
goto NEXT;
HANDLER:
retval += cnt;
return retval;
}
$ gcc -S -O2 -f-omit-frame-pointer
$ cat foo.s
.file "foo.c"
.version "01.01"
gcc2_compiled.:
.text
.align 4
.globl foo
.type foo,@function
foo:
movl 4(%esp),%eax
.L3:
decl %eax
jnz .L3
xorl %eax,%eax
ret
.Lfe1:
.size foo,.Lfe1-foo
.ident "GCC: (GNU) 2.95.3 20010315 (release)"
Is that efficient enough for you? Note that gcc has done *better* than
naive hand-optimization. Of course, it depends on what the loop does - in
my simple example the loop does pretty much nothing.
Rather just write clear, readable code and let GCC worry about making it
fast. If you try to second-guess GCC, you often just succeed in making
your intent unclear, and the compiler just has to to what you say, step by
step. Tell GCC *what* you want, not *how*.
Bernd Jendrissek
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.4 (GNU/Linux)
Comment: For info see http://www.gnupg.org
iD8DBQE82QLs/FmLrNfLpjMRAr5VAJ9S3Gtkz+gsSO5oPcfkM+hF4TijrACeO3rv
fuaKPoD8a/3VnhGheAgpyx8=
=rkqr
-----END PGP SIGNATURE-----
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: i386 and asm jumping
2002-05-07 10:31 ` Johan Rydberg
@ 2002-05-07 15:23 ` Richard Henderson
2002-05-08 4:15 ` Bernd Jendrissek
1 sibling, 0 replies; 13+ messages in thread
From: Richard Henderson @ 2002-05-07 15:23 UTC (permalink / raw)
To: Johan Rydberg; +Cc: Andreas Schwab, Robert Dewar, jh, gcc
On Tue, May 07, 2002 at 07:32:39PM +0200, Johan Rydberg wrote:
> The code above will generate; load cnt into register,
> decrement register, store register and jump to HANDLER
> if zero flag is set. I would like to replace this with
> the following assembler code:
>
> decl cnt
> jz HANDLER
> jmp NEXT
>
> Speed is everything :)
I think you'd be better off fixing whatever in the compiler that
is preventing this rather than playing with funny asm statements.
r~
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: i386 and asm jumping
2002-05-07 6:48 ` Andreas Schwab
@ 2002-05-07 10:31 ` Johan Rydberg
2002-05-07 15:23 ` Richard Henderson
2002-05-08 4:15 ` Bernd Jendrissek
0 siblings, 2 replies; 13+ messages in thread
From: Johan Rydberg @ 2002-05-07 10:31 UTC (permalink / raw)
To: Andreas Schwab; +Cc: Robert Dewar, jh, gcc
On 2002.05.07 15:40 Andreas Schwab wrote:
: dewar@gnat.com (Robert Dewar) writes:
:
: |> > It is not possible. ASM statements may not jump.
: |> > You may want to use computed goto GCC extension istead.
: |>
: |> Seems a pity, this is quite a serious restriction in capability
: |> compared with Asm inserts in other compilers.
:
: What's wrong with computed goto in this situation?
What I would like to do is to replace the following code
with inline assembler:
if (--cnt == 0)
goto HANDLER;
goto NEXT;
The code above will generate; load cnt into register,
decrement register, store register and jump to HANDLER
if zero flag is set. I would like to replace this with
the following assembler code:
decl cnt
jz HANDLER
jmp NEXT
Speed is everything :)
regards
johan
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: i386 and asm jumping
2002-05-07 7:30 Robert Dewar
@ 2002-05-07 9:03 ` Peter Barada
0 siblings, 0 replies; 13+ messages in thread
From: Peter Barada @ 2002-05-07 9:03 UTC (permalink / raw)
To: dewar; +Cc: dewar, schwab, gcc, jh, jrydberg
>>>What's wrong with computed goto in this situation?
>
>Lots of machines have interesting branch instructions which you may want
>to generate for some particular reason. After all if you take the above
>attitude, *any* inserted asm can always be replaced by C code :-)
Jumps in asm statements will create problems since the optimizers have
no knowledge that there is a possible change in flow caused by the asm
statement, and hence will not have an accurate flow diagram of the
function. From there its all downhill.
--
Peter Barada Peter.Barada@motorola.com
Wizard 781-852-2768 (direct)
WaveMark Solutions(wholly owned by Motorola) 781-270-0193 (fax)
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: i386 and asm jumping
2002-05-07 5:49 Robert Dewar
2002-05-07 6:48 ` Andreas Schwab
@ 2002-05-07 7:45 ` Michael Matz
1 sibling, 0 replies; 13+ messages in thread
From: Michael Matz @ 2002-05-07 7:45 UTC (permalink / raw)
To: Robert Dewar; +Cc: jh, gcc
Hi,
On Tue, 7 May 2002, Robert Dewar wrote:
> > It is not possible. ASM statements may not jump.
> > You may want to use computed goto GCC extension istead.
>
> Seems a pity, this is quite a serious restriction in capability
> compared with Asm inserts in other compilers.
And how do those compare in optimizing functions containing asm's? Sitch
it off completely? If you can jump out of the inside of an asm, you
basically have a trapping insn. It's target may or may not be given as a
parameter, e.g. a label. If not, hmm, possibly it's equivalent to a
computed goto, i.e. reaches possibly all defined labels. But that aside,
internally with non-trapping insns, only jump_insn can jump. I wouldn't
call that a serious restriction. If you want asm, write a .s file.
Ciao,
Michael.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: i386 and asm jumping
@ 2002-05-07 7:30 Robert Dewar
2002-05-07 9:03 ` Peter Barada
0 siblings, 1 reply; 13+ messages in thread
From: Robert Dewar @ 2002-05-07 7:30 UTC (permalink / raw)
To: dewar, schwab; +Cc: gcc, jh, jrydberg
>>What's wrong with computed goto in this situation?
Lots of machines have interesting branch instructions which you may want
to generate for some particular reason. After all if you take the above
attitude, *any* inserted asm can always be replaced by C code :-)
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: i386 and asm jumping
2002-05-07 5:49 Robert Dewar
@ 2002-05-07 6:48 ` Andreas Schwab
2002-05-07 10:31 ` Johan Rydberg
2002-05-07 7:45 ` Michael Matz
1 sibling, 1 reply; 13+ messages in thread
From: Andreas Schwab @ 2002-05-07 6:48 UTC (permalink / raw)
To: Robert Dewar; +Cc: jh, jrydberg, gcc
dewar@gnat.com (Robert Dewar) writes:
|> > It is not possible. ASM statements may not jump.
|> > You may want to use computed goto GCC extension istead.
|>
|> Seems a pity, this is quite a serious restriction in capability
|> compared with Asm inserts in other compilers.
What's wrong with computed goto in this situation?
Andreas.
P.S.: the right contstraint would probably be "m" and %a0 for substituting
it.
--
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE GmbH, Deutschherrnstr. 15-19, D-90429 Nürnberg
Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: i386 and asm jumping
@ 2002-05-07 5:49 Robert Dewar
2002-05-07 6:48 ` Andreas Schwab
2002-05-07 7:45 ` Michael Matz
0 siblings, 2 replies; 13+ messages in thread
From: Robert Dewar @ 2002-05-07 5:49 UTC (permalink / raw)
To: jh, jrydberg; +Cc: gcc
> It is not possible. ASM statements may not jump.
> You may want to use computed goto GCC extension istead.
Seems a pity, this is quite a serious restriction in capability
compared with Asm inserts in other compilers.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: i386 and asm jumping
2002-05-07 5:06 Johan Rydberg
@ 2002-05-07 5:15 ` Jan Hubicka
0 siblings, 0 replies; 13+ messages in thread
From: Jan Hubicka @ 2002-05-07 5:15 UTC (permalink / raw)
To: Johan Rydberg; +Cc: gcc
>
> Hi!
>
> I would like to hard optimize a special case in my
> code. And what I would like to do is really just
> the following:
>
> the_label:
> ...
> __asm___ ("jmp %0" :: "?" (&& the_label));
>
> What I wanna know is if this is possible? What
> constrain should I use? `m' doesn't work, neither
> do `p'. Any ideas?
It is not possible. ASM statements may not jump.
You may want to use computed goto GCC extension istead.
Honza
>
> regards
> johan
^ permalink raw reply [flat|nested] 13+ messages in thread
* i386 and asm jumping
@ 2002-05-07 5:06 Johan Rydberg
2002-05-07 5:15 ` Jan Hubicka
0 siblings, 1 reply; 13+ messages in thread
From: Johan Rydberg @ 2002-05-07 5:06 UTC (permalink / raw)
To: gcc
Hi!
I would like to hard optimize a special case in my
code. And what I would like to do is really just
the following:
the_label:
...
__asm___ ("jmp %0" :: "?" (&& the_label));
What I wanna know is if this is possible? What
constrain should I use? `m' doesn't work, neither
do `p'. Any ideas?
regards
johan
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2002-05-09 15:50 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-05-07 16:33 i386 and asm jumping Erik Schnetter
2002-05-08 2:43 ` Andreas Schwab
2002-05-09 9:01 ` Erik Schnetter
-- strict thread matches above, loose matches on Subject: below --
2002-05-07 7:30 Robert Dewar
2002-05-07 9:03 ` Peter Barada
2002-05-07 5:49 Robert Dewar
2002-05-07 6:48 ` Andreas Schwab
2002-05-07 10:31 ` Johan Rydberg
2002-05-07 15:23 ` Richard Henderson
2002-05-08 4:15 ` Bernd Jendrissek
2002-05-07 7:45 ` Michael Matz
2002-05-07 5:06 Johan Rydberg
2002-05-07 5:15 ` Jan Hubicka
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).