From: Samuel Thibault Subject: [PATCH] [Mini-OS] Optimize get_current() Date: Fri, 23 Nov 2007 15:58:00 +0000 Message-ID: <20071123155800.GA11663@implementation.uk.xensource.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Content-Disposition: inline List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org Let gcc perform the computation with SP itself, leading to yet better code. diff -r 2e05a6173be0 extras/mini-os/include/x86/arch_sched.h --- a/extras/mini-os/include/x86/arch_sched.h Fri Nov 23 11:58:11 2007 +0000 +++ b/extras/mini-os/include/x86/arch_sched.h Fri Nov 23 15:53:18 2007 +0000 @@ -7,10 +7,11 @@ { struct thread **current; #ifdef __i386__ - __asm__("andl %%esp,%0; ":"=r" (current) : "0" (~8191UL)); + register unsigned long sp asm("esp"); #else - __asm__("andq %%rsp,%0; ":"=r" (current) : "0" (~8191UL)); + register unsigned long sp asm("rsp"); #endif + current = (void *)(sp & ~8191UL); return *current; }