Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

access(), netSocketInfo and unlink(). #63

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
21 changes: 12 additions & 9 deletions common/libsimdmath/common/simdmath/_sincos.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@
#ifndef ___SIMD_MATH__SINCOS_H___
#define ___SIMD_MATH__SINCOS_H___

//
// Common constants used to evaluate sind2/cosd2/tand2
//
/*
* Common constants used to evaluate sind2/cosd2/tand2
*/

#define __SINCOSD_CC0 0.00000000206374484196
#define __SINCOSD_CC1 -0.00000027555365134677
#define __SINCOSD_CC2 0.00002480157946764225
Expand All @@ -51,9 +52,10 @@
#define __SINCOSD_KC2 7.5497899548918821691639751442098584e-8


//
// Common constants used to evaluate sinf4/cosf4/tanf4
//
/*
* Common constants used to evaluate sinf4/cosf4/tanf4
*/

#define __SINCOSF_CC0 -0.0013602249f
#define __SINCOSF_CC1 0.0416566950f
#define __SINCOSF_CC2 -0.4999990225f
Expand All @@ -64,9 +66,10 @@
#define __SINCOSF_KC1 1.57079625129f
#define __SINCOSF_KC2 7.54978995489e-8f

//
// Common constants used to evaluate sinf4est/cosf4est
//
/*
* Common constants used to evaluate sinf4est/cosf4est
*/

#define __SINCOSF_R1 -0.1666665668f
#define __SINCOSF_R2 0.8333025139e-2f
#define __SINCOSF_R3 -0.1980741872e-3f
Expand Down
6 changes: 3 additions & 3 deletions common/libsimdmath/ppu/simdmath/_acosf4.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@

#include <simdmath/_sqrtf4.h>

