This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

i386 fpu function rewrite



I'd like to rewrite at least some of the i386 fpu functions that are
currently assembler files to C files.  This has the benefit that we
have stricter prototype checking, can do the bounds checking more
easily and I can use the same file for both i386 and x86-64.  x86-64
uses different calling conventions and has differnt sizes for pointers
so that embedding the assembler in a C file seems to be the best way
to me.

An example is sysdeps/i386/fpu/e_acos.S:

The original file is:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/*
 * Written by J.T. Conklin <jtc@netbsd.org>.
 * Public domain.
 */

#include <machine/asm.h>

RCSID("$NetBSD: e_acos.S,v 1.4 1995/05/08 23:44:37 jtc Exp $")

/* acos = atan (sqrt(1 - x^2) / x) */
ENTRY(__ieee754_acos)
	fldl	4(%esp)			/* x */
	fld	%st			/* x : x */
	fmul	%st(0)			/* x^2 : x */
	fld1				/* 1 : x^2 : x */
	fsubp				/* 1 - x^2 : x */
	fsqrt				/* sqrt (1 - x^2) : x */
	fxch	%st(1)			/* x : sqrt (1 - x^2) */
	fpatan				/* atan (sqrt(1 - x^2) / x) */
	ret
END (__ieee754_acos)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I've rewritten this to sysdeps/i386/fpu/e_acos.c:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#include <math_private.h>

/* acos = atan (sqrt(1 - x^2) / x) */
double
__ieee754_acos (double x)
{
  double res;
  
  asm ("fld	%%st			/* x : x */
	fmul	%%st(0)			/* x^2 : x */
	fld1				/* 1 : x^2 : x */
	fsubp				/* 1 - x^2 : x */
	fsqrt				/* sqrt (1 - x^2) : x */
	fxch	%%st(1)			/* x : sqrt (1 - x^2) */
	fpatan				/* atan (sqrt(1 - x^2) / x) */"
       : "=t" (res) : "0" (x) : "st(1)");

  return res;
  
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This assembles to the same file if I use  -momit-leaf-frame-pointer or
-fomit-frame-pointer, otherwise the frame pointer is added.

I can also easily use this file for x86-64.  Is it ok to continue this
way?  I'd like to send in patches for glibc for e_atan and other
functions soon.

Andreas
-- 
 Andreas Jaeger
  SuSE Labs aj@suse.de
   private aj@arthur.inka.de
    http://www.suse.de/~aj


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]