2.1.91 Small patch to asm-i386/current.h

Jean Wolter (jw5@os.inf.tu-dresden.de)
29 Mar 1998 14:39:32 +0200


While reading through the Linux sources and especially through the gcc
generated code I found, that gcc doesn't generate the best code for
the definition of current. It keeps the result of get_esp() in a
separate register despite it doesn't need it anymore. The instructions
depend on each other preventing the cpu to make use of its pipelines.

linux/include/asm/current.h:7
cd7: 89 e1 movl %esp,%ecx
linux/fs/binfmt_elf.c:584
cd9: 89 ca movl %ecx,%edx
cdb: 81 e2 00 e0 ff andl $0xffffe000,%edx
ce0: ff
ce1: 8b b2 84 03 00 movl 0x384(%edx),%esi
ce6: 00
ce7: c7 46 30 00 00 movl $0x0,0x30(%esi)
cec: 00 00

Since the definition of current is widely used throughout the kernel I
think it may be worth to optimize it a little bit. I would propose the
following changes to asm-i386/current.h:

diff -u current.h.orig current.h
--- current.h.orig Sun Mar 29 13:00:11 1998
+++ current.h Sun Mar 29 13:28:23 1998
@@ -1,14 +1,13 @@
#ifndef _I386_CURRENT_H
#define _I386_CURRENT_H

-static inline unsigned long get_esp(void)
+static inline struct task_struct * get_current(void)
{
- unsigned long esp;
- __asm__("movl %%esp,%0":"=r" (esp));
- return esp;
+ struct task_struct *current;
+ __asm__("andl %%esp,%0; ":"=r" (current) : "0" (~8191UL));
+ return current;
}

-#define current ((struct task_struct *)(get_esp() & ~8191UL))
-
+#define current get_current()

#endif /* !(_I386_CURRENT_H) */

This small change
- removes the unnecessary register loading
- reduces the dependencies between the instructions (if we are
lucky, the first instruction can be paired with a previous one)
- (results in about 2 KByte smaller text size)

linux/include/asm/current.h:15
cc7: ba 00 e0 ff ff movl $0xffffe000,%edx
ccc: 21 e2 andl %esp,%edx
linux/fs/binfmt_elf.c:584
cce: 8b 8a 84 03 00 movl 0x384(%edx),%ecx
cd3: 00
cd4: c7 41 30 00 00 movl $0x0,0x30(%ecx)
cd9: 00 00

Jean

-- 
I get up each morning, gather my wits.
Pick up the paper, read the obits.
if I'm not there I know I'm not dead.
So I eat a good breakfast and go back to bed. Peete Seeger

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu