* [PATCH 5/14] i386 / Use early clobber to eliminate rotate in desc
@ 2005-08-11 4:54 zach
2005-08-16 23:45 ` Andi Kleen
0 siblings, 1 reply; 6+ messages in thread
From: zach @ 2005-08-11 4:54 UTC (permalink / raw)
To: akpm, chrisl, chrisw, hpa, Keir.Fraser, linux-kernel, m+Ian.Pratt,
mbligh, pratap, virtualization, zach, zwame
Use an early clobber on addr to avoid the extra rorl instruction at the
end of _set_tssldt_desc.
Also, get some C type checking on the descriptor struct here.
Patch-base: 2.6.13-rc5-mm1
Patch-keys: i386 desc cleanup optimize
Signed-off-by: Zachary Amsden <zach@vmware.com>
Index: linux-2.6.13/include/asm-i386/desc.h
===================================================================
--- linux-2.6.13.orig/include/asm-i386/desc.h 2005-08-09 18:59:10.000000000 -0700
+++ linux-2.6.13/include/asm-i386/desc.h 2005-08-10 20:42:20.000000000 -0700
@@ -34,17 +34,21 @@
extern struct desc_struct default_ldt[];
extern void set_intr_gate(unsigned int irq, void * addr);
-#define _set_tssldt_desc(n,addr,limit,type) \
-__asm__ __volatile__ ("movw %w3,0(%2)\n\t" \
- "movw %w1,2(%2)\n\t" \
- "rorl $16,%1\n\t" \
- "movb %b1,4(%2)\n\t" \
- "movb %4,5(%2)\n\t" \
- "movb $0,6(%2)\n\t" \
- "movb %h1,7(%2)\n\t" \
- "rorl $16,%1" \
- : "=m"(*(n)) : "q" (addr), "r"(n), "ir"(limit), "i"(type))
-
+#define _set_tssldt_desc(desc,addr,limit,type) \
+do { \
+ unsigned long __tmp; \
+ typecheck(struct desc_struct *, desc); \
+ asm volatile ("movw %w4,0(%3)\n\t" \
+ "movw %w2,2(%3)\n\t" \
+ "rorl $16,%2\n\t" \
+ "movb %b2,4(%3)\n\t" \
+ "movb %5,5(%3)\n\t" \
+ "movb $0,6(%3)\n\t" \
+ "movb %h2,7(%3)\n\t" \
+ : "=m"(*(desc)), "=&q" (__tmp) \
+ : "1" (addr), "r"(desc), "ir"(limit), "i"(type)); \
+} while (0)
+
#include <mach_desc.h>
#define set_tss_desc(cpu,addr) __set_tss_desc(cpu, GDT_ENTRY_TSS, addr)
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH 5/14] i386 / Use early clobber to eliminate rotate in desc
2005-08-11 4:54 [PATCH 5/14] i386 / Use early clobber to eliminate rotate in desc zach
@ 2005-08-16 23:45 ` Andi Kleen
2005-08-16 23:56 ` Zachary Amsden
0 siblings, 1 reply; 6+ messages in thread
From: Andi Kleen @ 2005-08-16 23:45 UTC (permalink / raw)
To: zach
Cc: akpm, chrisl, chrisw, hpa, Keir.Fraser, linux-kernel, m+Ian.Pratt,
mbligh, pratap, virtualization, zwame
On Wed, Aug 10, 2005 at 09:54:11PM -0700, zach@vmware.com wrote:
> Use an early clobber on addr to avoid the extra rorl instruction at the
> end of _set_tssldt_desc.
I would suggest to just use C for this. I do this on x86-64 and
I don't think there is any reason to use this hard to maintain
code for it.
It's probably a left over from Linus first experiments with inline
assembly, similar to the old string.h and by now so obsolete
it doesn't even stink anymore.
-Andi
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 5/14] i386 / Use early clobber to eliminate rotate in desc
2005-08-16 23:45 ` Andi Kleen
@ 2005-08-16 23:56 ` Zachary Amsden
2005-08-17 0:06 ` H. Peter Anvin
0 siblings, 1 reply; 6+ messages in thread
From: Zachary Amsden @ 2005-08-16 23:56 UTC (permalink / raw)
To: Andi Kleen
Cc: akpm, chrisl, chrisw, hpa, Keir.Fraser, linux-kernel, m+Ian.Pratt,
mbligh, pratap, virtualization, zwame
Andi Kleen wrote:
>On Wed, Aug 10, 2005 at 09:54:11PM -0700, zach@vmware.com wrote:
>
>
>>Use an early clobber on addr to avoid the extra rorl instruction at the
>>end of _set_tssldt_desc.
>>
>>
>
>I would suggest to just use C for this. I do this on x86-64 and
>I don't think there is any reason to use this hard to maintain
>code for it.
>
This one in particular is non-optimal looking from C because the
compiler misses the potential for rotation. But, composing into
temporaries and then issuing two writes to memory instead of multiple
writes within the same word could actually get you a better cycle count,
and that is something GCC just might be able to do :)
Zach
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 5/14] i386 / Use early clobber to eliminate rotate in desc
2005-08-16 23:56 ` Zachary Amsden
@ 2005-08-17 0:06 ` H. Peter Anvin
2005-08-17 14:22 ` Alan Cox
0 siblings, 1 reply; 6+ messages in thread
From: H. Peter Anvin @ 2005-08-17 0:06 UTC (permalink / raw)
To: Zachary Amsden
Cc: Andi Kleen, akpm, chrisl, chrisw, Keir.Fraser, linux-kernel,
m+Ian.Pratt, mbligh, pratap, virtualization, zwame
Zachary Amsden wrote:
>
> This one in particular is non-optimal looking from C because the
> compiler misses the potential for rotation. But, composing into
> temporaries and then issuing two writes to memory instead of multiple
> writes within the same word could actually get you a better cycle count,
> and that is something GCC just might be able to do :)
>
At least i386 and x86-64 gcc should recognize
((foo << x) + (foo >> (32-x)))
... as a 32-bit rotate; similar for 8-, 16- and 64-bit rotates of
appropriate sized items. Also, it seems it could just be an inline
function instead of a macro.
-hpa
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 5/14] i386 / Use early clobber to eliminate rotate in desc
2005-08-17 0:06 ` H. Peter Anvin
@ 2005-08-17 14:22 ` Alan Cox
2005-08-17 15:54 ` H. Peter Anvin
0 siblings, 1 reply; 6+ messages in thread
From: Alan Cox @ 2005-08-17 14:22 UTC (permalink / raw)
To: H. Peter Anvin
Cc: Zachary Amsden, Andi Kleen, akpm, chrisl, chrisw, Keir.Fraser,
linux-kernel, m+Ian.Pratt, mbligh, pratap, virtualization, zwame
On Maw, 2005-08-16 at 17:06 -0700, H. Peter Anvin wrote:
> At least i386 and x86-64 gcc should recognize
>
> ((foo << x) + (foo >> (32-x)))
>
> ... as a 32-bit rotate
Only for 1 <= x <= 31. For the x = 0 case the code posted is undefined
and at least in some cases gcc will do "interesting" things as a result
such as treating >> 32 as >> 0.
Alan
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 5/14] i386 / Use early clobber to eliminate rotate in desc
2005-08-17 14:22 ` Alan Cox
@ 2005-08-17 15:54 ` H. Peter Anvin
0 siblings, 0 replies; 6+ messages in thread
From: H. Peter Anvin @ 2005-08-17 15:54 UTC (permalink / raw)
To: Alan Cox
Cc: Zachary Amsden, Andi Kleen, akpm, chrisl, chrisw, Keir.Fraser,
linux-kernel, m+Ian.Pratt, mbligh, pratap, virtualization, zwame
Alan Cox wrote:
> On Maw, 2005-08-16 at 17:06 -0700, H. Peter Anvin wrote:
>
>>At least i386 and x86-64 gcc should recognize
>>
>> ((foo << x) + (foo >> (32-x)))
>>
>>... as a 32-bit rotate
>
>
> Only for 1 <= x <= 31. For the x = 0 case the code posted is undefined
> and at least in some cases gcc will do "interesting" things as a result
> such as treating >> 32 as >> 0.
>
True, although I thought gcc considered the above an idiom and would
generate a rotate instruction. Perhaps it should be | rather than +.
-hpa
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2005-08-17 15:55 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-08-11 4:54 [PATCH 5/14] i386 / Use early clobber to eliminate rotate in desc zach
2005-08-16 23:45 ` Andi Kleen
2005-08-16 23:56 ` Zachary Amsden
2005-08-17 0:06 ` H. Peter Anvin
2005-08-17 14:22 ` Alan Cox
2005-08-17 15:54 ` H. Peter Anvin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox