[PATCH] AT_FPUCW - a way how to avoid initializing FPU for non-FPU programs

Jakub Jelinek (jj@sunsite.ms.mff.cuni.cz)
Wed, 16 Sep 1998 10:00:04 +0200 (MET DST)


Hi!

This simple patch exports the default value of FPU control word in the ELF
auxiliary vector, so that libc can look at it and avoid touching FPU just to
initialize it to the default value.
At the moment, even if a program does not use FPU at all, libc during
initialization sets the FPU control word to the value it wants to use, so
for every program, a fpdis exception happens at least once, even though it
is not needed.
By using the ELF_FPUCW value found at AT_FPUCW in the auxiliary vector, libc
can avoid setting it, if the value is the same as the default.
I think this change does not hurt anything, as unknown members of the
auxiliary vector are silently ignored, so even if we are in feature freeze,
I think it would be great if this was applied before 2.2 and next versions
of libc could make use of it.
This topic has been discussed on l-k a couple of months ago, but nobody came
with an implementation at that time, although it is really simple.

--- linux/fs/binfmt_elf.c.jj Fri Sep 4 11:28:43 1998
+++ linux/fs/binfmt_elf.c Fri Sep 11 10:58:40 1998
@@ -160,6 +160,12 @@ create_elf_tables(char *p, int argc, int
}
sp -= 2;
NEW_AUX_ENT(0, AT_HWCAP, hwcap);
+
+#ifdef ELF_FPUCW
+ /* Once all archs provide this value, we can remove the #ifdef */
+ sp -= 2;
+ NEW_AUX_ENT(0, AT_FPUCW, ELF_FPUCW);
+#endif

if (exec) {
sp -= 11*2;
--- linux/include/asm-i386/elf.h.jj Fri Sep 4 11:46:50 1998
+++ linux/include/asm-i386/elf.h Fri Sep 11 10:53:39 1998
@@ -76,6 +76,9 @@ typedef struct user_i387_struct elf_fpre

#define ELF_HWCAP (boot_cpu_data.x86_capability)

+/* Default FPU control word is 0x37F (as initialized by fninit). */
+#define ELF_FPUCW 0x37F
+
/* This yields a string that ld.so will use to load implementation
specific libraries for optimization. This is more specific in
intent than poking at uname or /proc/cpuinfo.
--- linux/include/asm-m68k/elf.h.jj Fri Sep 4 11:46:53 1998
+++ linux/include/asm-m68k/elf.h Wed Sep 16 10:12:00 1998
@@ -73,6 +73,9 @@

#define ELF_HWCAP (0)

+/* Default FPU control word is 0. */
+#define ELF_FPUCW 0
+
/* This yields a string that ld.so will use to load implementation
specific libraries for optimization. This is more specific in
intent than poking at uname or /proc/cpuinfo. */
--- linux/include/asm-mips/elf.h.jj Fri Sep 4 11:47:54 1998
+++ linux/include/asm-mips/elf.h Wed Sep 16 10:11:09 1998
@@ -44,6 +44,9 @@

#define ELF_HWCAP (0)

+/* Default FPU control word is 0. */
+#define ELF_FPUCW 0
+
/* This yields a string that ld.so will use to load implementation
specific libraries for optimization. This is more specific in
intent than poking at uname or /proc/cpuinfo.
--- linux/include/asm-sparc/elf.h.jj Wed Sep 9 15:43:00 1998
+++ linux/include/asm-sparc/elf.h Fri Sep 11 10:52:55 1998
@@ -97,6 +97,9 @@ typedef struct {
srmmu_modtype != Cypress_vE && \
srmmu_modtype != Cypress_vD) ? \
HWCAP_SPARC_MULDIV : 0)))
+
+/* Default FPU control word is 0. */
+#define ELF_FPUCW 0

/* This yields a string that ld.so will use to load implementation
specific libraries for optimization. This is more specific in
--- linux/include/asm-sparc64/elf.h.jj Wed Sep 9 15:43:03 1998
+++ linux/include/asm-sparc64/elf.h Fri Sep 11 10:52:11 1998
@@ -57,6 +57,9 @@ typedef struct {
#define ELF_HWCAP (HWCAP_SPARC_FLUSH | HWCAP_SPARC_STBAR | \
HWCAP_SPARC_SWAP | HWCAP_SPARC_MULDIV | \
HWCAP_SPARC_V9)
+
+/* Default FPU control word is 0. */
+#define ELF_FPUCW 0

/* This yields a string that ld.so will use to load implementation
specific libraries for optimization. This is more specific in
--- linux/include/linux/elf.h.jj Wed Sep 9 15:43:40 1998
+++ linux/include/linux/elf.h Fri Sep 11 10:49:33 1998
@@ -129,6 +129,7 @@ typedef __u64 Elf64_Word;
#define AT_EGID 14 /* effective gid */
#define AT_PLATFORM 15 /* string identifying CPU for optimizations */
#define AT_HWCAP 16 /* arch dependent hints at CPU capabilities */
+#define AT_FPUCW 17 /* default FPU control word for a process */

typedef struct dynamic{
Elf32_Sword d_tag;

Cheers,
Jakub
___________________________________________________________________
Jakub Jelinek | jj@sunsite.mff.cuni.cz | http://sunsite.mff.cuni.cz
Administrator of SunSITE Czech Republic, MFF, Charles University
___________________________________________________________________
Ultralinux - first 64bit OS to take full power of the UltraSparc
Linux version 2.1.121 on a sparc64 machine (498.80 BogoMips).
___________________________________________________________________

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/