public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* i386 fpu function rewrite
@ 2001-05-05 11:10 Andreas Jaeger
  2001-05-05 11:31 ` Jakub Jelinek
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Andreas Jaeger @ 2001-05-05 11:10 UTC (permalink / raw)
  To: libc-alpha; +Cc: Jan Hubicka

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: i386 fpu function rewrite
  2001-05-05 11:10 i386 fpu function rewrite Andreas Jaeger
@ 2001-05-05 11:31 ` Jakub Jelinek
  2001-05-05 12:05   ` Andreas Jaeger
  2001-05-05 15:31 ` Jan Hubicka
  2001-05-05 23:31 ` Ulrich Drepper
  2 siblings, 1 reply; 6+ messages in thread
From: Jakub Jelinek @ 2001-05-05 11:31 UTC (permalink / raw)
  To: Andreas Jaeger; +Cc: libc-alpha, Jan Hubicka

On Sat, May 05, 2001 at 08:08:30PM +0200, Andreas Jaeger wrote:
>   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)");

Now that gcc deprecates multi-line string literals you probably should either
use \n\ or make it a bunch of one line strings contatenated together.

	Jakub

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: i386 fpu function rewrite
  2001-05-05 11:31 ` Jakub Jelinek
@ 2001-05-05 12:05   ` Andreas Jaeger
  0 siblings, 0 replies; 6+ messages in thread
From: Andreas Jaeger @ 2001-05-05 12:05 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: libc-alpha, Jan Hubicka

Jakub Jelinek <jakub@redhat.com> writes:

> On Sat, May 05, 2001 at 08:08:30PM +0200, Andreas Jaeger wrote:
> >   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)");
> 
> Now that gcc deprecates multi-line string literals you probably should either
> use \n\ or make it a bunch of one line strings contatenated together.

I noticed this already and will add this in my real patch.  For now I
just like to hear that such a rewrite is acceptable and if there's
anything I should take care of.

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: i386 fpu function rewrite
  2001-05-05 11:10 i386 fpu function rewrite Andreas Jaeger
  2001-05-05 11:31 ` Jakub Jelinek
@ 2001-05-05 15:31 ` Jan Hubicka
  2001-05-05 23:31 ` Ulrich Drepper
  2 siblings, 0 replies; 6+ messages in thread
From: Jan Hubicka @ 2001-05-05 15:31 UTC (permalink / raw)
  To: Andreas Jaeger; +Cc: libc-alpha, Jan Hubicka

> /* 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)");
Most of the instructions here can be generated by gcc itself.
I would say that it is preferable to use c code that calls few
macros to output instructions like fpatan and similar beasts.

This has advantage, that we can use gcc to optimize functions for given
CPU (beside scheduling there are few optimizations gcc can do, like
replacing fld1 by memory load on Pentium) and in future we would like to
replace macros by intrics, like SSE support have.

On the other hand, the reload pass may bring unnecesary fxch instructions
even in such trivial code streams, so I am not sure this is really good
idea, given that gcc will probably stay weak forever on this side.

Honza
> 
>   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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: i386 fpu function rewrite
  2001-05-05 11:10 i386 fpu function rewrite Andreas Jaeger
  2001-05-05 11:31 ` Jakub Jelinek
  2001-05-05 15:31 ` Jan Hubicka
@ 2001-05-05 23:31 ` Ulrich Drepper
  2001-05-06  2:45   ` Andreas Jaeger
  2 siblings, 1 reply; 6+ messages in thread
From: Ulrich Drepper @ 2001-05-05 23:31 UTC (permalink / raw)
  To: Andreas Jaeger; +Cc: libc-alpha, Jan Hubicka

Andreas Jaeger <aj@suse.de> writes:

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

If loading the parameters is all which is done in C then fine.  But no
step further.  Been there, done that.  I've looked into using macros
to add only few asm instructions and do the rest in C.  gcc simply
screws it up.  The register stack handling is not clever enough.

-- 
---------------.                          ,-.   1325 Chesapeake Terrace
Ulrich Drepper  \    ,-------------------'   \  Sunnyvale, CA 94089 USA
Red Hat          `--' drepper at redhat.com   `------------------------

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: i386 fpu function rewrite
  2001-05-05 23:31 ` Ulrich Drepper
@ 2001-05-06  2:45   ` Andreas Jaeger
  0 siblings, 0 replies; 6+ messages in thread
From: Andreas Jaeger @ 2001-05-06  2:45 UTC (permalink / raw)
  To: Ulrich Drepper; +Cc: libc-alpha, Jan Hubicka

Ulrich Drepper <drepper@redhat.com> writes:

> Andreas Jaeger <aj@suse.de> writes:
> 
> > This assembles to the same file if I use  -momit-leaf-frame-pointer or
> > -fomit-frame-pointer, otherwise the frame pointer is added.
> 
> If loading the parameters is all which is done in C then fine.  But no
> step further.  Been there, done that.  I've looked into using macros
> to add only few asm instructions and do the rest in C.  gcc simply
> screws it up.  The register stack handling is not clever enough.

Ok, I'll sent some patches the next days.

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2001-05-06  2:45 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-05-05 11:10 i386 fpu function rewrite Andreas Jaeger
2001-05-05 11:31 ` Jakub Jelinek
2001-05-05 12:05   ` Andreas Jaeger
2001-05-05 15:31 ` Jan Hubicka
2001-05-05 23:31 ` Ulrich Drepper
2001-05-06  2:45   ` Andreas Jaeger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).