//
// Computes the inverse cosine of all four slots of x.
//
/*
* Computes the inverse cosine of all four slots of x.
*/
static inline vector float
_acosf4 (vector float x)
{
Expand Down
46 changes: 23 additions & 23 deletions common/libsimdmath/ppu/simdmath/_asinf4.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,53 +39,53 @@
static inline vector float
_asinf4 (vector float x)
{
// positive = (x > 0)
//
/* positive = (x > 0) */

vector unsigned int positive = (vector unsigned int)vec_cmpgt(x, __vec_splatsf4(0.0f));

// x = absf(x)
//
/* x = absf(x) */

x = vec_abs(x);

// gtHalf = (|x| > 0.5)
//
/* gtHalf = (|x| > 0.5) */

vector unsigned int gtHalf = (vector unsigned int)vec_cmpgt(x, __vec_splatsf4(0.5f));


// if (x > 0.5)
// g = 0.5 - 0.5*x
// x = -2 * sqrtf(g)
// else
// g = x * x
//
/* if (x > 0.5)
* g = 0.5 - 0.5*x
* x = -2 * sqrtf(g)
* else
* g = x * x
*/
vector float g =
vec_sel(vec_madd(x, x, __vec_splatsf4(0.0f)),
vec_madd(__vec_splatsf4(-0.5f), x, __vec_splatsf4(0.5f)), gtHalf);

x = vec_sel(x, vec_madd(__vec_splatsf4(-2.0f), _sqrtf4(g), __vec_splatsf4(0.0f)), gtHalf);

// Compute the polynomials and take their ratio
// denom = (1.0f*g + -0.554846723e+1f)*g + 5.603603363f
// num = x * g * (-0.504400557f * g + 0.933933258f)
//
/* Compute the polynomials and take their ratio
* denom = (1.0f*g + -0.554846723e+1f)*g + 5.603603363f
* num = x * g * (-0.504400557f * g + 0.933933258f)
*/
vector float denom = vec_add(g, __vec_splatsf4(-5.54846723f));
vector float num = vec_madd(__vec_splatsf4(-0.504400557f), g, __vec_splatsf4(0.933933258f));
denom = vec_madd(denom, g, __vec_splatsf4(5.603603363f));
num = vec_madd(vec_madd(x, g, __vec_splatsf4(0.0f)), num, __vec_splatsf4(0.0f));


// x = x + num / denom
//
/* x = x + num / denom */

x = vec_add(x,_divf4(num,denom));

// if (x > 0.5)
// x = x + M_PI_2
//
/* if (x > 0.5)
* x = x + M_PI_2
*/
x = vec_sel(x,vec_add(x, __vec_splatsf4(1.57079632679489661923f)), gtHalf);


// if (!positive) x = -x
//
/* if (!positive) x = -x */

x = vec_sel((vector float)vec_xor(__vec_splatsi4(0x80000000), (vector signed int)x),
x, positive);

Expand Down
21 changes: 11 additions & 10 deletions common/libsimdmath/ppu/simdmath/_atan2f4.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,22 @@

#include <simdmath/_atanf4.h>

//
// Inverse tangent function of two variables
//
/*
* Inverse tangent function of two variables
*/

static inline vector float
_atan2f4 (vector float y, vector float x)
{
vector float res = _atanf4(divf4(y,x));

// Use the arguments to determine the quadrant of the result:
// if (x < 0)
// if (y < 0)
// res = -PI + res
// else
// res = PI + res
//
/* Use the arguments to determine the quadrant of the result:
* if (x < 0)
* if (y < 0)
* res = -PI + res
* else
* res = PI + res
*/
vector unsigned int yNeg = (vector unsigned int)vec_cmpgt(__vec_splatsf4(0.0f), y);
vector unsigned int xNeg = (vector unsigned int)vec_cmpgt(__vec_splatsf4(0.0f) ,x);

Expand Down
7 changes: 4 additions & 3 deletions common/libsimdmath/ppu/simdmath/_atanf4.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@

#include <simdmath/_recipf4.h>

//
// Computes the inverse tangent of all four slots of x.
//
/*
* Computes the inverse tangent of all four slots of x.
*/

static inline vector float
_atanf4 (vector float x)
{
Expand Down
6 changes: 3 additions & 3 deletions common/libsimdmath/ppu/simdmath/_cbrtf4.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ __cbrtf4_calc_quot(vector signed int n)
return quot;
}

#define __CBRTF_cbrt2 1.2599210498948731648 // 2^(1/3)
#define __CBRTF_sqr_cbrt2 1.5874010519681994748 // 2^(2/3)
#define __CBRTF_cbrt2 1.2599210498948731648 /* 2^(1/3) */
#define __CBRTF_sqr_cbrt2 1.5874010519681994748 /* 2^(2/3) */

static inline vector float
_cbrtf4 (vector float x)
Expand All @@ -77,7 +77,7 @@ _cbrtf4 (vector float x)
vector float p3 = vec_madd(p, vec_madd(p, p, zeros), zeros);

vector signed int quot = __cbrtf4_calc_quot(xexp);
// mod = xexp - 3*quotient
/* mod = xexp - 3*quotient */
vector signed int modval = vec_sub(vec_sub(xexp,quot), vec_sl(quot, __vec_splatsu4(1)));
vector float factor = __vec_splatsf4(1.0/__CBRTF_sqr_cbrt2);
factor = vec_sel(factor, __vec_splatsf4(1.0/__CBRTF_cbrt2), vec_cmpeq(modval, __vec_splatsi4(-1)));
Expand Down
54 changes: 29 additions & 25 deletions common/libsimdmath/ppu/simdmath/_cosf4.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,48 +37,51 @@
#include <simdmath/_vec_utils.h>


//
// Computes the cosine of each of the four slots
// by using a polynomial approximation.
//
/*
* Computes the cosine of each of the four slots
* by using a polynomial approximation.
*/

static inline vector float
_cosf4 (vector float x)
{
vector float xl,xl2,xl3,res;
vector signed int q;

// Range reduction using : xl = angle * TwoOverPi;
//
/* Range reduction using : xl = angle * TwoOverPi; */

xl = vec_madd(x, __vec_splatsf4(0.63661977236f), __vec_splatsf4(0.0f));

// Find the quadrant the angle falls in
// using: q = (int) (ceil(abs(xl))*sign(xl))
//
/* Find the quadrant the angle falls in
* using: q = (int) (ceil(abs(xl))*sign(xl))
*/

xl = vec_add(xl, vec_sel(__vec_splatsf4(0.5f), xl, __vec_splatsu4(0x80000000)));
q = vec_cts(xl, 0);


// Compute an offset based on the quadrant that the angle falls in
//
/* Compute an offset based on the quadrant that the angle falls in */

vector signed int offset = vec_add(__vec_splatsi4(1), vec_and(q, __vec_splatsi4(0x3)));

// Remainder in range [-pi/4..pi/4]
//
/* Remainder in range [-pi/4..pi/4] */

vector float qf = vec_ctf(q,0);
vector float p1 = vec_nmsub(qf, __vec_splatsf4(__SINCOSF_KC1), x);
xl = vec_nmsub(qf, __vec_splatsf4(__SINCOSF_KC2), p1);

// Compute x^2 and x^3
//
/* Compute x^2 and x^3 */

xl2 = vec_madd(xl, xl, __vec_splatsf4(0.0f));
xl3 = vec_madd(xl2, xl, __vec_splatsf4(0.0f));


// Compute both the sin and cos of the angles
// using a polynomial expression:
// cx = 1.0f + xl2 * ((C0 * xl2 + C1) * xl2 + C2), and
// sx = xl + xl3 * ((S0 * xl2 + S1) * xl2 + S2)
//
/* Compute both the sin and cos of the angles
* using a polynomial expression:
* cx = 1.0f + xl2 * ((C0 * xl2 + C1) * xl2 + C2), and
* sx = xl + xl3 * ((S0 * xl2 + S1) * xl2 + S2)
*/

vector float ct1 = vec_madd(__vec_splatsf4(__SINCOSF_CC0), xl2, __vec_splatsf4(__SINCOSF_CC1));
vector float st1 = vec_madd(__vec_splatsf4(__SINCOSF_SC0), xl2, __vec_splatsf4(__SINCOSF_SC1));

Expand All @@ -88,15 +91,16 @@ _cosf4 (vector float x)
vector float cx = vec_madd(ct2, xl2, __vec_splatsf4(1.0f));
vector float sx = vec_madd(st2, xl3, xl);

// Use the cosine when the offset is odd and the sin
// when the offset is even
//
/* Use the cosine when the offset is odd and the sin
* when the offset is even
*/

vector unsigned int mask1 =
(vector unsigned int)vec_cmpeq(vec_and(offset, __vec_splatsi4(0x1)), __vec_splatsi4(0));
res = vec_sel(cx, sx, mask1);

// Flip the sign of the result when (offset mod 4) = 1 or 2
//
/* Flip the sign of the result when (offset mod 4) = 1 or 2 */

vector unsigned int mask2 =
(vector unsigned int)vec_cmpeq(vec_and(offset, __vec_splatsi4(0x2)), __vec_splatsi4(0));
res = vec_sel((vector float)vec_xor(__vec_splatsu4(0x80000000U), (vector unsigned int)res), res, mask2);
Expand Down
2 changes: 1 addition & 1 deletion common/libsimdmath/ppu/simdmath/_divf4.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
static inline vector float
_divf4 (vector float numer, vector float denom)
{
// Reciprocal estimate and 1 Newton-Raphson iteration.
/* Reciprocal estimate and 1 Newton-Raphson iteration. */

vector float y0, y0numer;

Expand Down
13 changes: 7 additions & 6 deletions common/libsimdmath/ppu/simdmath/_divi4.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@

#include <simdmath/_vec_utils.h>

// divi4 - for each of four integer slots, compute quotient and remainder of numer/denom
// and store in divi4_t struct. Divide by zero produces quotient = 0, remainder = numerator.
/* divi4 - for each of four integer slots, compute quotient and remainder of numer/denom
* and store in divi4_t struct. Divide by zero produces quotient = 0, remainder = numerator.
*/

static inline divi4_t
_divi4 (vector signed int numer, vector signed int denom )
Expand All @@ -54,18 +55,18 @@ _divi4 (vector signed int numer, vector signed int denom )
vector unsigned int quot, newQuot, skip, newNum, cont;
int anyCont;

// determine whether result needs sign change
/* determine whether result needs sign change */

numerPos = (vector unsigned int)vec_cmpgt( numer, minusone );
denomPos = (vector unsigned int)vec_cmpgt( denom, minusone );
quotNeg = vec_xor( numerPos, denomPos );

// use absolute values of numerator, denominator
/* use absolute values of numerator, denominator */

numerAbs = (vector unsigned int)vec_sel( vec_sub( (vector signed int)zero, numer ), numer, numerPos );
denomAbs = (vector unsigned int)vec_sel( vec_sub( (vector signed int)zero, denom ), denom, denomPos );

// get difference of leading zeros to align denom with numer
/* get difference of leading zeros to align denom with numer */

denomZeros = vec_sub( k158, vec_sr( (vector unsigned int)vec_ctf( denomAbs, 0 ), k23 ) );
numerZeros = vec_sub( k158, vec_sr( (vector unsigned int)vec_ctf( numerAbs, 0 ), k23 ) );
Expand All @@ -76,7 +77,7 @@ _divi4 (vector signed int numer, vector signed int denom )
oneShifted = vec_sel( oneShifted, zero, vec_or( vec_cmpeq( denomAbs, zero ),
vec_cmpgt( denomAbs, numerAbs ) ) );

// long division
/* long division */

quot = zero;

Expand Down
13 changes: 8 additions & 5 deletions common/libsimdmath/ppu/simdmath/_exp2f4.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@
* this range will produce undefined results.
*/


#define __EXP2F_LN2 0.69314718055995f /* ln(2) */
/* ln(2) */
#define __EXP2F_LN2 0.69314718055995f

static inline vector float
_exp2f4 (vector float x)
Expand All @@ -103,10 +103,12 @@ _exp2f4 (vector float x)
frac = vec_sub(vec_ctf(ix, 0), x);
frac = vec_madd(frac, __vec_splatsf4(__EXP2F_LN2), zeros);

overflow = (vector unsigned int)vec_cmpgt(x, (vector float)(__vec_splatsi4(0x4300FFFF))); // !!! Biggest possible exponent to fit in range.
/* !!! Biggest possible exponent to fit in range. */
overflow = (vector unsigned int)vec_cmpgt(x, (vector float)(__vec_splatsi4(0x4300FFFF)));
underflow = (vector unsigned int)vec_cmpgt(__vec_splatsf4(-126.0f), x);

exp_int = (vector float)(vec_sl(vec_add(ix, __vec_splatsi4(126)), __vec_splatsu4(23))); // !!! HRD <- add with saturation
/* !!! HRD <- add with saturation */
exp_int = (vector float)(vec_sl(vec_add(ix, __vec_splatsi4(126)), __vec_splatsu4(23)));

/* Instruction counts can be reduced if the polynomial was
* computed entirely from nested (dependent) fma's. However,
Expand All @@ -125,7 +127,8 @@ _exp2f4 (vector float x)

exp_frac = vec_madd(frac4, hi, lo);
result = vec_madd(exp_frac, exp_int, zeros);
result = vec_madd(exp_frac, exp_int, result); // !!! HRD
/* !!! HRD */
result = vec_madd(exp_frac, exp_int, result);

/* Handle overflow */
result = vec_sel(result, __vec_splatsf4(HUGE_VALF), overflow);
Expand Down
Loading