From 06467d613002201f625c5bd4d790af13711e9b4a Mon Sep 17 00:00:00 2001 From: Banjo Kazooie Date: Fri, 28 Oct 2022 19:32:32 -0500 Subject: [PATCH] core1/gu/cosf.c done --- README.md | 2 +- include/guint.h | 41 +++++++++++ progress/progress_core1.svg | 4 +- progress/progress_total.svg | 4 +- src/core1/done/gu/cosf.c | 137 ++++++++++++++++++++++++++++++++++++ src/core1/gu/cosf.c | 6 -- subyaml/core1.us.v10.yaml | 5 +- 7 files changed, 186 insertions(+), 13 deletions(-) create mode 100644 include/guint.h create mode 100644 src/core1/done/gu/cosf.c delete mode 100644 src/core1/gu/cosf.c diff --git a/README.md b/README.md index 98dd5ada..fbe2952f 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# banjo (92.2108%) +# banjo (92.2342%) diff --git a/include/guint.h b/include/guint.h new file mode 100644 index 00000000..259bf201 --- /dev/null +++ b/include/guint.h @@ -0,0 +1,41 @@ +/************************************************************************** + * * + * Copyright (C) 1994, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + **************************************************************************/ +#include "mbi.h" +#include "gu.h" + +typedef union +{ + struct + { + unsigned int hi; + unsigned int lo; + } word; + + double d; +} du; + +typedef union +{ + unsigned int i; + float f; +} fu; + +#ifndef __GL_GL_H__ + +typedef float Matrix[4][4]; + +#endif + +#define ROUND(d) (int)(((d) >= 0.0) ? ((d) + 0.5) : ((d) - 0.5)) +#define ABS(d) ((d) > 0) ? (d) : -(d) + +extern float __libm_qnan_f; \ No newline at end of file diff --git a/progress/progress_core1.svg b/progress/progress_core1.svg index 576a72db..9826281b 100644 --- a/progress/progress_core1.svg +++ b/progress/progress_core1.svg @@ -17,7 +17,7 @@ core1 - 84.9818% - 84.9818% + 85.1429% + 85.1429% \ No newline at end of file diff --git a/progress/progress_total.svg b/progress/progress_total.svg index 76ccec42..01fc829c 100644 --- a/progress/progress_total.svg +++ b/progress/progress_total.svg @@ -17,7 +17,7 @@ Banjo-Kazooie (us.v10) - 92.2108% - 92.2108% + 92.2342% + 92.2342% \ No newline at end of file diff --git a/src/core1/done/gu/cosf.c b/src/core1/done/gu/cosf.c new file mode 100644 index 00000000..73c4f121 --- /dev/null +++ b/src/core1/done/gu/cosf.c @@ -0,0 +1,137 @@ +/************************************************************************** + * * + * Copyright (C) 1994, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + **************************************************************************/ + +#include "guint.h" + +/* ==================================================================== + * ==================================================================== + * + * Module: fcos.c + * $Revision: 1.2 $ + * $Date: 1995/07/12 17:47:57 $ + * $Author: jeffd $ + * $Source: /disk6/Master/cvsmdev2/PR/libultra/gu/cosf.c,v $ + * + * Revision history: + * 09-Jun-93 - Original Version + * + * Description: source code for fcos function + * + * ==================================================================== + * ==================================================================== + */ + +#pragma weak fcos = __cosf +#pragma weak cosf = __cosf +#define fcos __cosf + +/* coefficients for polynomial approximation of cos on +/- pi/2 */ + +static const du P[] = +{ +{0x3ff00000, 0x00000000}, +{0xbfc55554, 0xbc83656d}, +{0x3f8110ed, 0x3804c2a0}, +{0xbf29f6ff, 0xeea56814}, +{0x3ec5dbdf, 0x0e314bfe}, +}; + +static const du rpi = +{0x3fd45f30, 0x6dc9c883}; + +static const du pihi = +{0x400921fb, 0x50000000}; + +static const du pilo = +{0x3e6110b4, 0x611a6263}; + +static const fu zero = {0x00000000}; + + +/* ==================================================================== + * + * FunctionName fcos + * + * Description computes cosine of arg + * + * ==================================================================== + */ + +float +fcos( float x ) +{ +float absx; +double dx, xsq, poly; +double dn; +int n; +double result; +int ix, xpt; + + + ix = *(int *)&x; + xpt = (ix >> 22); + xpt &= 0x1ff; + + /* xpt is exponent(x) + 1 bit of mantissa */ + + + if ( xpt < 0x136 ) + { + /* |x| < 2^28 */ + + /* use the standard algorithm from Cody and Waite, doing + the computations in double precision + */ + + absx = ABS(x); + + dx = absx; + + dn = dx*rpi.d + 0.5; + n = ROUND(dn); + dn = n; + + dn -= 0.5; + + dx = dx - dn*pihi.d; + dx = dx - dn*pilo.d; /* dx = x - (n - 0.5)*pi */ + + xsq = dx*dx; + + poly = ((P[4].d*xsq + P[3].d)*xsq + P[2].d)*xsq + P[1].d; + + result = dx + (dx*xsq)*poly; + + /* negate result if n is odd */ + + if ( (n & 1) == 0 ) + return ( (float)result ); + + return ( -(float)result ); + } + + if ( x != x ) + { + /* x is a NaN; return a quiet NaN */ + +#ifdef _IP_NAN_SETS_ERRNO + + *__errnoaddr = EDOM; +#endif + + return ( __libm_qnan_f ); + } + + /* just give up and return 0.0 */ + + return ( zero.f ); +} \ No newline at end of file diff --git a/src/core1/gu/cosf.c b/src/core1/gu/cosf.c deleted file mode 100644 index 49e68b3e..00000000 --- a/src/core1/gu/cosf.c +++ /dev/null @@ -1,6 +0,0 @@ -#include -#include "functions.h" -#include "variables.h" - - -#pragma GLOBAL_ASM("asm/nonmatchings/core1/gu/cosf/cosf.s") diff --git a/subyaml/core1.us.v10.yaml b/subyaml/core1.us.v10.yaml index 32ce4bbe..6c000223 100644 --- a/subyaml/core1.us.v10.yaml +++ b/subyaml/core1.us.v10.yaml @@ -139,7 +139,7 @@ segments: - [0x275E0, c, done/os/settreadpri] #DONE - [0x276C0, c, done/gu/mtxutil] #DONE - [0x27930, c, done/gu/sqrtf] #DONE - - [0x27940, c, gu/cosf] + - [0x27940, c, done/gu/cosf] - [0x27AB0, hasm, ultra/setintmask] #DONE - [0x27B50, c, done/io/dpsetstat] #DONE - [0x27B60, c, done/io/sptask] #DONE @@ -306,7 +306,8 @@ segments: - [0x3B180, .rodata, done/audio/n_resample] - [0x3B190, .rodata, done/gu/sinf] - [0x3B1E0, .rodata, done/audio/cents2ratio] - - [0x3B1F0, bin, data_3B1F0] # .rodata, ultra/setintmask] # splat bug preventing this from linking correctly + - [0x3B1F0, .rodata, done/gu/cosf] + - [0x3B240, bin, data_3B1F0] # .rodata, ultra/setintmask] # splat bug preventing this from linking correctly - [0x3B2C0, .rodata, done/gu/rotate] # need to resolve .data section first - [0x3B2D0, .rodata, done/audio/cseq] - [0x3B2E0, .rodata, done/audio/drvrNew]