From: Momchil Velikov <velco@fadata.bg>
To: Linus Torvalds <torvalds@transmeta.com>
Cc: jh@suse.cz, linux-kernel@vger.kernel.org
Subject: Re: i386 flags register clober in inline assembly
Date: 17 Nov 2001 22:24:28 +0200 [thread overview]
Message-ID: <87r8qx6t8j.fsf@fadata.bg> (raw)
In-Reply-To: <87y9l58pb5.fsf@fadata.bg> <200111171920.fAHJKjJ01550@penguin.transmeta.com>
In-Reply-To: <200111171920.fAHJKjJ01550@penguin.transmeta.com>
>>>>> "Linus" == Linus Torvalds <torvalds@transmeta.com> writes:
Linus> (Example code:
Linus> atomic_sub_and_test:
Linus> __asm__ __volatile__(
Linus> LOCK "subl %2,%0; sete %1"
Linus> :"=m" (v->counter), "=qm" (c)
Linus> :"ir" (i), "m" (v->counter) : "memory");
Linus> Where we first get the value we _really_ want in ZF in eflags, then we
Linus> use "sete" to move it to a register, and then gcc will end up generating
Linus> code to test that register by hand, so the end result is usually
Linus> something like:
Linus> #APP
Linus> lock ; decl 20(%edi); sete %al
Linus> #NO_APP
Linus> testb %al, %al
Linus> je .L1570
Linus> even though what we'd _want_ is really
Linus> lock ; decl 20(%edi)
Linus> jne .L1570
Linus> which is not only smaller and faster, but is often _really_ faster
Linus> because at least some Intel CPU's will forward the flags values to the
Linus> branch prediction stuff, and going through a register dependency will
Linus> add non-forwarded state and thus extra cycles.
Linus> So I would personally _really_ really like for some way to expose the
Linus> internal gcc
Linus> "(set (cc0) ..asm..)"
Linus> construct, together with some way of setting the cc_status.flags.
Linux> From what I can tell, all the x86 machine description already uses "cc0"
Linus> together with the notion of comparing it to zero (either signed or
Linus> unsigned), so something like this _might_ just work
Linus> unsigned long result;
Linus> asm volatile(
Linus> LOCK "decl %m"
Linus> :"+m" (v->counter),
Linus> "=cc" (result)
Linus> : :"memory");
Linus> if (result > 0) /* "jnb" */
Linus> ...
Linus> which would be wonderful, and would expand to
Linus> (set (cc0) ..asm..)
Linus> (set (pc)
Linus> (if_then_else (gtu (cc0) (const_int 0))
Linus> (label_ref (match_operand ..
Linus> (pc))
Indeed, with pattern like:
(define_insn "*ja"
[(set (pc)
(if_then_else (gtu (match_operand:CC 0 "" "") (const_int 0))
(label_ref (match_operand 1 "" ""))
(pc)))]
""
"ja ..."
...)
Linus> Which _should_ just automatically give us
Linus> lock ; decl ..
Linus> ja ..
Linus> which is exactly what we want.
Regards,
-velco
next prev parent reply other threads:[~2001-11-17 20:27 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-11-17 14:06 i386 flags register clober in inline assembly Momchil Velikov
2001-11-17 15:14 ` Jan Hubicka
2001-11-17 19:20 ` Linus Torvalds
2001-11-17 19:58 ` H. Peter Anvin
2001-11-17 20:24 ` Momchil Velikov [this message]
2001-11-17 20:30 ` Linus Torvalds
2001-11-17 20:40 ` Jan Hubicka
2001-11-17 20:42 ` Linus Torvalds
2001-11-18 1:09 ` Jan Hubicka
2001-11-18 2:48 ` Linus Torvalds
2001-11-20 8:33 ` Richard Henderson
2001-11-20 13:00 ` Jan Hubicka
2001-11-20 23:14 ` Richard Henderson
2001-11-20 17:12 ` Linus Torvalds
2001-11-17 21:00 ` H. Peter Anvin
2001-11-20 14:39 ` PATCH 2.4.15-pre6 idt compilation and proc_misc cleanup Martin Dalecki
2001-11-23 22:24 ` Roman Zippel
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=87r8qx6t8j.fsf@fadata.bg \
--to=velco@fadata.bg \
--cc=jh@suse.cz \
--cc=linux-kernel@vger.kernel.org \
--cc=torvalds@transmeta.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.