Fix fnmadds & fnmsubs emulation + try to provide optimized fma routines for

better precision
This commit is contained in:
gbeauche 2006-07-04 07:06:18 +00:00
parent dc88ee271d
commit 0a74d0559a
4 changed files with 82 additions and 16 deletions

View File

@ -545,7 +545,7 @@ const powerpc_cpu::instr_info_t powerpc_cpu::powerpc_ii_table[] = {
A_form, 63, 31, CFLOW_NORMAL
},
{ "fnmadds",
EXECUTE_FP_ARITH(float, fnmadd, RD, RA, RC, RB, RC_BIT_G, true),
EXECUTE_FP_ARITH(double, fnmadds, RD, RA, RC, RB, RC_BIT_G, true),
NULL,
PPC_I(FNMADDS),
A_form, 59, 31, CFLOW_NORMAL
@ -557,7 +557,7 @@ const powerpc_cpu::instr_info_t powerpc_cpu::powerpc_ii_table[] = {
A_form, 63, 30, CFLOW_NORMAL
},
{ "fnmsubs",
EXECUTE_FP_ARITH(float, fnmsub, RD, RA, RC, RB, RC_BIT_G, true),
EXECUTE_FP_ARITH(double, fnmsubs, RD, RA, RC, RB, RC_BIT_G, true),
NULL,
PPC_I(FNMSUBS),
A_form, 59, 30, CFLOW_NORMAL

View File

@ -132,13 +132,15 @@ DEFINE_OP1(fnop, double, x);
DEFINE_OP1(fabs, double, fabs(x));
DEFINE_OP2(fadd, double, x + y);
DEFINE_OP2(fdiv, double, x / y);
DEFINE_OP3(fmadd, double, (x * y) + z);
DEFINE_OP3(fmsub, double, (x * y) - z);
DEFINE_OP3(fmadd, double, mathlib_fmadd(x, y, z));
DEFINE_OP3(fmsub, double, mathlib_fmsub(x, y, z));
DEFINE_OP2(fmul, double, x * y);
DEFINE_OP1(fnabs, double, -fabs(x));
DEFINE_OP1(fneg, double, -x);
DEFINE_OP3(fnmadd, double, -((x * y) + z));
DEFINE_OP3(fnmsub, double, -((x * y) - z));
DEFINE_OP3(fnmadd, double, -mathlib_fmadd(x, y, z));
DEFINE_OP3(fnmsub, double, -mathlib_fmsub(x, y, z));
DEFINE_OP3(fnmadds, double, -(float)mathlib_fmadd(x, y, z));
DEFINE_OP3(fnmsubs, double, -(float)mathlib_fmsub(x, y, z));
DEFINE_OP2(fsub, double, x - y);
DEFINE_OP3(fsel, double, (x >= 0.0) ? y : z);
DEFINE_OP1(frim, double, floor(x));
@ -146,19 +148,9 @@ DEFINE_OP1(frin, double, round(x));
DEFINE_OP1(frip, double, ceil(x));
DEFINE_OP1(friz, double, trunc(x));
DEFINE_OP1(fnops, float, x);
DEFINE_OP1(fabss, float, fabs(x));
DEFINE_OP2(fadds, float, x + y);
DEFINE_OP2(fdivs, float, x / y);
DEFINE_OP3(fmadds, float, (x * y) + z);
DEFINE_OP3(fmsubs, float, (x * y) - z);
DEFINE_OP2(fmuls, float, x * y);
DEFINE_OP1(fnabss, float, -fabs(x));
DEFINE_OP1(fnegs, float, -x);
DEFINE_OP3(fnmadds, float, -((x * y) + z));
DEFINE_OP3(fnmsubs, float, -((x * y) - z));
DEFINE_OP2(fsubs, float, x - y);
DEFINE_OP1(exp2, float, exp2f(x));
DEFINE_OP1(log2, float, log2f(x));
DEFINE_OP1(fres, float, 1 / x);

View File

@ -0,0 +1,63 @@
/*
* mathlib-ppc.hpp - Math library wrapper, ppc specific code
* Code largely derived from GNU libc
*
* Kheperix (C) 2003-2005 Gwenole Beauchesne
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef MATHLIB_PPC_H
#define MATHLIB_PPC_H
// Floating-Point Multiply Add
#if defined __GNUC__
static inline double mathlib_fmadd(double x, double y, double z)
{
double r;
__asm__ __volatile__ ("fmadd %0,%1,%2,%3" : "=f" (r) : "f" (x), "f" (y) , "f" (z));
return r;
}
static inline float mathlib_fmadd(float x, float y, float z)
{
float r;
__asm__ __volatile__ ("fmadds %0,%1,%2,%3" : "=f" (r) : "f" (x), "f" (y) , "f" (z));
return r;
}
#define mathlib_fmadd(x, y, z) (mathlib_fmadd)(x, y, z)
#endif
// Floating-Point Multiply Subtract
#if defined __GNUC__
static inline double mathlib_fmsub(double x, double y, double z)
{
double r;
__asm__ __volatile__ ("fmsub %0,%1,%2,%3" : "=f" (r) : "f" (x), "f" (y) , "f" (z));
return r;
}
static inline float mathlib_fmsub(float x, float y, float z)
{
float r;
__asm__ __volatile__ ("fmsubs %0,%1,%2,%3" : "=f" (r) : "f" (x), "f" (y) , "f" (z));
return r;
}
#define mathlib_fmsub(x, y, z) (mathlib_fmsub)(x, y, z)
#endif
#endif /* MATHLIB_PPC_H */

View File

@ -79,6 +79,17 @@ enum {
#if defined(__x86_64__)
#include "mathlib/mathlib-x86_64.hpp"
#endif
#if defined(__powerpc__) || defined(__ppc__)
#include "mathlib/mathlib-ppc.hpp"
#endif
// Floating-Point Multiply Add/Subtract functions
#ifndef mathlib_fmadd
#define mathlib_fmadd(x, y, z) (((x) * (y)) + (z))
#endif
#ifndef mathlib_fmsub
#define mathlib_fmsub(x, y, z) (((x) * (y)) - (z))
#endif
// 7.12.6.2 The exp2 functions
#ifdef HAVE_EXP2F