Added SCE SIMD math library in Extras/simdmathlibrary

The upcoming vectormath that will used to speed up the SPU version of Extras/BulletMultiThreaded depends on this.
This commit is contained in:
ejcoumans
2007-07-23 04:58:24 +00:00
parent 685138d033
commit 7529cdb3f6
287 changed files with 32064 additions and 0 deletions

View File

@@ -0,0 +1,147 @@
# make file to build the libsimdmath library for PPU
# Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms,
# with or without modification, are permitted provided that the
# following conditions are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of the Sony Computer Entertainment Inc nor the names
# of its contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
# All that you do to add a file is edit OBJS, the rest will just work
prefix = /usr
DESTDIR =
OBJS = fabsf4.o absi4.o truncf4.o sqrtf4.o tanf4.o \
negatef4.o fmaf4.o copysignf4.o modff4.o \
fmaxf4.o fminf4.o fdimf4.o sinf4.o asinf4.o \
floorf4.o recipf4.o ceilf4.o divf4.o divi4.o \
cosf4.o hypotf4.o cbrtf4.o logf4.o sincosf4.o \
rsqrtf4.o log2f4.o ldexpf4.o expf4.o frexpf4.o \
expm1f4.o logbf4.o log1pf4.o log10f4.o ilogbf4.o \
fmodf4.o negatei4.o exp2f4.o powf4.o atanf4.o \
atan2f4.o acosf4.o
INCLUDES_PPU = -I../
ARCH_PPU = 64
CROSS_PPU = ppu-
AR_PPU = $(CROSS_PPU)ar
CC_PPU = $(CROSS_PPU)gcc
CXX_PPU = $(CROSS_PPU)g++
RANLIB_PPU = $(CROSS_PPU)ranlib
TEST_CMD_PPU =
ARCH_CFLAGS_PPU = -m$(ARCH_PPU) -maltivec -mabi=altivec
CFLAGS_PPU=$(INCLUDES_PPU) -O2 -W -Wall -std=gnu99 $(ARCH_CFLAGS_PPU) -fPIC
LDFLAGS_PPU = $(ARCH_CFLAGS_PPU)
INSTALL = install
MAKE_DEFS = \
prefix='$(prefix)' \
DESTDIR='$(DESTDIR)' \
LIB_BASE='$(LIB_BASE)' \
LIB_NAME='$(LIB_NAME)' \
STATIC_LIB='$(STATIC_LIB)' \
SHARED_LIB='$(SHARED_LIB)' \
ARCH_PPU='$(ARCH_PPU)' \
ARCH_CFLAGS_PPU='$(ARCH_CFLAGS_PPU)' \
CROSS_PPU='$(CROSS_PPU)' \
AR_PPU='$(AR_PPU)' \
CC_PPU='$(CC_PPU)' \
CXX_PPU='$(CXX_PPU)' \
RANLIB_PPU='$(RANLIB_PPU)' \
TEST_CMD_PPU='$(TEST_CMD_PPU)' \
INSTALL='$(INSTALL)'
LIB_MAJOR_VERSION = 1
LIB_MINOR_VERSION = 0
LIB_BASE = simdmath
LIB_NAME = lib$(LIB_BASE)
STATIC_LIB = $(LIB_NAME).a
SHARED_LIB = $(LIB_NAME).so
SHARED_LIB_SONAME = $(SHARED_LIB).$(LIB_MAJOR_VERSION)
SHARED_LIB_FULL = $(SHARED_LIB).$(LIB_MAJOR_VERSION).$(LIB_MINOR_VERSION)
ALL_LIBS = $(STATIC_LIB) $(SHARED_LIB) $(SHARED_LIB_FULL) $(SHARED_LIB_SONAME)
all: $(ALL_LIBS)
static: $(STATIC_LIB)
shared: $(SHARED_LIB)
$(STATIC_LIB): $(OBJS)
$(AR_PPU) cr $@ $(OBJS)
$(RANLIB_PPU) $@
$(SHARED_LIB): $(OBJS)
$(CC_PPU) -shared $(OBJS) -o $@ $(LDFLAGS_PPU) -Wl,-h,$(SHARED_LIB_SONAME)
$(SHARED_LIB_SONAME) $(SHARED_LIB_FULL): $(SHARED_LIB)
ln -fs $(SHARED_LIB) $@
install: $(ALL_LIBS)
$(INSTALL) -m 755 -d $(DESTDIR)$(prefix)/include
$(INSTALL) -m 644 ../simdmath.h $(DESTDIR)$(prefix)/include/
$(INSTALL) -m 755 -d $(DESTDIR)$(prefix)/lib
$(INSTALL) -m 644 $(STATIC_LIB) $(DESTDIR)$(prefix)/lib/$(STATIC_LIB)
$(INSTALL) -m 755 $(SHARED_LIB) $(DESTDIR)$(prefix)/lib/$(SHARED_LIB_FULL)
ln -fs $(SHARED_LIB_FULL) $(DESTDIR)$(prefix)/lib/$(SHARED_LIB_SONAME)
ln -fs $(SHARED_LIB_SONAME) $(DESTDIR)$(prefix)/lib/$(SHARED_LIB)
clean:
cd tests; $(MAKE) $(MAKE_DEFS) clean
rm -f $(OBJS)
rm -f $(STATIC_LIB) $(SHARED_LIB) $(SHARED_LIB_SONAME) $(SHARED_LIB_FULL)
$(OBJS): ../simdmath.h common-types.h
check: $(ALL_LIBS)
cd tests; $(MAKE) $(MAKE_DEFS) all; $(MAKE) $(MAKE_DEFS) check
# Some Objects have special header files.
sinf4.o cosf4.o sincosf4.o tanf4.o: sincos_c.h
%.o: %.c
$(CC_PPU) $(CFLAGS_PPU) -c $<
#----------
# C++
#----------
%.o: %.C
$(CXX_PPU) $(CFLAGS_PPU) -c $<
%.o: %.cpp
$(CXX_PPU) $(CFLAGS_PPU) -c $<
%.o: %.cc
$(CXX_PPU) $(CFLAGS_PPU) -c $<
%.o: %.cxx
$(CXX_PPU) $(CFLAGS_PPU) -c $<

View File

@@ -0,0 +1,40 @@
/* absi4 - for each of four integer slots, compute absolute value.
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved.
Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#include <simdmath.h>
#include <altivec.h>
vector signed int
absi4 (vector signed int x)
{
return vec_abs( x );
}

View File

@@ -0,0 +1,79 @@
/* acosf4 -
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved.
Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#include <simdmath.h>
#include <altivec.h>
#include "common-types.h"
//
// Computes the inverse cosine of all four slots of x.
//
vector float
acosf4 (vector float x)
{
vec_float4 result, xabs;
vec_float4 t1;
vec_float4 xabs2, xabs4;
vec_float4 hi, lo;
vec_float4 neg, pos;
vec_uint4 select;
xabs = vec_abs(x);
select = (vec_uint4)(vec_sra((vec_int4)(x), ((vec_uint4){31, 31, 31, 31}) ));
t1 = sqrtf4(vec_sub( ((vec_float4){1.0, 1.0, 1.0, 1.0}) , xabs));
/* Instruction counts can be reduced if the polynomial was
* computed entirely from nested (dependent) fma's. However,
* to reduce the number of pipeline stalls, the polygon is evaluated
* in two halves (hi amd lo).
*/
xabs2 = vec_madd(xabs, xabs, ((vec_float4){0.0f, 0.0f, 0.0f, 0.0f}) );
xabs4 = vec_madd(xabs2, xabs2, ((vec_float4){0.0f, 0.0f, 0.0f, 0.0f}) );
hi = vec_madd( ((vec_float4){-0.0012624911, -0.0012624911, -0.0012624911, -0.0012624911}) , xabs, ((vec_float4){0.0066700901, 0.0066700901, 0.0066700901, 0.0066700901}) );
hi = vec_madd(hi, xabs, vec_splatsf4(-0.0170881256));
hi = vec_madd(hi, xabs, vec_splatsf4( 0.0308918810));
lo = vec_madd(vec_splatsf4(-0.0501743046), xabs, vec_splatsf4(0.0889789874));
lo = vec_madd(lo, xabs, vec_splatsf4(-0.2145988016));
lo = vec_madd(lo, xabs, vec_splatsf4( 1.5707963050));
result = vec_madd(hi, xabs4, lo);
/* Adjust the result if x is negactive.
*/
neg = vec_nmsub(t1, result, vec_splatsf4(3.1415926535898f));
pos = vec_madd(t1, result, ((vec_float4){0.0f, 0.0f, 0.0f, 0.0f}) );
result = vec_sel(pos, neg, select);
return result;
}

View File

@@ -0,0 +1,86 @@
/* asinf4 - Computes the inverse sine of all four slots of x
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved.
Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#include <simdmath.h>
#include <altivec.h>
#include "common-types.h"
vector float asinf4 (vector float x)
{
// positive = (x > 0)
//
vec_uint4 positive = (vec_uint4)vec_cmpgt(x,vec_splatsf4(0.0f));
// x = absf(x)
//
x = vec_abs(x);
// gtHalf = (|x| > 0.5)
//
vec_uint4 gtHalf = (vec_uint4)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
//
vec_float4 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)
//
vec_float4 denom = vec_add(g,vec_splatsf4(-5.54846723f));
vec_float4 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 = vec_add(x,divf4(num,denom));
// 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
//
x = vec_sel((vec_float4)vec_xor(vec_splatsi4(0x80000000),(vec_int4)x),x,positive);
return x;
}

View File

@@ -0,0 +1,61 @@
/* atan2f4 -
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved.
Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#include <simdmath.h>
#include <altivec.h>
#include "common-types.h"
//
// Inverse tangent function of two variables
//
vector float
atan2f4 (vector float y, vector float x)
{
vec_float4 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
//
vec_uint4 yNeg = (vec_uint4)vec_cmpgt( ((vec_float4){0.0f, 0.0f, 0.0f, 0.0f}) ,y);
vec_uint4 xNeg = (vec_uint4)vec_cmpgt( ((vec_float4){0.0f, 0.0f, 0.0f, 0.0f}) ,x);
vec_float4 bias = vec_sel(vec_splatsf4(3.14159265358979323846f),vec_splatsf4(-3.14159265358979323846f),yNeg);
vec_float4 newRes = vec_add(bias, res);
res = vec_sel(res,newRes,xNeg);
return res;
}

View File

@@ -0,0 +1,83 @@
/* atanf4 -
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved.
Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#include <simdmath.h>
#include <altivec.h>
#include "common-types.h"
//
// Computes the inverse tangent of all four slots of x.
//
vector float
atanf4 (vector float x)
{
vec_float4 bias;
vec_float4 x2, x3, x4, x8, x9;
vec_float4 hi, lo;
vec_float4 result;
vec_float4 inv_x;
vec_uint4 sign;
vec_uint4 select;
vec_float4 xabs;
vec_float4 vzero = (vec_float4){0.0, 0.0, 0.0, 0.0};
sign = vec_and((vec_uint4)x, vec_splatsu4(0x80000000));
xabs = (vec_float4)vec_andc((vec_uint4)x, vec_splatsu4(0x80000000));
inv_x = recipf4(x);
inv_x = (vec_float4)vec_xor((vec_uint4)inv_x, vec_splatsu4(0x80000000));
select = (vec_uint4)vec_cmpgt(xabs, ((vec_float4){1.0, 1.0, 1.0, 1.0}) );
bias = (vec_float4)vec_or(sign, (vec_uint4)(vec_splatsf4(1.57079632679489661923f)));
bias = (vec_float4)vec_and((vec_uint4)bias, select);
x = vec_sel(x, inv_x, select);
/* Instruction counts can be reduced if the polynomial was
* computed entirely from nested (dependent) fma's. However,
* to reduce the number of pipeline stalls, the polygon is evaluated
* in two halves(hi and lo).
*/
bias = vec_add(bias, x);
x2 = vec_madd(x, x, vzero);
x3 = vec_madd(x2, x, vzero);
x4 = vec_madd(x2, x2, vzero);
x8 = vec_madd(x4, x4, vzero);
x9 = vec_madd(x8, x, vzero);
hi = vec_madd(vec_splatsf4(0.0028662257), x2, vec_splatsf4(-0.0161657367));
hi = vec_madd(hi, x2, vec_splatsf4(0.0429096138));
hi = vec_madd(hi, x2, vec_splatsf4(-0.0752896400));
hi = vec_madd(hi, x2, vec_splatsf4(0.1065626393));
lo = vec_madd(vec_splatsf4(-0.1420889944), x2, vec_splatsf4(0.1999355085));
lo = vec_madd(lo, x2, vec_splatsf4(-0.3333314528));
lo = vec_madd(lo, x3, bias);
result = vec_madd(hi, x9, lo);
return result;
}

View File

@@ -0,0 +1,103 @@
/* cbrtf4 -
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved.
Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#include <simdmath.h>
#include <altivec.h>
#include "common-types.h"
#define __calcQuot(xexp) n = xexp; \
vec_uint4 negxexpmask = (vec_uint4)vec_cmpgt( ((vec_int4){0, 0, 0, 0}) , n); \
n = vec_sel(n, vec_add(n, ((vec_int4){2, 2, 2, 2}) ), negxexpmask); \
\
quot = vec_add(vec_sra(n, ((vec_uint4){2, 2, 2, 2}) ), vec_sra(n, ((vec_uint4){4, 4, 4, 4}) )); \
quot = vec_add(quot, vec_sra(quot, ((vec_uint4){4, 4, 4, 4}) )); \
quot = vec_add(quot, vec_sra(quot, ((vec_uint4){8, 8, 8, 8}) )); \
quot = vec_add(quot, vec_sra(quot, ((vec_uint4){16, 16, 16, 16}) )); \
vec_int4 r = vec_sub(vec_sub(n,quot), vec_sl(quot, ((vec_uint4){1, 1, 1, 1}) )); \
quot = vec_add( \
quot, \
vec_sra( \
vec_add( \
vec_add(r,((vec_int4){5, 5, 5, 5})), \
vec_sl (r,((vec_uint4){2, 2, 2, 2})) \
), \
((vec_uint4){4, 4, 4, 4}) \
) \
); \
#define _CBRTF_H_cbrt2 1.2599210498948731648 // 2^(1/3)
#define _CBRTF_H_sqr_cbrt2 1.5874010519681994748 // 2^(2/3)
vector float
cbrtf4 (vector float x)
{
vec_float4 zeros = (vec_float4){0.0f, 0.0f, 0.0f, 0.0f};
vec_int4 xexp, n;
vec_float4 sgnmask = (vec_float4)(vec_splatsi4(0x80000000));
vec_uint4 negmask = (vec_uint4)vec_cmpgt(zeros, x);
x = vec_andc(x, sgnmask);
x = frexpf4(x, &xexp);
vec_float4 p = vec_madd(
vec_madd(x, vec_splatsf4(-0.191502161678719066f), vec_splatsf4(0.697570460207922770f)),
x,
vec_splatsf4(0.492659620528969547f)
);
vec_float4 p3 = vec_madd(p, vec_madd(p, p, zeros), zeros);
vec_int4 quot;
__calcQuot(xexp);
vec_int4 modval = vec_sub(vec_sub(xexp,quot), vec_sl(quot,vec_splatsu4(1))); // mod = xexp - 3*quotient
vec_float4 factor = vec_splatsf4(1.0/_CBRTF_H_sqr_cbrt2);
factor = vec_sel(factor, vec_splatsf4(1.0/_CBRTF_H_cbrt2), vec_cmpeq(modval,vec_splatsi4(-1)));
factor = vec_sel(factor, vec_splatsf4( 1.0), vec_cmpeq(modval,vec_splatsi4( 0)));
factor = vec_sel(factor, vec_splatsf4( _CBRTF_H_cbrt2), vec_cmpeq(modval,vec_splatsi4( 1)));
factor = vec_sel(factor, vec_splatsf4(_CBRTF_H_sqr_cbrt2), vec_cmpeq(modval,vec_splatsi4( 2)));
vec_float4 pre = vec_madd(p, factor, zeros);
vec_float4 numr = vec_madd(x , vec_splatsf4(2.0f), p3);
vec_float4 denr = vec_madd(p3, vec_splatsf4(2.0f), x );
vec_float4 res = vec_madd(pre, divf4(numr, denr), zeros);
res = ldexpf4(res, quot);
return vec_sel(res, vec_or(res,sgnmask), negmask);
}
/*
_FUNC_DEF(vec_float4, cbrtf4, (vec_float4 x))
{
vec_uint4 neg = (vec_uint4)vec_cmpgt((vec_float4)(0.0f), x);
vec_float4 sbit = (vec_float4)(vec_float4)((int)0x80000000);
vec_float4 absx = vec_andc(x, sbit);
vec_float4 res = exp2f4(vec_mul((vec_float4)(0.3333333333333f), log2f4(absx)));
res = vec_sel(res, vec_or(sbit, res), neg);
return res;
}
*/

View File

@@ -0,0 +1,39 @@
/* ceilf4 - for each of four float slots, round up to smallest integer not less than the value.
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved.
Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#include <simdmath.h>
#include <altivec.h>
vector float
ceilf4 (vector float x)
{
return vec_ceil( x );
}

View File

@@ -0,0 +1,52 @@
/* Common types for PPU SIMD Math Library
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved.
Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef ___COMMON_TYPES_H___
#define ___COMMON_TYPES_H___
typedef vector float vec_float4;
typedef vector signed int vec_int4;
typedef vector unsigned int vec_uint4;
static inline vec_float4 vec_splatsf4(const float x)
{
return (vec_float4) {x, x, x, x};
}
static inline vec_int4 vec_splatsi4(const signed int x)
{
return (vec_int4) {x, x, x, x};
}
static inline vec_uint4 vec_splatsu4(const unsigned int x)
{
return (vec_uint4) {x, x, x, x};
}
#endif

View File

@@ -0,0 +1,41 @@
/* copysignf4 - for each of four float slots, return value with magnitude from x and sign from y.
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved.
Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#include <simdmath.h>
#include <altivec.h>
#include "common-types.h"
vector float
copysignf4 (vector float x, vector float y)
{
return vec_sel( x, y, vec_splatsu4(0x80000000) );
}

View File

@@ -0,0 +1,104 @@
/* cosf4 -
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved.
Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#include <simdmath.h>
#include <altivec.h>
#include "sincos_c.h"
#include "common-types.h"
//
// Computes the cosine of each of the four slots
// by using a polynomial approximation.
//
vector float
cosf4 (vector float x)
{
vec_float4 xl,xl2,xl3,res;
vec_int4 q;
// 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))
//
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
//
vec_int4 offset = vec_add(vec_splatsi4(1),vec_and(q,vec_splatsi4((int)0x3)));
// Remainder in range [-pi/4..pi/4]
//
vec_float4 qf = vec_ctf(q,0);
vec_float4 p1 = vec_nmsub(qf,vec_splatsf4(_SINCOS_KC1),x);
xl = vec_nmsub(qf,vec_splatsf4(_SINCOS_KC2),p1);
// 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)
//
vec_float4 ct1 = vec_madd(vec_splatsf4(_SINCOS_CC0),xl2,vec_splatsf4(_SINCOS_CC1));
vec_float4 st1 = vec_madd(vec_splatsf4(_SINCOS_SC0),xl2,vec_splatsf4(_SINCOS_SC1));
vec_float4 ct2 = vec_madd(ct1,xl2,vec_splatsf4(_SINCOS_CC2));
vec_float4 st2 = vec_madd(st1,xl2,vec_splatsf4(_SINCOS_SC2));
vec_float4 cx = vec_madd(ct2,xl2,vec_splatsf4(1.0f));
vec_float4 sx = vec_madd(st2,xl3,xl);
// Use the cosine when the offset is odd and the sin
// when the offset is even
//
vec_uint4 mask1 = (vec_uint4)vec_cmpeq(vec_and(offset,
((vec_int4){0x1, 0x1, 0x1, 0x1})),
((vec_int4){0, 0, 0, 0}));
res = vec_sel(cx,sx,mask1);
// Flip the sign of the result when (offset mod 4) = 1 or 2
//
vec_uint4 mask2 = (vec_uint4)vec_cmpeq(vec_and(offset,vec_splatsi4(0x2)),vec_splatsi4((int)0));
res = vec_sel((vec_float4)vec_xor(vec_splatsu4(0x80000000U),(vec_uint4)res),res,mask2);
return res;
}

View File

@@ -0,0 +1,47 @@
/* divf4 - for each of four float slots, divide numer by denom.
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved.
Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#include <simdmath.h>
#include <altivec.h>
#include "common-types.h"
vector float
divf4 (vector float numer, vector float denom)
{
// Reciprocal estimate and 1 Newton-Raphson iteration.
vector float y0, y0numer;
y0 = vec_re( denom );
y0numer = vec_madd( numer, y0, ((vec_float4){0.0f, 0.0f, 0.0f, 0.0f}) );
return vec_madd( vec_nmsub( denom, y0, ((vec_float4){1.0f, 1.0f, 1.0f, 1.0f}) ), y0numer, y0numer );
}

View File

@@ -0,0 +1,103 @@
/* divi4 -
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved.
Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#include <simdmath.h>
#include <altivec.h>
#include "common-types.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_t
divi4 (vec_int4 numer, vec_int4 denom )
{
vec_int4 minusone = vec_splatsi4(-1);
vec_uint4 zero = vec_splatsu4(0);
vec_uint4 one = vec_splatsu4(1);
vec_uint4 k158 = vec_splatsu4(158);
vec_uint4 k23 = vec_splatsu4(23);
divi4_t res;
vec_uint4 numerPos, denomPos, quotNeg;
vec_uint4 numerAbs, denomAbs;
vec_uint4 denomZeros, numerZeros, shift, denomShifted, oneShifted;
vec_uint4 quot, newQuot, skip, newNum, cont;
int anyCont;
// determine whether result needs sign change
numerPos = (vec_uint4)vec_cmpgt( numer, minusone );
denomPos = (vec_uint4)vec_cmpgt( denom, minusone );
quotNeg = vec_xor( numerPos, denomPos );
// use absolute values of numerator, denominator
numerAbs = (vec_uint4)vec_sel( vec_sub( (vec_int4)zero, numer ), numer, numerPos );
denomAbs = (vec_uint4)vec_sel( vec_sub( (vec_int4)zero, denom ), denom, denomPos );
// get difference of leading zeros to align denom with numer
denomZeros = vec_sub( k158, vec_sr( (vec_uint4)vec_ctf( denomAbs, 0 ), k23 ) );
numerZeros = vec_sub( k158, vec_sr( (vec_uint4)vec_ctf( numerAbs, 0 ), k23 ) );
shift = vec_sub( denomZeros, numerZeros );
denomShifted = vec_sl( denomAbs, shift );
oneShifted = vec_sl( one, shift );
oneShifted = vec_sel( oneShifted, zero, vec_or( vec_cmpeq( denomAbs, zero ),
vec_cmpgt( denomAbs, numerAbs ) ) );
// long division
quot = zero;
do
{
cont = (vec_uint4)vec_cmpgt( oneShifted, zero );
anyCont = vec_any_gt( oneShifted, zero );
skip = (vec_uint4)vec_cmpgt( denomShifted, numerAbs );
newQuot = vec_or( quot, oneShifted );
newNum = vec_sub( numerAbs, denomShifted );
oneShifted = vec_sr( oneShifted, one );
denomShifted = vec_sr( denomShifted, one );
quot = vec_sel( newQuot, quot, skip );
numerAbs = vec_sel( numerAbs, newNum, vec_andc( cont, skip ) );
}
while ( anyCont );
res.quot = (vec_int4)vec_sel( quot, vec_sub( zero, quot ), quotNeg );
res.rem = (vec_int4)vec_sel( (vec_uint4)vec_sub( (vec_int4)zero, (vec_int4)numerAbs ), numerAbs, numerPos );
return res;
}

View File

@@ -0,0 +1,138 @@
/* exp2f4
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved.
Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#include <simdmath.h>
#include <altivec.h>
#include <math.h>
#include "common-types.h"
/*
* FUNCTION
* vec_float4 _exp2_v(vec_float4 x)
*
* DESCRIPTION
* _exp2_v computes 2 raised to the input vector x. Computation is
* performed by observing the 2^(a+b) = 2^a * 2^b.
* We decompose x into a and b (above) by letting.
* a = ceil(x), b = x - a;
*
* 2^a is easilty computed by placing a into the exponent
* or a floating point number whose mantissa is all zeros.
*
* 2^b is computed using the following polynomial approximation.
* (C. Hastings, Jr, 1955).
*
* __7__
* \
* \
* 2^(-x) = / Ci*x^i
* /____
* i=1
*
* for x in the range 0.0 to 1.0
*
* C0 = 1.0
* C1 = -0.9999999995
* C2 = 0.4999999206
* C3 = -0.1666653019
* C4 = 0.0416573475
* C5 = -0.0083013598
* C6 = 0.0013298820
* C7 = -0.0001413161
*
* This function does not handle out of range conditions. It
* assumes that x is in the range (-128.0, 127.0]. Values outside
* this range will produce undefined results.
*/
#define _EXP2F_H_LN2 0.69314718055995f /* ln(2) */
vector float
exp2f4 (vector float x)
{
vec_int4 ix;
vec_uint4 overflow;
vec_uint4 underflow;
vec_float4 frac, frac2, frac4;
vec_float4 exp_int, exp_frac;
vec_float4 result;
vec_float4 hi, lo;
vec_float4 zeros = vec_splatsf4(0.0f);
vec_float4 bias;
/* Break in the input x into two parts ceil(x), x - ceil(x).
*/
#if 1
bias = (vec_float4)(vec_sra((vec_int4)x, vec_splatsu4(31) ));
bias = (vec_float4)(vec_andc(vec_splatsu4(0x3F7FFFFF), (vec_uint4)bias));
ix = vec_cts(vec_add(x, bias), 0);
#else
bias = vec_sel(vec_floor(x), vec_ceil(x), vec_cmpgt(x, vec_splatsf4(0.0f)));
ix = vec_cts(bias, 0);
#endif
frac = vec_sub(vec_ctf(ix, 0), x);
frac = vec_madd(frac, vec_splatsf4(_EXP2F_H_LN2), zeros);
// !!! HRD Changing weird un-understandable and incorrect overflow handling code
//overflow = vec_sel((vec_uint4)(0x7FFFFFFF), (vec_uint4)x, (vec_uint4)(0x80000000) );
overflow = (vec_uint4)vec_cmpgt(x, (vec_float4)(vec_splatsi4(0x4300FFFF))); // !!! Biggest possible exponent to fit in range.
underflow = (vec_uint4)vec_cmpgt(vec_splatsf4(-126.0f), x);
//exp_int = (vec_float4)(vec_sl(vec_add(ix, (vec_int4)(127)), (vec_uint4)(23))); // !!! HRD <- changing this to correct for
// !!! overflow (x >= 127.999999f)
exp_int = (vec_float4)(vec_sl(vec_add(ix, vec_splatsi4(126)), vec_splatsu4(23))); // !!! HRD <- add with saturation
/* Instruction counts can be reduced if the polynomial was
* computed entirely from nested (dependent) fma's. However,
* to reduce the number of pipeline stalls, the polygon is evaluated
* in two halves (hi amd lo).
*/
frac2 = vec_madd(frac, frac, zeros);
frac4 = vec_madd(frac2, frac2, zeros);
hi = vec_madd(frac, vec_splatsf4(-0.0001413161), vec_splatsf4(0.0013298820));
hi = vec_madd(frac, hi, vec_splatsf4(-0.0083013598));
hi = vec_madd(frac, hi, vec_splatsf4(0.0416573475));
lo = vec_madd(frac, vec_splatsf4(-0.1666653019), vec_splatsf4(0.4999999206));
lo = vec_madd(frac, lo, vec_splatsf4(-0.9999999995));
lo = vec_madd(frac, lo, vec_splatsf4(1.0));
exp_frac = vec_madd(frac4, hi, lo);
//ix = vec_add(ix, vec_sr((vec_int4)(exp_frac), (vec_uint4)(23) ));
result = vec_madd(exp_frac, exp_int, zeros);
result = vec_madd(exp_frac, exp_int, result); // !!! HRD
/* Handle overflow */
result = vec_sel(result, vec_splatsf4(HUGE_VALF), overflow);
result = vec_sel(result, zeros, underflow);
//result = vec_sel(result, (vec_float4)(overflow), vec_cmpgt((vec_uint4)(ix), (vec_uint4)(255)));
return (result);
}

View File

@@ -0,0 +1,65 @@
/* expf4 -
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved.
Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#include <simdmath.h>
#include <altivec.h>
#include "common-types.h"
#define _EXPF_H_C1 ((float)-0.6931470632553101f)
#define _EXPF_H_C2 ((float)-1.1730463525082e-7f)
#define _EXPF_H_INVLN2 ((float)1.4426950408889634f)
vector float
expf4 (vector float x)
{
vec_float4 zeros = vec_splatsf4(0.0f);
vec_uint4 xnegmask = (vec_uint4)vec_cmpgt(zeros, x);
vec_float4 goffset = vec_sel(vec_splatsf4( 0.5f),vec_splatsf4(-0.5f),xnegmask);
vec_float4 g = vec_madd(x, vec_splatsf4(_EXPF_H_INVLN2), zeros);
vec_int4 xexp = vec_cts(vec_add(g, goffset),0);
g = vec_ctf(xexp, 0);
g = vec_madd(g, vec_splatsf4(_EXPF_H_C2), vec_madd(g, vec_splatsf4(_EXPF_H_C1), x));
vec_float4 z = vec_madd(g, g, zeros);
vec_float4 a = vec_madd(z, vec_splatsf4(0.0999748594f), zeros);
vec_float4 b = vec_madd(g,
vec_madd(z,
vec_splatsf4(0.0083208258f),
vec_splatsf4(0.4999999992f)
),
zeros);
vec_float4 foo = divf4(vec_add(vec_splatsf4(1.0f), vec_add(a, b)),
vec_add(vec_splatsf4(1.0f), vec_sub(a, b)));
return ldexpf4(foo, xexp);
}

View File

@@ -0,0 +1,57 @@
/* expm1f4 -
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved.
Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#include <simdmath.h>
#include <altivec.h>
#include "common-types.h"
#define _EXPM1F_H_ln1by2 ((float)-0.6931471805599f)
#define _EXPM1F_H_ln3by2 ((float) 0.4054651081082f)
vector float
expm1f4 (vector float x)
{
vec_float4 zeros = vec_splatsf4(0.0f);
vec_uint4 nearzeromask = (vec_uint4)vec_and(vec_cmpgt(x, vec_splatsf4(_EXPM1F_H_ln1by2)),
vec_cmpgt(vec_splatsf4(_EXPM1F_H_ln3by2), x));
vec_float4 x2 = vec_madd(x,x,zeros);
vec_float4 d0, d1, n0, n1;
d0 = vec_madd(x , vec_splatsf4(-0.3203561199f), vec_splatsf4(0.9483177697f));
d1 = vec_madd(x2, vec_splatsf4( 0.0326527809f), d0);
n0 = vec_madd(x , vec_splatsf4(0.1538026623f), vec_splatsf4(0.9483177732f));
n1 = vec_madd(x , vec_splatsf4(0.0024490478f), vec_splatsf4(0.0305274668f));
n1 = vec_madd(x2, n1, n0);
return vec_sel(vec_sub(expf4(x), vec_splatsf4(1.0f)),
vec_madd(x, divf4(n1, d1), zeros),
nearzeromask);
}

View File

@@ -0,0 +1,38 @@
/* fabsf4 - for each of four float slots, compute absolute value.
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved.
Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#include <simdmath.h>
#include <altivec.h>
vector float fabsf4(vector float x)
{
return vec_abs( x );
}

View File

@@ -0,0 +1,39 @@
/* fdimf -
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved.
Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#include <simdmath.h>
#include <altivec.h>
vector float
fdimf4 (vector float x, vector float y)
{
vector float diff = vec_sub(x,y);
return vec_sel(((vector float){0.0f, 0.0f, 0.0f, 0.0f}), diff, vec_cmpgt(x,y));
}

View File

@@ -0,0 +1,39 @@
/* floorf4 - for each of four float slots, round down to largest integer not greater than the value.
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved.
Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#include <simdmath.h>
#include <altivec.h>
vector float
floorf4 (vector float x)
{
return vec_floor( x );
}

View File

@@ -0,0 +1,37 @@
/* fmaf4
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved.
Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#include <simdmath.h>
#include <altivec.h>
vector float
fmaf4 (vector float x, vector float y, vector float z)
{
return vec_madd(x,y,z);
}

View File

@@ -0,0 +1,40 @@
/* fmaxf4 - for each of four float slots, compute maximum of x and y
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved.
Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#include <simdmath.h>
#include <altivec.h>
vector float
fmaxf4 (vector float x, vector float y)
{
return vec_max( x, y );
}

View File

@@ -0,0 +1,39 @@
/* fminf4 - for each of four float slots, compute minimum of x and y
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved.
Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#include <simdmath.h>
#include <altivec.h>
vector float
fminf4 (vector float x, vector float y)
{
return vec_min( x, y );
}

View File

@@ -0,0 +1,82 @@
/* fmodf4 - for each of four float slots, compute remainder of x/y defined as x - truncated_integer(x/y) * y.
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved.
Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#include <simdmath.h>
#include <altivec.h>
#include "common-types.h"
//
// This returns an accurate result when |divf4(x,y)| < 2^20 and |x| < 2^128, and otherwise returns zero.
// If x == 0, the result is 0.
// If x != 0 and y == 0, the result is undefined.
vector float
fmodf4 (vector float x, vector float y)
{
vec_float4 q, xabs, yabs, qabs, xabs2;
vec_int4 qi0, qi1, qi2;
vec_float4 i0, i1, i2, r1, r2, i;
vec_uint4 inrange;
// Find i = truncated_integer(|x/y|)
// If |divf4(x,y)| < 2^20, the quotient is at most off by 1.0.
// Thus i is either the truncated quotient, one less, or one greater.
q = divf4( x, y );
xabs = fabsf4( x );
yabs = fabsf4( y );
qabs = fabsf4( q );
xabs2 = vec_add( xabs, xabs );
inrange = (vec_uint4)vec_cmpgt( (vec_float4)(vec_splatsu4(0x49800000)), qabs );
qi1 = vec_cts( qabs, 0 );
qi0 = vec_add( qi1, ((vec_int4){-1, -1, -1, -1}) );
qi2 = vec_add( qi1, ((vec_int4){1, 1, 1, 1}) );
i0 = vec_ctf( qi0, 0 );
i1 = vec_ctf( qi1, 0 );
i2 = vec_ctf( qi2, 0 );
// Correct i will be the largest one such that |x| - i*|y| >= 0.
r1 = vec_nmsub( i1, yabs, xabs );
r2 = vec_nmsub( i2, yabs, xabs );
i = i0;
i = vec_sel( i1, i, vec_cmpgt( vec_splatsi4(0), (vec_int4)r1 ) );
i = vec_sel( i2, i, vec_cmpgt( vec_splatsi4(0), (vec_int4)r2 ) );
i = copysignf4( i, q );
return vec_sel( vec_splatsf4(0.0f), vec_nmsub( i, y, x ), inrange );
}

View File

@@ -0,0 +1,57 @@
/* frexpf4 -
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved.
Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#include <simdmath.h>
#include <altivec.h>
#include "common-types.h"
vector float
frexpf4 (vector float x, vector signed int *exp)
{
vec_int4 zeros = (vec_int4){0,0,0,0};
vec_uint4 zeromask = (vec_uint4)vec_cmpeq(x, (vec_float4)zeros);
vec_int4 expmask = vec_splatsi4(0x7F800000);
vec_int4 e1 = vec_and ( (vec_int4)x, expmask);
vec_int4 e2 = vec_sub(vec_sr(e1, vec_splatsu4(23) ), vec_splatsi4(126) );
*exp = vec_sel(e2, zeros, zeromask);
vec_float4 m2 = vec_sel(x, (vec_float4)(vec_splatsi4(0x3F000000)), (vec_uint4)expmask);
return vec_sel(m2, (vec_float4)zeros, zeromask);
}
/*
{
*exp = ((vec_int4)(0));
return ((vec_float4)(0.0f));
}
*/

View File

@@ -0,0 +1,41 @@
/* hypotf4 -
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved.
Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#include <simdmath.h>
#include <altivec.h>
#include "common-types.h"
vector float
hypotf4 (vector float x, vector float y)
{
vec_float4 sum = vec_madd(x,x, ((vec_float4){0.0f, 0.0f, 0.0f, 0.0f}) );
sum = vec_madd(y,y,sum);
return sqrtf4(sum);
}

View File

@@ -0,0 +1,47 @@
/* ilogbf4 -
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved.
Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#include <simdmath.h>
#include <altivec.h>
#include <math.h>
#include "common-types.h"
vector signed int
ilogbf4 (vector float x)
{
vec_int4 minus127 = vec_splatsi4(-127);
vec_int4 e1 = vec_and((vec_int4)x, vec_splatsi4(0x7F800000));
vec_uint4 zeromask = (vec_uint4)vec_cmpeq(e1, vec_splatsi4(0));
vec_int4 e2 = vec_add(vec_sr(e1,vec_splatsu4(23)), minus127);
return vec_sel(e2, vec_splatsi4(FP_ILOGB0), zeromask);
}

View File

@@ -0,0 +1,58 @@
/* ldexpf4 -
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved.
Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#include <simdmath.h>
#include <altivec.h>
#include "common-types.h"
vector float
ldexpf4 (vector float x, vector signed int exp)
{
vec_int4 zeros = vec_splatsi4(0);
vec_int4 expmask = vec_splatsi4(0x7F800000);
vec_int4 e1 = vec_and((vec_int4)x, expmask);
vec_int4 e2 = vec_sr(e1,vec_splatsu4(23));
vec_uint4 maxmask = (vec_uint4)vec_cmpgt(exp, vec_splatsi4(255));
vec_uint4 minmask = (vec_uint4)vec_cmpgt(vec_splatsi4(-255), exp);
minmask = vec_or (minmask, (vec_uint4)vec_cmpeq(x, (vec_float4)zeros));
vec_int4 esum = vec_add(e2, exp);
maxmask = vec_or (maxmask, (vec_uint4)vec_cmpgt(esum, vec_splatsi4(255)));
maxmask = vec_and(maxmask, vec_splatsu4(0x7FFFFFFF));
minmask = vec_or (minmask, (vec_uint4)vec_cmpgt(zeros, esum));
x = vec_sel(x, (vec_float4)vec_sl(esum,vec_splatsu4(23)), (vec_uint4)expmask);
x = vec_sel(x, (vec_float4)zeros, minmask);
x = vec_sel(x, (vec_float4)maxmask, maxmask);
return x;
}

View File

@@ -0,0 +1,82 @@
/* log10f4 -
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved.
Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#include <simdmath.h>
#include <altivec.h>
#include "common-types.h"
#define _LOG10F_H_loga2msb ((float) 0.3010299205780f)
#define _LOG10F_H_loga2lsb ((float) 7.5085978266e-8f)
#define _LOG10F_H_logaemsb ((float) 0.4342944622040f)
#define _LOG10F_H_logaelsb ((float) 1.9699272335e-8f)
#define _LOG10F_H_neglogae ((float)-0.4342944819033f)
#define _LOG10F_H_c0 ((float)(-0.2988439998f))
#define _LOG10F_H_c1 ((float)(-0.3997655209f))
#define _LOG10F_H_c2 ((float)(-0.6666679125f))
vector float
log10f4 (vector float x)
{
vec_int4 zeros = vec_splatsi4(0);
vec_float4 ones = vec_splatsf4(1.0f);
//vec_uchar16 zeromask = (vec_uchar16)vec_cmpeq(x, (vec_float4)zeros);
vec_int4 expmask = vec_splatsi4(0x7F800000);
vec_int4 xexp = vec_add( vec_sr(vec_and((vec_int4)x, expmask), vec_splatsu4(23)), vec_splatsi4(-126) );
x = vec_sel(x, (vec_float4)(vec_splatsi4(0x3F000000)), (vec_uint4)expmask);
vec_uint4 mask = (vec_uint4)vec_cmpgt( vec_splatsf4((float)0.7071067811865f), x);
x = vec_sel(x , vec_add(x, x) , mask);
xexp = vec_sel(xexp, vec_sub(xexp, vec_splatsi4(1)), mask);
vec_float4 x1 = vec_sub(x , ones);
vec_float4 z = divf4 (x1, vec_add(x, ones));
vec_float4 w = vec_madd(z , z, (vec_float4)zeros);
vec_float4 polywneg;
polywneg = vec_madd(vec_splatsf4(_LOG10F_H_c0), w, vec_splatsf4(_LOG10F_H_c1));
polywneg = vec_madd(polywneg , w, vec_splatsf4(_LOG10F_H_c2));
vec_float4 y = vec_madd(z, vec_madd(polywneg, w, x1), (vec_float4)zeros);
vec_float4 wnew = vec_ctf(xexp,0);
vec_float4 zz1 = vec_madd(vec_splatsf4(_LOG10F_H_logaemsb), x1,
vec_madd(vec_splatsf4(_LOG10F_H_loga2msb),wnew,(vec_float4)zeros));
vec_float4 zz2 = vec_madd(vec_splatsf4(_LOG10F_H_logaelsb), x1,
vec_madd(vec_splatsf4(_LOG10F_H_loga2lsb), wnew,
vec_madd(vec_splatsf4(_LOG10F_H_neglogae),y,(vec_float4)zeros))
);
//return vec_sel(vec_add(zz1,zz2), (vec_float4)zeromask, zeromask);
return vec_add(zz1, zz2);
}

View File

@@ -0,0 +1,54 @@
/* log1pf4 -
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved.
Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#include <simdmath.h>
#include <altivec.h>
#include "common-types.h"
vector float
log1pf4 (vector float x)
{
vec_uint4 nearzeromask = (vec_uint4)vec_and(vec_cmpgt(x, vec_splatsf4(-0.5f)),
vec_cmpgt(vec_splatsf4(0.5f), x));
vec_float4 x2 = vec_madd(x,x,vec_splatsf4(0.0f));
vec_float4 d0, d1, n0, n1;
d0 = vec_madd(x , vec_splatsf4(1.5934420741f), vec_splatsf4(0.8952856868f));
d1 = vec_madd(x , vec_splatsf4(0.1198195734f), vec_splatsf4(0.8377145063f));
d1 = vec_madd(x2, d1, d0);
n0 = vec_madd(x , vec_splatsf4(1.1457993413f), vec_splatsf4(0.8952856678f));
n1 = vec_madd(x , vec_splatsf4(0.0082862580f), vec_splatsf4(0.3394238808f));
n1 = vec_madd(x2, n1, n0);
return vec_sel(logf4(vec_add(x, vec_splatsf4(1.0f))),
vec_madd(x, divf4(n1, d1), vec_splatsf4(0.0f)),
nearzeromask);
}

View File

@@ -0,0 +1,80 @@
/* log2f4 -
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved.
Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#include <simdmath.h>
#include <altivec.h>
#include "common-types.h"
#define _LOG2F_H_l2emsb ((float) 1.4426950216293f)
#define _LOG2F_H_l2elsb ((float) 1.9259629911e-8f)
#define _LOG2F_H_negl2e ((float)-1.4426950408890f)
#define _LOG2F_H_c0 ((float)(-0.2988439998f))
#define _LOG2F_H_c1 ((float)(-0.3997655209f))
#define _LOG2F_H_c2 ((float)(-0.6666679125f))
vector float
log2f4 (vector float x)
{
vec_int4 zeros = vec_splatsi4(0);
vec_float4 ones = vec_splatsf4(1.0f);
//vec_uint4 zeromask = (vec_uint4)vec_cmpeq(x, (vec_float4)zeros);
vec_int4 expmask = vec_splatsi4(0x7F800000);
vec_int4 xexp = vec_add( vec_sr(vec_and((vec_int4)x, expmask), vec_splatsu4(23)), vec_splatsi4(-126) );
x = vec_sel(x, (vec_float4)(vec_splatsi4(0x3F000000)), (vec_uint4)expmask);
vec_uint4 mask = (vec_uint4)vec_cmpgt( vec_splatsf4((float)0.7071067811865f), x);
x = vec_sel(x , vec_add(x, x) , mask);
xexp = vec_sel(xexp, vec_sub(xexp, vec_splatsi4(1) ), mask);
vec_float4 x1 = vec_sub(x , ones);
vec_float4 z = divf4(x1, vec_add(x, ones));
vec_float4 w = vec_madd(z , z, (vec_float4)zeros);
vec_float4 polywneg;
polywneg = vec_madd(vec_splatsf4(_LOG2F_H_c0), w, vec_splatsf4(_LOG2F_H_c1));
polywneg = vec_madd(polywneg , w, vec_splatsf4(_LOG2F_H_c2));
vec_float4 y = vec_madd(z, vec_madd(polywneg, w, x1), (vec_float4)zeros);
vec_float4 zz1 = vec_madd(vec_splatsf4(_LOG2F_H_l2emsb), x1, vec_ctf(xexp,0));
vec_float4 zz2 = vec_madd(vec_splatsf4(_LOG2F_H_l2elsb), x1,
vec_madd(vec_splatsf4(_LOG2F_H_negl2e), y, (vec_float4)zeros)
);
//return vec_sel(vec_add(zz1,zz2), (vec_float4)zeromask, zeromask);
return vec_add(zz1,zz2);
}
/*
{
return ((vec_float4)(0.0f));
}
*/

View File

@@ -0,0 +1,44 @@
/* logbf4 -
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved.
Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#include <simdmath.h>
#include <altivec.h>
#include <math.h>
#include "common-types.h"
vector float
logbf4 (vector float x)
{
vec_int4 e1 = vec_and((vec_int4)x, vec_splatsi4(0x7F800000));
vec_uint4 zeromask = (vec_uint4)vec_cmpeq(e1, vec_splatsi4(0));
e1 = vec_sub(e1, vec_splatsi4(0x3F800000));
return vec_sel(vec_ctf(e1,23), vec_splatsf4(-HUGE_VALF), zeromask);
}

View File

@@ -0,0 +1,73 @@
/* logf4 -
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved.
Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#include <simdmath.h>
#include <altivec.h>
#include "common-types.h"
#define _LOGF_H_ln2msb ((float)(0.6931470632553f))
#define _LOGF_H_negln2lsb ((float)(-1.1730463525e-7f))
#define _LOGF_H_c0 ((float)(-0.2988439998f))
#define _LOGF_H_c1 ((float)(-0.3997655209f))
#define _LOGF_H_c2 ((float)(-0.6666679125f))
vector float
logf4 (vector float x)
{
vec_int4 zeros = vec_splatsi4(0);
vec_float4 ones = vec_splatsf4(1.0f);
//vec_uchar16 zeromask = (vec_uchar16)vec_cmpeq(x, (vec_float4)zeros);
vec_int4 expmask = vec_splatsi4(0x7F800000);
vec_int4 xexp = vec_add( vec_sr(vec_and((vec_int4)x, expmask), vec_splatsu4(23)), vec_splatsi4(-126) );
x = vec_sel(x, (vec_float4)(vec_splatsi4(0x3F000000)), (vec_uint4)expmask);
vec_uint4 mask = (vec_uint4)vec_cmpgt(vec_splatsf4((float)0.7071067811865f), x);
x = vec_sel(x , vec_add(x, x) , mask);
xexp = vec_sel(xexp, vec_sub(xexp,vec_splatsi4(1)), mask);
vec_float4 x1 = vec_sub(x , ones);
vec_float4 z = divf4 (x1, vec_add(x, ones));
vec_float4 w = vec_madd(z , z, (vec_float4)zeros);
vec_float4 polywneg;
polywneg = vec_madd(vec_splatsf4(_LOGF_H_c0), w, vec_splatsf4(_LOGF_H_c1));
polywneg = vec_madd(polywneg , w, vec_splatsf4(_LOGF_H_c2));
vec_float4 y = vec_madd(z, vec_madd(polywneg, w, x1), (vec_float4)zeros);
vec_float4 wnew = vec_ctf(xexp,0);
vec_float4 zz1 = vec_madd(vec_splatsf4(_LOGF_H_ln2msb) , wnew, x1);
vec_float4 zz2neg = vec_madd(vec_splatsf4(_LOGF_H_negln2lsb), wnew, y );
//return vec_sel(vec_sub(zz1,zz2neg), (vec_float4)zeromask, zeromask);
return vec_sub(zz1,zz2neg);
}

View File

@@ -0,0 +1,47 @@
/* modff4
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved.
Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#include <simdmath.h>
#include <altivec.h>
// modff4 - for each of four float slots, compute fractional and integral parts.
// Returns fractional part and stores integral part in *iptr.
vector float
modff4 (vector float x, vector float *iptr)
{
vector float integral, fraction;
integral = truncf4( x );
fraction = vec_sub( x, integral );
*iptr = integral;
return fraction;
}

View File

@@ -0,0 +1,40 @@
/* negatef4 - for each of four float slots, negate the sign bit.
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved.
Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#include <simdmath.h>
#include <altivec.h>
#include "common-types.h"
vector float
negatef4 (vector float x)
{
return (vector float)vec_xor( (vector unsigned int)x, vec_splatsu4(0x80000000) );
}

View File

@@ -0,0 +1,39 @@
/* negatei4 - for each of four int slots, negate the sign bit.
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved.
Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#include <simdmath.h>
#include <altivec.h>
vector signed int
negatei4 (vector signed int x)
{
vector signed int zero = (vector signed int){0, 0, 0, 0};
return vec_sub (zero, x);
}

View File

@@ -0,0 +1,74 @@
/* exp2f4
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved.
Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#include <simdmath.h>
#include <altivec.h>
#include <math.h>
#include "common-types.h"
vector float
powf4 (vector float x, vector float y)
{
vec_int4 zeros = (vec_int4){0,0,0,0};
vec_uint4 zeromask = (vec_uint4)vec_cmpeq((vec_float4)zeros, x);
vec_uint4 negmask = (vec_uint4)vec_cmpgt((vec_float4)zeros, x);
vec_float4 sbit = (vec_float4)(vec_splatsi4(0x80000000));
vec_float4 absx = vec_andc(x, sbit);
vec_float4 absy = vec_andc(y, sbit);
vec_uint4 oddy = vec_and(vec_ctu(absy, 0), vec_splatsu4(0x00000001));
negmask = vec_and(negmask, (vec_uint4)vec_cmpgt(oddy, (vec_uint4)zeros));
vec_float4 res = exp2f4(vec_madd(y, log2f4(absx), (vec_float4)zeros));
res = vec_sel(res, vec_or(sbit, res), negmask);
return vec_sel(res, (vec_float4)zeros, zeromask);
}
/*
{
vec_int4 zeros = vec_splats(0);
vec_int4 ones = (vec_int4)vec_splats((char)0xFF);
vec_uint4 zeromask = (vec_uint4)vec_cmpeq((vec_float4)zeros, x);
vec_uint4 onemask = (vec_uint4)vec_cmpeq((vec_float4)ones , y);
vec_uint4 negmask = (vec_uint4)vec_cmpgt(vec_splats(0.0f), x);
vec_float4 sbit = (vec_float4)(vec_int4)(0x80000000);
vec_float4 absx = vec_andc(x, sbit);
vec_float4 absy = vec_andc(y, sbit);
vec_uint4 oddy = vec_and(vec_convtu(absy, 0), (vec_uint4)vec_splats(0x00000001));
negmask = vec_and(negmask, (vec_uint4)vec_cmpgt(oddy, (vec_uint4)zeros));
}
*/

View File

@@ -0,0 +1,46 @@
/* recipf4 - for each of four float slots, compute reciprocal.
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved.
Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#include <simdmath.h>
#include <altivec.h>
#include "common-types.h"
vector float
recipf4 (vector float x)
{
// Reciprocal estimate and 1 Newton-Raphson iteration.
vec_float4 y0;
vec_float4 ones = ((vec_float4){1.0f, 1.0f, 1.0f, 1.0f});
y0 = vec_re( x );
return vec_madd( vec_nmsub( x, y0, ones), y0, y0 );
}

View File

@@ -0,0 +1,53 @@
/* sqrtf4 -
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved.
Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#include <simdmath.h>
#include <altivec.h>
#include "common-types.h"
// rsqrtf4 - for each of four float slots, compute reciprocal square root.
// Undefined if input < 0.
vector float
rsqrtf4 (vector float x)
{
// Reciprocal square root estimate and 1 Newton-Raphson iteration.
vector float zero = vec_splatsf4(0.0f);
vector float half = vec_splatsf4(0.5f);
vector float one = vec_splatsf4(1.0f);
vector float y0, y0x, y0half;
y0 = vec_rsqrte( x );
y0x = vec_madd( y0, x, zero );
y0half = vec_madd( y0, half, zero );
return vec_madd( vec_nmsub( y0, y0x, one ), y0half, y0 );
}

View File

@@ -0,0 +1,96 @@
/* Common constants for Sin/Cos/Tan
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved.
Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __SINCOS_C2__
#define __SINCOS_C2__
//
// Common constants used to evaluate sind2/cosd2/tand2
//
#define _SINCOS_CC0D 0.00000000206374484196
#define _SINCOS_CC1D -0.00000027555365134677
#define _SINCOS_CC2D 0.00002480157946764225
#define _SINCOS_CC3D -0.00138888888730525966
#define _SINCOS_CC4D 0.04166666666651986722
#define _SINCOS_CC5D -0.49999999999999547304
#define _SINCOS_SC0D 0.00000000015893606014
#define _SINCOS_SC1D -0.00000002505069049138
#define _SINCOS_SC2D 0.00000275573131527032
#define _SINCOS_SC3D -0.00019841269827816117
#define _SINCOS_SC4D 0.00833333333331908278
#define _SINCOS_SC5D -0.16666666666666612594
#define _SINCOS_KC1D (13176794.0 / 8388608.0)
#define _SINCOS_KC2D 7.5497899548918821691639751442098584e-8
//
// Common constants used to evaluate sinf4/cosf4/tanf4
//
#define _SINCOS_CC0 -0.0013602249f
#define _SINCOS_CC1 0.0416566950f
#define _SINCOS_CC2 -0.4999990225f
#define _SINCOS_SC0 -0.0001950727f
#define _SINCOS_SC1 0.0083320758f
#define _SINCOS_SC2 -0.1666665247f
#define _SINCOS_KC1 1.57079625129f
#define _SINCOS_KC2 7.54978995489e-8f
//
// Common constants used to evaluate sinf4est/cosf4est
//
#define _SINCOS_R1 -0.1666665668f
#define _SINCOS_R2 0.8333025139e-2f
#define _SINCOS_R3 -0.1980741872e-3f
#define _SINCOS_R4 0.2601903036e-5f
#define _SINCOS_C1 (201.0f/64.0f)
#define _SINCOS_C2 9.67653589793e-4f
// common constants used to evaluate sinf/cosf
#define _SIN_C1 -0.35950439e-4f
#define _SIN_C2 0.2490001007e-2f
#define _SIN_C3 -0.8074543253e-1f
#define _SIN_C4 0.7853981633f
#define _COS_C1 -0.31872783e-3f
#define _COS_C2 0.1584968416e-1f
#define _COS_C3 -0.30842416558f
#define _COS_C4 0.9999999673f
#define POW2(x) x*x
#define SPOLY(x) (((_SIN_C1 * POW2(x) + _SIN_C2) * POW2(x) + (_SIN_C3)) * POW2(x) + _SIN_C4) * x
#define CPOLY(x) (((_COS_C1 * POW2(x) + _COS_C2) * POW2(x) + (_COS_C3)) * POW2(x) + _COS_C4)
#define M_PI 3.141592653589793f
#endif

View File

@@ -0,0 +1,106 @@
/* sincosf4 -
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved.
Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#include <simdmath.h>
#include <altivec.h>
#include "sincos_c.h"
#include "common-types.h"
//
// Computes both the sine and cosine of the all four slots of x
// by using a polynomial approximation.
//
void sincosf4 (vector float x, vector float *s, vector float *c)
{
vec_float4 xl,xl2,xl3;
vec_int4 q;
vec_int4 offsetSin, offsetCos;
// 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))
//
xl = vec_add(xl,vec_sel(vec_splatsf4(0.5f),xl,vec_splatsu4(0x80000000)));
q = vec_cts(xl,0);
// Compute the offset based on the quadrant that the angle falls in.
// Add 1 to the offset for the cosine.
//
offsetSin = vec_and(q,vec_splatsi4((int)0x3));
offsetCos = vec_add(vec_splatsi4(1),offsetSin);
// Remainder in range [-pi/4..pi/4]
//
vec_float4 qf = vec_ctf(q,0);
vec_float4 p1 = vec_nmsub(qf,vec_splatsf4(_SINCOS_KC1),x);
xl = vec_nmsub(qf,vec_splatsf4(_SINCOS_KC2),p1);
// 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)
//
vec_float4 ct1 = vec_madd(vec_splatsf4(_SINCOS_CC0),xl2,vec_splatsf4(_SINCOS_CC1));
vec_float4 st1 = vec_madd(vec_splatsf4(_SINCOS_SC0),xl2,vec_splatsf4(_SINCOS_SC1));
vec_float4 ct2 = vec_madd(ct1,xl2,vec_splatsf4(_SINCOS_CC2));
vec_float4 st2 = vec_madd(st1,xl2,vec_splatsf4(_SINCOS_SC2));
vec_float4 cx = vec_madd(ct2,xl2,vec_splatsf4(1.0f));
vec_float4 sx = vec_madd(st2,xl3,xl);
// Use the cosine when the offset is odd and the sin
// when the offset is even
//
vec_uint4 sinMask = (vec_uint4)vec_cmpeq(vec_and(offsetSin,vec_splatsi4(0x1)),vec_splatsi4(0));
vec_uint4 cosMask = (vec_uint4)vec_cmpeq(vec_and(offsetCos,vec_splatsi4(0x1)),vec_splatsi4(0));
*s = vec_sel(cx,sx,sinMask);
*c = vec_sel(cx,sx,cosMask);
// Flip the sign of the result when (offset mod 4) = 1 or 2
//
sinMask = (vec_uint4)vec_cmpeq(vec_and(offsetSin,vec_splatsi4(0x2)),vec_splatsi4(0));
cosMask = (vec_uint4)vec_cmpeq(vec_and(offsetCos,vec_splatsi4(0x2)),vec_splatsi4(0));
*s = vec_sel((vec_float4)vec_xor(vec_splatsu4(0x80000000),(vec_uint4)*s),*s,sinMask);
*c = vec_sel((vec_float4)vec_xor(vec_splatsu4(0x80000000),(vec_uint4)*c),*c,cosMask);
}

View File

@@ -0,0 +1,103 @@
/* sinf4 -
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved.
Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#include <simdmath.h>
#include <altivec.h>
#include "sincos_c.h"
#include "common-types.h"
//
// Computes the sine of each of the four slots
// by using a polynomial approximation.
//
vector float
sinf4 (vector float x)
{
vec_float4 xl,xl2,xl3,res;
vec_int4 q;
// 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))
//
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
//
vec_int4 offset = vec_and(q,vec_splatsi4((int)0x3));
// Remainder in range [-pi/4..pi/4]
//
vec_float4 qf = vec_ctf(q,0);
vec_float4 p1 = vec_nmsub(qf,vec_splatsf4(_SINCOS_KC1),x);
xl = vec_nmsub(qf,vec_splatsf4(_SINCOS_KC2),p1);
// 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)
//
vec_float4 ct1 = vec_madd(vec_splatsf4(_SINCOS_CC0),xl2,vec_splatsf4(_SINCOS_CC1));
vec_float4 st1 = vec_madd(vec_splatsf4(_SINCOS_SC0),xl2,vec_splatsf4(_SINCOS_SC1));
vec_float4 ct2 = vec_madd(ct1,xl2,vec_splatsf4(_SINCOS_CC2));
vec_float4 st2 = vec_madd(st1,xl2,vec_splatsf4(_SINCOS_SC2));
vec_float4 cx = vec_madd(ct2,xl2,vec_splatsf4(1.0f));
vec_float4 sx = vec_madd(st2,xl3,xl);
// Use the cosine when the offset is odd and the sin
// when the offset is even
//
vec_uint4 mask1 = (vec_uint4)vec_cmpeq(vec_and(offset,
vec_splatsi4(0x1)),
vec_splatsi4((int)(0)));
res = vec_sel(cx,sx,mask1);
// Flip the sign of the result when (offset mod 4) = 1 or 2
//
vec_uint4 mask2 = (vec_uint4)vec_cmpeq(vec_and(offset,vec_splatsi4(0x2)),vec_splatsi4((int)0));
res = vec_sel((vec_float4)vec_xor(vec_splatsu4(0x80000000U),(vec_uint4)res),res,mask2);
return res;
}

View File

@@ -0,0 +1,53 @@
/* sqrtf4 -
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved.
Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#include <simdmath.h>
#include <altivec.h>
// sqrtf4 - for each of four float slots, compute square root.
// Undefined if input < 0.
vector float
sqrtf4 (vector float x)
{
// Reciprocal square root estimate and 1 Newton-Raphson iteration.
vector float zero = (vector float){0.0f, 0.0f, 0.0f, 0.0f};
vector float half = (vector float){0.5f, 0.5f, 0.5f, 0.5f};
vector float one = (vector float){1.0f, 1.0f, 1.0f, 1.0f};
vector float y0, y0x, y0xhalf;
vector unsigned int cmp_zero;
y0 = vec_rsqrte( x );
cmp_zero = (vector unsigned int)vec_cmpeq( x, zero );
y0x = vec_madd( y0, x, zero );
y0xhalf = vec_madd( y0x, half, zero );
return vec_sel( vec_madd( vec_nmsub( y0, y0x, one ), y0xhalf, y0x ), zero, cmp_zero );
}

View File

@@ -0,0 +1,96 @@
/* tanf4 -
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved.
Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#include <simdmath.h>
#include <altivec.h>
#include "sincos_c.h"
#include "common-types.h"
#define _TAN_KC1 1.57079625129f
#define _TAN_KC2 7.54978995489e-8f
//
// Computes the tangent of all four slots of x by using a polynomia approximation.
//
vector float
tanf4 (vector float x)
{
vector float xl,xl2,xl3,res;
vector signed int q;
// 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(x))*sign(x))
//
xl = vec_add(xl,vec_sel(vec_splatsf4(0.5f),xl,vec_splatsu4(0x80000000)));
q = vec_cts(xl,0);
// Remainder in range [-pi/4..pi/4]
//
vector float qf = vec_ctf(q,0);
vector float p1 = vec_nmsub(qf,vec_splatsf4(_SINCOS_KC1),x);
xl = vec_nmsub(qf,vec_splatsf4(_SINCOS_KC2),p1);
// 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 + x2 * (C0 * x2 + C1), and
// sx = xl + x3 * S0
//
vector float ct2 = vec_madd(vec_splatsf4( 0.0097099364f),xl2,vec_splatsf4(-0.4291161787f));
vector float cx = vec_madd(ct2,xl2,vec_splatsf4(1.0f));
vector float sx = vec_madd(vec_splatsf4(-0.0957822992f),xl3,xl);
// Compute both cx/sx and sx/cx
//
vector float cxosx = divf4(cx,sx);
vector float sxocx = divf4(sx,cx);
vector float ncxosx = (vector float)vec_xor(vec_splatsu4(0x80000000),(vector unsigned int)cxosx);
// For odd numbered quadrants return -cx/sx , otherwise return
// sx/cx
//
vector unsigned int mask = (vector unsigned int)vec_cmpeq(vec_and(q,vec_splatsi4(0x1)),vec_splatsi4(0));
res = vec_sel(ncxosx,sxocx,mask);
return res;
}

View File

@@ -0,0 +1,131 @@
# Makefile for testsuite for the PPU SIMD math library
# Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms,
# with or without modification, are permitted provided that the
# following conditions are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of the Sony Computer Entertainment Inc nor the names
# of its contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
TESTS = fabsf4 absi4 truncf4 sqrtf4 negatef4 \
copysignf4 modff4 fminf4_fmaxf4 \
floorf4 recipf4 ceilf4 divf4 divi4 \
rsqrtf4 fmodf4 negatei4
STATIC_TESTS = $(TESTS)
SHARED_TESTS = $(TESTS:=.shared)
ALL_TESTS = $(STATIC_TESTS) $(SHARED_TESTS)
INCLUDES_PPU = -I../../
ARCH_PPU = 64
CROSS_PPU = ppu-
AR_PPU = $(CROSS_PPU)ar
CC_PPU = $(CROSS_PPU)gcc
CXX_PPU = $(CROSS_PPU)g++
TEST_CMD_PPU =
ARCH_CFLAGS_PPU = -m$(ARCH_PPU) -maltivec -mabi=altivec
CFLAGS_PPU = $(INCLUDES_PPU) -O2 -W -Wall $(ARCH_CFLAGS_PPU)
STATIC_LDFLAGS_PPU = -static
SHARED_LDFLAGS_PPU = -Wl,-rpath=..
LDFLAGS_PPU = $(ARCH_CFLAGS_PPU) -L../ -l$(LIB_BASE) -lm
MAKE_DEFS = \
LIB_BASE='$(LIB_BASE)' \
LIB_NAME='$(LIB_NAME)' \
STATIC_LIB='$(STATIC_LIB)' \
SHARED_LIB='$(SHARED_LIB)' \
ARCH_PPU='$(ARCH_PPU)' \
ARCH_CFLAGS_PPU='$(ARCH_CFLAGS_PPU)' \
CROSS_PPU='$(CROSS_PPU)' \
AR_PPU='$(AR_PPU)' \
CC_PPU='$(CC_PPU)' \
CXX_PPU='$(CXX_PPU)' \
TEST_CMD_PPU='$(TEST_CMD_PPU)'
LIB_BASE = simdmath
LIB_NAME = lib$(LIB_BASE)
STATIC_LIB = $(LIB_NAME).a
SHARED_LIB = $(LIB_NAME).so
TEST_CMD = $(TEST_CMD_PPU)
COMMON_OBJS = testutils.o
all: $(ALL_TESTS)
$(STATIC_TESTS): %: %.o ../$(STATIC_LIB) $(COMMON_OBJS)
$(CC_PPU) $*.o $(COMMON_OBJS) $(LDFLAGS_PPU) $(STATIC_LDFLAGS_PPU) -o $@
$(SHARED_TESTS): %.shared: %.o ../$(SHARED_LIB) $(COMMON_OBJS)
$(CC_PPU) $*.o $(COMMON_OBJS) $(LDFLAGS_PPU) $(SHARED_LDFLAGS_PPU) -o $@
clean:
rm -f *.o
rm -f $(STATIC_TESTS) $(SHARED_TESTS)
rm -f core*
check: $(ALL_TESTS)
for test in $(ALL_TESTS); do \
echo "TEST $${test}"; \
if $(TEST_CMD) ./$${test}; then \
pass="$$pass $$test"; \
else \
fail="$$fail $$test"; \
fi \
done; \
echo; echo "PASS:$$pass"; echo "FAIL:$$fail"; \
test -z "$$fail"
static_check:
$(MAKE) $(MAKE_DEFS) ALL_TESTS="$(STATIC_TESTS)" check
shared_check:
$(MAKE) $(MAKE_DEFS) ALL_TESTS="$(SHARED_TESTS)" check
../$(STATIC_LIB):
cd ../;$(MAKE) $(MAKE_DEFS) $(STATIC_LIB)
../$(SHARED_LIB):
cd ../;$(MAKE) $(MAKE_DEFS) $(SHARED_LIB)
%.o: %.c common-test.h testutils.h
$(CC_PPU) $(CFLAGS_PPU) -c $<
#----------
# C++
#----------
%.o: %.C
$(CXX_PPU) $(CFLAGS_PPU) -c $<
%.o: %.cpp
$(CXX_PPU) $(CFLAGS_PPU) -c $<
%.o: %.cc
$(CXX_PPU) $(CFLAGS_PPU) -c $<
%.o: %.cxx
$(CXX_PPU) $(CFLAGS_PPU) -c $<

View File

@@ -0,0 +1,73 @@
/* Testcase for absi4
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved.
Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "common-test.h"
#include "testutils.h"
#include "simdmath.h"
int main()
{
TEST_SET_START("20040908101807EJL","EJL", "abs");
int x0n = hide_int(0);
int x0p = hide_int(0);
int x1n = hide_int(-1);
int x1p = hide_int(1);
int x2n = hide_int(-83532);
int x2p = hide_int(83532);
vec_int4 x0n_v = vec_splat_int(x0n);
vec_int4 x0p_v = vec_splat_int(x0p);
vec_int4 x1n_v = vec_splat_int(x1n);
vec_int4 x1p_v = vec_splat_int(x1p);
vec_int4 x2n_v = vec_splat_int(x2n);
vec_int4 x2p_v = vec_splat_int(x2p);
vec_int4 res_v;
TEST_START("absi4");
res_v = absi4(x0n_v);
TEST_CHECK("20040908103824EJL", allequal_int4( res_v, x0p_v ), 0);
res_v = absi4(x0p_v);
TEST_CHECK("20040908103903EJL", allequal_int4( res_v, x0p_v ), 0);
res_v = absi4(x1n_v);
TEST_CHECK("20040908103905EJL", allequal_int4( res_v, x1p_v ), 0);
res_v = absi4(x1p_v);
TEST_CHECK("20040908114003EJL", allequal_int4( res_v, x1p_v ), 0);
res_v = absi4(x2n_v);
TEST_CHECK("20040908114714EJL", allequal_int4( res_v, x2p_v ), 0);
res_v = absi4(x2p_v);
TEST_CHECK("20040908114715EJL", allequal_int4( res_v, x2p_v ), 0);
TEST_SET_DONE();
TEST_EXIT();
}

View File

@@ -0,0 +1,92 @@
/* Testcase for ceilf4
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved.
Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "common-test.h"
#include "testutils.h"
#include "simdmath.h"
int main()
{
TEST_SET_START("20040916103300EJL","EJL", "ceilf");
unsigned int i3 = 0x4affffff; // 2^23 - 0.5, largest truncatable value.
unsigned int i3i = 0x4b000000;
unsigned int i4 = 0x4b000000; // 2^23, no fractional part.
unsigned int i5 = 0xcf000001; // -2^31, one more large, and negative, value.
float x0 = hide_float(0.91825f);
float x0i = hide_float(1.0f);
float x1 = hide_float(-0.12958f);
float x1i = hide_float(0.0f);
float x2 = hide_float(-79615.1875f);
float x2i = hide_float(-79615.0f);
float x3 = hide_float(make_float(i3));
float x3i = hide_float(make_float(i3i));
float x4 = hide_float(make_float(i4));
float x4i = hide_float(make_float(i4));
float x5 = hide_float(make_float(i5));
float x5i = hide_float(make_float(i5));
vec_float4 x0_v = vec_splat_float(x0);
vec_float4 x0i_v = vec_splat_float(x0i);
vec_float4 x1_v = vec_splat_float(x1);
vec_float4 x1i_v = vec_splat_float(x1i);
vec_float4 x2_v = vec_splat_float(x2);
vec_float4 x2i_v = vec_splat_float(x2i);
vec_float4 x3_v = vec_splat_float(x3);
vec_float4 x3i_v = vec_splat_float(x3i);
vec_float4 x4_v = vec_splat_float(x4);
vec_float4 x4i_v = vec_splat_float(x4i);
vec_float4 x5_v = vec_splat_float(x5);
vec_float4 x5i_v = vec_splat_float(x5i);
vec_float4 res_v;
TEST_START("ceilf4");
res_v = ceilf4(x0_v);
TEST_CHECK("20040916103310EJL", allequal_float4( res_v, x0i_v ), 0);
res_v = ceilf4(x1_v);
TEST_CHECK("20040916103324EJL", allequal_float4( res_v, x1i_v ), 0);
res_v = ceilf4(x2_v);
TEST_CHECK("20040916103334EJL", allequal_float4( res_v, x2i_v ), 0);
res_v = ceilf4(x3_v);
TEST_CHECK("20040916103341EJL", allequal_float4( res_v, x3i_v ), 0);
res_v = ceilf4(x4_v);
TEST_CHECK("20040916103350EJL", allequal_float4( res_v, x4i_v ), 0);
res_v = ceilf4(x5_v);
TEST_CHECK("20040916103357EJL", allequal_float4( res_v, x5i_v ), 0);
TEST_SET_DONE();
TEST_EXIT();
}

View File

@@ -0,0 +1,198 @@
/* Header file for common parts of the testsuite
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved.
Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
static inline unsigned long long clock()
{
unsigned long long ret;
/* This need to be fixed for the hardware errata. */
__asm __volatile__ ( "mftb %0\n"
: "=r" (ret)
:
: "memory");
return (ret);
}
// Test files begin with TEST_SET_START("your initials","test set description")
// Individual tests begin with TEST_START("name of test")
// and end with TEST_PASS(), TEST_FAIL("reason for failure") or TEST_CHECK(<test to evaluate>)
// Or you can run a test encapsulated in a function with:
// TEST_FUNCTION("name of test", function(), "reason for failure")
//
// The clock starts when you call TEST_START and stops with TEST_PASS, TEST_FAIL or TEST_CHECK
// After a start there can be several PASS, FAIL or CHECK calls, each one counts as a test, time is measured from the prior call
//
char
*__initials, // Test owner's initials
*__description, // short descriptive name for this test set
*__name, // name of the currently running test
*__set_id; // id of the the test set
int
// __zip=0,
__success=1, // set to 0 if any tests failed
__count, // Total number of tests run
__passed; // Total number of tests passed
unsigned long long
__ttemp,
__time, // For timing tests (usually start time of last test)
__ttime; // Cumulative test runtime NOT counting runtime of the TEST macros
// TEST_SET_START
// Call at the start of a set of related tests to identify them
// Prints a "start of set banner message"
// set_id - unique test set identifyer a time in the format yyyymmddhhmmss followed by your initials ie: 20040716104615GAC
// initials - your initials
// description - brief descriptive name for this test set
#define TEST_SET_START(set_id,initials,description) \
do { \
__set_id=set_id; \
__initials=initials; \
__description=description; \
__count=0; \
__passed=0; \
__time=0; \
__ttime=0; \
printf("0\t%s\t%d\t%s\tSTART\tpassed\ttotal\ttime\t%s\tunique test id \t%s\n",__FILE__,__LINE__,__initials,__set_id, __description); \
} while(0)
// TEST_START
// Begins a test, and starts the clock
// name - brief name for this test
#define TEST_START(name) \
do { \
__asm __volatile__ ( "mftb %0 \n" : "=r" (__time) :: "memory"); \
__name=name; \
__asm __volatile__ ( "mftb %0 \n" : "=r" (__time) :: "memory"); \
} while(0)
// TEST_PASS
// Indicates the test passed
// test_id - unique test ID number, same format as the set_id number
// This should match the id provided to the matching TEST_FAIL call
#define TEST_PASS(test_id) \
do { \
__asm __volatile__ ( "mftb %0 \n" : "=r" (__ttemp) :: "memory"); \
__time=__ttemp-__time; \
__ttime+=__time; \
__count++; \
__passed++; \
printf("1\t%s\t%d\t%s\tPASS\t%d\t%d\t%lld\t%s\t%s\t%s\n",__FILE__,__LINE__,__initials,__passed,__count,__time,__set_id,test_id,__name); \
__asm __volatile__ ( "mftb %0 \n" : "=r" (__time) :: "memory"); \
} while(0)
// TEST_FAIL
// Indicates the test failed
// test_id - unique test ID number, same format as the set_id number
// This should match the id provided to the matching TEST_PASS call
// why - brief description of why it failed
#define TEST_FAIL(test_id,why,error_code) \
do { \
__asm __volatile__ ( "mftb %0 \n" : "=r" (__ttemp) :: "memory"); \
__time=__ttemp-__time; \
__ttime+=__time; \
__count++; \
__success=0; \
printf("1\t%s\t%d\t%s\tFAIL\t%d\t%d\t%lld\t%s\t%s\t%s\tFAILED BECAUSE: %s\t%d\n",__FILE__,__LINE__,__initials,__passed,__count,__time,__set_id,test_id,__name,why,error_code); \
__asm __volatile__ ( "mftb %0 \n" : "=r" (__time) :: "memory"); \
} while(0)
// TEST_CHECK
// Passes or fails the test after evaluating the "test" argument (just like assert but without terminating the program)
// The clock is immediately stopped so the time required to evaluate "test" will NOT be included in the reported time
// If the test failed, the reason will be printed as FAILED BECAUSE: check (value of "test") failed
// test_id - unique test ID number, same format as the set_id number
// test - expression evaluating to true/false
#define TEST_CHECK(test_id,test,error_code) \
do { \
__asm __volatile__ ( "mftb %0 \n" : "=r" (__ttemp) :: "memory"); \
__time=__ttemp-__time; \
__ttime+=__time; \
__count++; \
if(test) \
{ \
__passed++; \
printf("1\t%s\t%d\t%s\tPASS\t%d\t%d\t%lld\t%s\t%s\t%s\n",__FILE__,__LINE__,__initials,__passed,__count,__time,__set_id,test_id,__name); \
} \
else \
{ \
__success=0; \
printf("1\t%s\t%d\t%s\tFAIL\t%d\t%d\t%lld\t%s\t%s\t%s\tFAILED BECAUSE: check %s failed\t%d\n",__FILE__,__LINE__,__initials,__passed,__count,__time,__set_id,test_id,__name,#test,error_code); \
} \
__asm __volatile__ ( "mftb %0 \n" : "=r" (__time) :: "memory"); \
} while(0)
// TEST_FUNCTION
// Runs a test encapsulated in a function that returns 0 if the test passed and an error number if it failed
// The clock is started on calling the function and stopped as soon as it returns so the branching logic will not be included in the time
// test_id - unique test ID number, same format as the set_id number
// name - brief name for the test
// func - function invocation (should include parenthesis, may have arguments)
// why - brief description to print if the test fails
#define TEST_FUNCTION(test_id,name,func,why) \
do { \
TEST_START(name); \
int result=func; \
__asm __volatile__ ( "mftb %0 \n" : "=r" (__ttemp) :: "memory"); \
__time=__ttemp-__time; \
__ttime+=__time; \
__count++; \
if(result==0) \
{ \
__passed++; \
printf("1\t%s\t%d\t%s\tPASS\t%d\t%d\t%d\t%s\t%s\t%s\n",__FILE__,__LINE__,__initials,__passed,__count,__time,__set_id,test_id,__name); \
} \
else \
{ \
__success=0; \
printf("1\t%s\t%d\t%s\tFAIL\t%d\t%d\t%d\t%s\t%s\t%s\tFAILED BECAUSE: %s\t%d\n",__FILE__,__LINE__,__initials,__passed,__count,__time,__set_id,test_id,__name,why,result); \
} \
__asm __volatile__ ( "mftb %0 \n" : "=r" (__time) :: "memory"); \
} while(0)
// TEST_SET_DONE
// Ends a set of tests, prints out the closing banner (OK if all tests pass, PROBLEM if any fail)
// Also prints count of tests passed, tests run and total time
#define TEST_SET_DONE() \
do { \
printf("9\t%s\t%d\t%s\t%s\t%d\t%d\t%lld\t%s\tunique test id \t%s\n",__FILE__,__LINE__,__initials,(__count==__passed)?"OK":"PROBLEM",__passed,__count,__ttime,__set_id,__description); \
} while(0)
// TEST_EXIT
// Call this ONCE at the very end of the test program, it calls "exit" to return
// EXIT_SUCCESS if all tests passed or EXIT_FAILURE if any tests failed.
// This allows the makefile/shell script running the tests to know which ones failed
#define TEST_EXIT() \
do { \
printf("FINISHED!\n"); \
if(__success) \
exit(0); \
else \
exit(-1); \
} while (0)

View File

@@ -0,0 +1,67 @@
/* Testcase for copysignf4
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved.
Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "common-test.h"
#include "testutils.h"
#include "simdmath.h"
int main()
{
TEST_SET_START("20040917114054EJL", "EJL", "copysignf");
float x0m = hide_float(1989.0f);
float x0s = hide_float(-319875.0f);
float x0c = hide_float(-1989.0f);
float x1m = hide_float(9013.0f);
float x1s = hide_float(185.0f);
float x1c = hide_float(9013.0f);
vec_float4 x0m_v = vec_splat_float(x0m);
vec_float4 x0s_v = vec_splat_float(x0s);
vec_float4 x0c_v = vec_splat_float(x0c);
vec_float4 x1m_v = vec_splat_float(x1m);
vec_float4 x1s_v = vec_splat_float(x1s);
vec_float4 x1c_v = vec_splat_float(x1c);
vec_float4 res_v;
TEST_START("copysignf4");
res_v = copysignf4( x0m_v, x0s_v );
TEST_CHECK("20040917114058EJL", allequal_float4( res_v, x0c_v ), 0);
res_v = copysignf4( x1m_v, x1s_v );
TEST_CHECK("20040917114100EJL", allequal_float4( res_v, x1c_v ), 0);
TEST_SET_DONE();
TEST_EXIT();
}

View File

@@ -0,0 +1,128 @@
/* Testcase for divf4
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved.
Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "common-test.h"
#include "testutils.h"
#include "simdmath.h"
int main()
{
TEST_SET_START("20040928105926EJL","EJL", "divf4");
unsigned int i0n = 0x75013340;
unsigned int i0d = 0x75e7753f;
unsigned int i0r = 0x3e8ee64b;
unsigned int i1n = 0x4c7fed5a;
unsigned int i1d = 0x3a0731f0;
unsigned int i1r = 0x51f24e86;
unsigned int i2n = 0x5b08b303;
unsigned int i2d = 0x562f5046;
unsigned int i2r = 0x44479d24;
unsigned int i3n = 0x748a9b87;
unsigned int i3d = 0x6b014b46;
unsigned int i3r = 0x49093864;
unsigned int i4n = 0x35dcf9d8;
unsigned int i4d = 0x6278d6e0;
unsigned int i4r = 0x12e355b5;
unsigned int i5n = 0x74d505fd;
unsigned int i5d = 0x61ef565e;
unsigned int i5r = 0x5263daa3;
float x0n = hide_float(make_float(i0n));
float x0d = hide_float(make_float(i0d));
float x0r = hide_float(make_float(i0r));
float x1n = hide_float(make_float(i1n));
float x1d = hide_float(make_float(i1d));
float x1r = hide_float(make_float(i1r));
float x2n = hide_float(make_float(i2n));
float x2d = hide_float(make_float(i2d));
float x2r = hide_float(make_float(i2r));
float x3n = hide_float(make_float(i3n));
float x3d = hide_float(make_float(i3d));
float x3r = hide_float(make_float(i3r));
float x4n = hide_float(make_float(i4n));
float x4d = hide_float(make_float(i4d));
float x4r = hide_float(make_float(i4r));
float x5n = hide_float(make_float(i5n));
float x5d = hide_float(make_float(i5d));
float x5r = hide_float(make_float(i5r));
vec_float4 x0n_v = vec_splat_float(x0n);
vec_float4 x0d_v = vec_splat_float(x0d);
vec_float4 x0r_v = vec_splat_float(x0r);
vec_float4 x1n_v = vec_splat_float(x1n);
vec_float4 x1d_v = vec_splat_float(x1d);
vec_float4 x1r_v = vec_splat_float(x1r);
vec_float4 x2n_v = vec_splat_float(x2n);
vec_float4 x2d_v = vec_splat_float(x2d);
vec_float4 x2r_v = vec_splat_float(x2r);
vec_float4 x3n_v = vec_splat_float(x3n);
vec_float4 x3d_v = vec_splat_float(x3d);
vec_float4 x3r_v = vec_splat_float(x3r);
vec_float4 x4n_v = vec_splat_float(x4n);
vec_float4 x4d_v = vec_splat_float(x4d);
vec_float4 x4r_v = vec_splat_float(x4r);
vec_float4 x5n_v = vec_splat_float(x5n);
vec_float4 x5d_v = vec_splat_float(x5d);
vec_float4 x5r_v = vec_splat_float(x5r);
vec_float4 res_v;
TEST_START("divf4");
res_v = divf4(x0n_v, x0d_v);
TEST_CHECK("20040928105932EJL", allequal_ulps_float4( res_v, x0r_v, 2 ), 0);
res_v = divf4(x1n_v, x1d_v);
TEST_CHECK("20040928105934EJL", allequal_ulps_float4( res_v, x1r_v, 2 ), 0);
res_v = divf4(x2n_v, x2d_v);
TEST_CHECK("20040928105936EJL", allequal_ulps_float4( res_v, x2r_v, 2 ), 0);
res_v = divf4(x3n_v, x3d_v);
TEST_CHECK("20040928105938EJL", allequal_ulps_float4( res_v, x3r_v, 2 ), 0);
res_v = divf4(x4n_v, x4d_v);
TEST_CHECK("20040928105940EJL", allequal_ulps_float4( res_v, x4r_v, 2 ), 0);
res_v = divf4(x5n_v, x5d_v);
TEST_CHECK("20040928105943EJL", allequal_ulps_float4( res_v, x5r_v, 2 ), 0);
TEST_SET_DONE();
TEST_EXIT();
}

View File

@@ -0,0 +1,124 @@
/* Testcase for divi4
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved.
Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "common-test.h"
#include "testutils.h"
#include "simdmath.h"
int main()
{
TEST_SET_START("20040928161739EJL","EJL", "divi4");
int x0n = 0xffccb78d;
int x0d = 0x0 ;
int x0q = 0x0 ;
int x0r = 0xffccb78d;
int x1n = 0x0;
int x1d = 0xff976bb6;
int x1q = 0x0 ;
int x1r = 0x0;
int x2n = 0x0;
int x2d = 0x0;
int x2q = 0x0 ;
int x2r = 0x0;
int x3n = 0xf0e91618;
int x3d = 0xfddff7ac;
int x3q = 0x7 ;
int x3r = 0xffc95064;
int x4n = 0xf2128d9d;
int x4d = 0xe0f76 ;
int x4q = 0xffffff03;
int x4r = 0xfff7d53b;
int x5n = 0xda1ba2ce;
int x5d = 0x4c9 ;
int x5q = 0xfff814d3;
int x5r = 0xfffffd23;
int x6n = 0xdd4426a6;
int x6d = 0xf8d245cf;
int x6q = 0x4 ;
int x6r = 0xf9fb0f6a;
int x7n = 0xd1d5ae9 ;
int x7d = 0x333ab105;
int x7q = 0x0 ;
int x7r = 0xd1d5ae9 ;
int x8n = 0x3e0c6 ;
int x8d = 0xfff24255;
int x8q = 0x0 ;
int x8r = 0x3e0c6 ;
int x9n = 0xfd6fe27e;
int x9d = 0xf32454 ;
int x9q = 0xfffffffe;
int x9r = 0xff562b26;
int x10n =0xfb150f79;
int x10d =0xf521 ;
int x10q =0xfffffade;
int x10r =0xffff42db;
int x11n =0xfe88071f;
int x11d =0xfff937c2;
int x11q =0x37 ;
int x11r =0xfffd0c71;
vec_int4 x0n_v = (vec_int4){ x0n, x1n, x2n, x3n };
vec_int4 x1n_v = (vec_int4){ x4n, x5n, x6n, x7n };
vec_int4 x2n_v = (vec_int4){ x8n, x9n, x10n, x11n };
vec_int4 x0d_v = (vec_int4){ x0d, x1d, x2d, x3d };
vec_int4 x1d_v = (vec_int4){ x4d, x5d, x6d, x7d };
vec_int4 x2d_v = (vec_int4){ x8d, x9d, x10d, x11d };
vec_int4 x0q_v = (vec_int4){ x0q, x1q, x2q, x3q };
vec_int4 x1q_v = (vec_int4){ x4q, x5q, x6q, x7q };
vec_int4 x2q_v = (vec_int4){ x8q, x9q, x10q, x11q };
vec_int4 x0r_v = (vec_int4){ x0r, x1r, x2r, x3r };
vec_int4 x1r_v = (vec_int4){ x4r, x5r, x6r, x7r };
vec_int4 x2r_v = (vec_int4){ x8r, x9r, x10r, x11r };
divi4_t res;
TEST_START("divi4");
res = divi4(x0n_v, x0d_v);
TEST_CHECK("20040928161846EJL", allequal_int4( res.quot, x0q_v ) && allequal_int4( res.rem, x0r_v ), 0);
res = divi4(x1n_v, x1d_v);
TEST_CHECK("20040928161851EJL", allequal_int4( res.quot, x1q_v ) && allequal_int4( res.rem, x1r_v ), 0);
res = divi4(x2n_v, x2d_v);
TEST_CHECK("20040928161855EJL", allequal_int4( res.quot, x2q_v ) && allequal_int4( res.rem, x2r_v ), 0);
TEST_SET_DONE();
TEST_EXIT();
}

View File

@@ -0,0 +1,85 @@
/* Testcase for fabsf4
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved.
Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "common-test.h"
#include "testutils.h"
#include "simdmath.h"
int main()
{
TEST_SET_START("20040915032605EJL","EJL", "fabsf");
unsigned int i3n = 0xff000000;
unsigned int i3p = 0x7f000000;
float x0n = hide_float(-0.0f);
float x0p = hide_float(0.0f);
float x1n = hide_float(-83532.96153153f);
float x1p = hide_float(83532.96153153f);
float x2n = hide_float(-0.0000000013152f);
float x2p = hide_float(0.0000000013152f);
float x3n = hide_float(make_float(i3n));
float x3p = hide_float(make_float(i3p));
vec_float4 x0n_v = vec_splat_float(x0n);
vec_float4 x0p_v = vec_splat_float(x0p);
vec_float4 x1n_v = vec_splat_float(x1n);
vec_float4 x1p_v = vec_splat_float(x1p);
vec_float4 x2n_v = vec_splat_float(x2n);
vec_float4 x2p_v = vec_splat_float(x2p);
vec_float4 x3n_v = vec_splat_float(x3n);
vec_float4 x3p_v = vec_splat_float(x3p);
vec_float4 res_v;
TEST_START("fabsf4");
res_v = fabsf4(x0n_v);
TEST_CHECK("20040915032618EJL", allequal_float4( res_v, x0p_v ), 0);
res_v = fabsf4(x0p_v);
TEST_CHECK("20040915032632EJL", allequal_float4( res_v, x0p_v ), 0);
res_v = fabsf4(x1n_v);
TEST_CHECK("20040915032643EJL", allequal_float4( res_v, x1p_v ), 0);
res_v = fabsf4(x1p_v);
TEST_CHECK("20040915032654EJL", allequal_float4( res_v, x1p_v ), 0);
res_v = fabsf4(x2n_v);
TEST_CHECK("20040915032704EJL", allequal_float4( res_v, x2p_v ), 0);
res_v = fabsf4(x2p_v);
TEST_CHECK("20040915032712EJL", allequal_float4( res_v, x2p_v ), 0);
res_v = fabsf4(x3n_v);
TEST_CHECK("20040915032719EJL", allequal_float4( res_v, x3p_v ), 0);
res_v = fabsf4(x3p_v);
TEST_CHECK("20040915032729EJL", allequal_float4( res_v, x3p_v ), 0);
TEST_SET_DONE();
TEST_EXIT();
}

View File

@@ -0,0 +1,189 @@
/* Header file for common parts of the testsuite
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved.
Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _FLOATINGPOINT_TESTS_H_
#define _FLOATINGPOINT_TESTS_H_
#if defined(__PPC__)
#include <altivec.h>
#define vec_uchar16 vector unsigned char
#define vec_char16 vector signed char
#define vec_ushort8 vector unsigned short
#define vec_short8 vector signed short
#define vec_uint4 vector unsigned int
#define vec_int4 vector signed int
#define vec_ullong2 vector unsigned long long
#define vec_llong2 vector signed long long
#define vec_float4 vector float
#define vec_double2 vector double
#else
#if __SPU__
#include <spu_intrinsics.h>
#endif
#endif
// To avoid type punning warnings (for printing in hex notation, doing bit-diff etc)
typedef union {
double d;
unsigned char uc[8];
unsigned int ui[2];
unsigned long long int ull;
} sce_math_alt_double;
typedef union {
float f;
unsigned char uc[4];
unsigned int ui;
} sce_math_alt_float;
#if (__PPC__ || __SPU__)
typedef union {
vec_int4 vsi;
int si[4];
} sce_math_alt_vec_int4;
typedef union {
vec_uint4 vui;
int ui[4];
} sce_math_alt_vec_uint4;
typedef union {
vec_float4 vf;
float sf[4];
unsigned int ui[4];
} sce_math_alt_vec_float4;
#endif
#if __SPU__
typedef union {
double sd[2];
vec_double2 vd;
unsigned long long int ui[2];
} sce_math_alt_vec_double2;
#endif
#if __PPC__
inline vec_int4 bitdiff4(vec_float4 ref, vec_float4 vals) {
vec_int4 refi = (vec_int4)ref;
vec_int4 valsi = (vec_int4)vals;
vec_int4 diff = vec_sub(refi, valsi);
vec_int4 negdiff = vec_sub(((vec_int4){0,0,0,0}), diff);
return vec_sel(negdiff, diff, vec_cmpgt(diff, ((vec_int4){0,0,0,0}) ));
}
inline int bitdiff(float ref, float val) {
sce_math_alt_float aref, aval;
aref.f = ref;
aval.f = val;
int diff = aref.ui - aval.ui;
return (diff>0)?diff:-diff;
}
inline vec_int4 bitmatch4(vec_float4 ref, vec_float4 vals) {
vec_int4 refi = (vec_int4)ref;
vec_int4 valsi = (vec_int4)vals;
vec_int4 diff = vec_sub(refi, valsi);
vec_int4 negdiff = vec_sub(((vec_int4){0,0,0,0}), diff);
diff = vec_sel(negdiff, diff, vec_cmpgt(diff, ((vec_int4){0,0,0,0}) ));
vec_float4 logdiff = vec_loge(vec_ctf(diff,0));
return vec_sub(((vec_int4){32,32,32,32}), vec_cts(vec_ceil(logdiff),0));
}
inline int bitmatch(float ref, float val) {
sce_math_alt_vec_float4 aref, aval;
sce_math_alt_vec_int4 adiff;
aref.sf[0] = ref;
aval.sf[0] = val;
adiff.vsi = bitmatch4(aref.vf, aval.vf);
return adiff.si[0];
}
inline float extractFloat(vec_float4 vf, int index)
{
sce_math_alt_vec_float4 vec;
vec.vf = vf;
return vec.sf[index];
}
inline int extractInt(vec_int4 vi, int index)
{
sce_math_alt_vec_int4 vec;
vec.vsi = vi;
return vec.si[index];
}
inline int extractUInt(vec_uint4 vi, int index)
{
sce_math_alt_vec_uint4 vec;
vec.vui = vi;
return vec.ui[index];
}
#else
#if __SPU__
inline vec_int4 bitdiff4(vec_float4 ref, vec_float4 vals) {
vec_int4 refi = (vec_int4)ref;
vec_int4 valsi = (vec_int4)vals;
vec_int4 diff = spu_sub(refi, valsi);
vec_int4 negdiff = spu_sub(spu_splats((int)0), diff);
return spu_sel(negdiff, diff, (vec_uchar16)spu_cmpgt(diff, 0));
}
inline int bitdiff(float ref, float val) {
return spu_extract(bitdiff4(spu_promote(ref,0), spu_promote(val,0)), 0);
}
inline vec_int4 bitmatch4(vec_float4 ref, vec_float4 vals) {
vec_int4 refi = (vec_int4)ref;
vec_int4 valsi = (vec_int4)vals;
vec_int4 diff = spu_sub(refi, valsi);
vec_int4 negdiff = spu_sub(spu_splats((int)0), diff);
return (vec_int4)spu_cntlz(spu_sel(negdiff, diff, (vec_uchar16)spu_cmpgt(diff, 0)));
}
inline int bitmatch(float ref, float val) {
return spu_extract(bitmatch4(spu_promote(ref,0), spu_promote(val,0)), 0);
}
#else
inline int bitdiff(sce_math_alt_float ref, sce_math_alt_float val) {
int diff = ref.ui - val.ui;
return((diff>0)?diff:-diff);
}
inline int bitmatch(sce_math_alt_float ref, sce_math_alt_float val) {
int diff, i;
unsigned int udiff;
diff = ref.ui - val.ui;
udiff = (diff>0) ? diff : -diff;
i = 32;
while(udiff != 0) {
i = i-1;
udiff = udiff >> 1;
}
return udiff;
}
#endif // __SPU__
#endif // __PPC__
#endif // _FLOATINGPOINT_TESTS_H_

View File

@@ -0,0 +1,92 @@
/* Testcase for floorf4
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved.
Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "common-test.h"
#include "testutils.h"
#include "simdmath.h"
int main()
{
TEST_SET_START("20040916145017EJL","EJL", "floorf");
unsigned int i3 = 0x4affffff; // 2^23 - 0.5, largest truncatable value.
unsigned int i3i = 0x4afffffe;
unsigned int i4 = 0x4b000000; // 2^23, no fractional part.
unsigned int i5 = 0xcf000001; // -2^31, one more large, and negative, value.
float x0 = hide_float(0.91825f);
float x0i = hide_float(0.0f);
float x1 = hide_float(-0.12958f);
float x1i = hide_float(-1.0f);
float x2 = hide_float(-79615.1875f);
float x2i = hide_float(-79616.0f);
float x3 = hide_float(make_float(i3));
float x3i = hide_float(make_float(i3i));
float x4 = hide_float(make_float(i4));
float x4i = hide_float(make_float(i4));
float x5 = hide_float(make_float(i5));
float x5i = hide_float(make_float(i5));
vec_float4 x0_v = vec_splat_float(x0);
vec_float4 x0i_v = vec_splat_float(x0i);
vec_float4 x1_v = vec_splat_float(x1);
vec_float4 x1i_v = vec_splat_float(x1i);
vec_float4 x2_v = vec_splat_float(x2);
vec_float4 x2i_v = vec_splat_float(x2i);
vec_float4 x3_v = vec_splat_float(x3);
vec_float4 x3i_v = vec_splat_float(x3i);
vec_float4 x4_v = vec_splat_float(x4);
vec_float4 x4i_v = vec_splat_float(x4i);
vec_float4 x5_v = vec_splat_float(x5);
vec_float4 x5i_v = vec_splat_float(x5i);
vec_float4 res_v;
TEST_START("floorf4");
res_v = floorf4(x0_v);
TEST_CHECK("20040916145022EJL", allequal_float4( res_v, x0i_v ), 0);
res_v = floorf4(x1_v);
TEST_CHECK("20040916145024EJL", allequal_float4( res_v, x1i_v ), 0);
res_v = floorf4(x2_v);
TEST_CHECK("20040916145027EJL", allequal_float4( res_v, x2i_v ), 0);
res_v = floorf4(x3_v);
TEST_CHECK("20040916145029EJL", allequal_float4( res_v, x3i_v ), 0);
res_v = floorf4(x4_v);
TEST_CHECK("20040916145032EJL", allequal_float4( res_v, x4i_v ), 0);
res_v = floorf4(x5_v);
TEST_CHECK("20040916145034EJL", allequal_float4( res_v, x5i_v ), 0);
TEST_SET_DONE();
TEST_EXIT();
}

View File

@@ -0,0 +1,91 @@
/* Testcase for fminf4 and fmaxf4
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved.
Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdlib.h>
#include <math.h>
#include "common-test.h"
#include "testutils.h"
#include "simdmath.h"
int main()
{
TEST_SET_START("20040928184342EJL","EJL", "fminf4_fmaxf4");
float x0min = hide_float(1760.135f);
float x0max = hide_float(19355.03f);
float x1min = hide_float(-12351.9f);
float x1max = hide_float(-139.035f);
float x2min = hide_float(-1.0);
float x2max = hide_float(0.0);
vec_float4 x0min_v = vec_splat_float(x0min);
vec_float4 x0max_v = vec_splat_float(x0max);
vec_float4 x1min_v = vec_splat_float(x1min);
vec_float4 x1max_v = vec_splat_float(x1max);
vec_float4 x2min_v = vec_splat_float(x2min);
vec_float4 x2max_v = vec_splat_float(x2max);
vec_float4 res_v;
TEST_START("fminf4");
res_v = fminf4(x0min_v, x0max_v);
TEST_CHECK("20040928184345EJL", allequal_float4( res_v, x0min_v ), 0);
res_v = fminf4(x0max_v, x0min_v);
TEST_CHECK("20040928184349EJL", allequal_float4( res_v, x0min_v ), 0);
res_v = fminf4(x1min_v, x1max_v);
TEST_CHECK("20040928184351EJL", allequal_float4( res_v, x1min_v ), 0);
res_v = fminf4(x1max_v, x1min_v);
TEST_CHECK("20040928184353EJL", allequal_float4( res_v, x1min_v ), 0);
res_v = fminf4(x2min_v, x2max_v);
TEST_CHECK("20040928184354EJL", allequal_float4( res_v, x2min_v ), 0);
res_v = fminf4(x2max_v, x2min_v);
TEST_CHECK("20040928184356EJL", allequal_float4( res_v, x2min_v ), 0);
TEST_START("fmaxf4");
res_v = fmaxf4(x0min_v, x0max_v);
TEST_CHECK("20040928184411EJL", allequal_float4( res_v, x0max_v ), 0);
res_v = fmaxf4(x0max_v, x0min_v);
TEST_CHECK("20040928184413EJL", allequal_float4( res_v, x0max_v ), 0);
res_v = fmaxf4(x1min_v, x1max_v);
TEST_CHECK("20040928184415EJL", allequal_float4( res_v, x1max_v ), 0);
res_v = fmaxf4(x1max_v, x1min_v);
TEST_CHECK("20040928184416EJL", allequal_float4( res_v, x1max_v ), 0);
res_v = fmaxf4(x2min_v, x2max_v);
TEST_CHECK("20040928184417EJL", allequal_float4( res_v, x2max_v ), 0);
res_v = fmaxf4(x2max_v, x2min_v);
TEST_CHECK("20040928184419EJL", allequal_float4( res_v, x2max_v ), 0);
TEST_SET_DONE();
TEST_EXIT();
}

View File

@@ -0,0 +1,129 @@
/* Testcase for fmodf4
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved.
Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "common-test.h"
#include "testutils.h"
#include "simdmath.h"
int main()
{
TEST_SET_START("20040928191240EJL","EJL", "fmodf4");
unsigned int i0n = 0x449edbc6;
unsigned int i0d = 0x40cf799d;
unsigned int i0r = 0x3daa7300;
unsigned int i1n = 0x6bca107a;
unsigned int i1d = 0x6c4a107a;
unsigned int i1r = 0x6bca107a;
unsigned int i2n = 0x1c123605;
unsigned int i2d = 0x1c923602;
unsigned int i2r = 0x1c123605;
unsigned int i3n = 0x2b4c50fa;
unsigned int i3d = 0x253a3ae3;
unsigned int i3r = 0x25141df9;
unsigned int i4n = 0x73addffc;
unsigned int i4d = 0x742ddffc;
unsigned int i4r = 0x73addffc;
unsigned int i5n = 0x29d4d97c;
unsigned int i5d = 0x2a546e77;
unsigned int i5r = 0x29d4d97c;
float x0n = hide_float(make_float(i0n));
float x0d = hide_float(make_float(i0d));
float x0r = hide_float(make_float(i0r));
float x1n = hide_float(make_float(i1n));
float x1d = hide_float(make_float(i1d));
float x1r = hide_float(make_float(i1r));
float x2n = hide_float(make_float(i2n));
float x2d = hide_float(make_float(i2d));
float x2r = hide_float(make_float(i2r));
float x3n = hide_float(make_float(i3n));
float x3d = hide_float(make_float(i3d));
float x3r = hide_float(make_float(i3r));
float x4n = hide_float(make_float(i4n));
float x4d = hide_float(make_float(i4d));
float x4r = hide_float(make_float(i4r));
float x5n = hide_float(make_float(i5n));
float x5d = hide_float(make_float(i5d));
float x5r = hide_float(make_float(i5r));
vec_float4 x0n_v = vec_splat_float(x0n);
vec_float4 x0d_v = vec_splat_float(x0d);
vec_float4 x0r_v = vec_splat_float(x0r);
vec_float4 x1n_v = vec_splat_float(x1n);
vec_float4 x1d_v = vec_splat_float(x1d);
vec_float4 x1r_v = vec_splat_float(x1r);
vec_float4 x2n_v = vec_splat_float(x2n);
vec_float4 x2d_v = vec_splat_float(x2d);
vec_float4 x2r_v = vec_splat_float(x2r);
vec_float4 x3n_v = vec_splat_float(x3n);
vec_float4 x3d_v = vec_splat_float(x3d);
vec_float4 x3r_v = vec_splat_float(x3r);
vec_float4 x4n_v = vec_splat_float(x4n);
vec_float4 x4d_v = vec_splat_float(x4d);
vec_float4 x4r_v = vec_splat_float(x4r);
vec_float4 x5n_v = vec_splat_float(x5n);
vec_float4 x5d_v = vec_splat_float(x5d);
vec_float4 x5r_v = vec_splat_float(x5r);
vec_float4 res_v;
TEST_START("fmodf4");
res_v = fmodf4(x0n_v, x0d_v);
TEST_CHECK("20040928191245EJL", allequal_ulps_float4( res_v, x0r_v, 1 ), 0);
res_v = fmodf4(x1n_v, x1d_v);
TEST_CHECK("20040928191247EJL", allequal_ulps_float4( res_v, x1r_v, 1 ), 0);
res_v = fmodf4(x2n_v, x2d_v);
TEST_CHECK("20040928191249EJL", allequal_ulps_float4( res_v, x2r_v, 1 ), 0);
res_v = fmodf4(x3n_v, x3d_v);
TEST_CHECK("20040928191251EJL", allequal_ulps_float4( res_v, x3r_v, 1 ), 0);
res_v = fmodf4(x4n_v, x4d_v);
TEST_CHECK("20040928191253EJL", allequal_ulps_float4( res_v, x4r_v, 1 ), 0);
res_v = fmodf4(x5n_v, x5d_v);
TEST_CHECK("20040928191255EJL", allequal_ulps_float4( res_v, x5r_v, 1 ), 0);
TEST_SET_DONE();
TEST_EXIT();
}

View File

@@ -0,0 +1,108 @@
/* Testcase for modff4
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved.
Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "common-test.h"
#include "testutils.h"
#include "simdmath.h"
int main()
{
TEST_SET_START("20040916170642EJL", "EJL", "modff");
unsigned int i3 = 0x4affffff; // 2^23 - 0.5, largest truncatable value.
unsigned int i3i = 0x4afffffe;
unsigned int i4 = 0x4b000000; // 2^23, no fractional part.
unsigned int i5 = 0xcf000001; // -2^31, one more large, and negative, value.
float x0 = hide_float(0.91825f);
float x0i = hide_float(0.0f);
float x0f = hide_float(0.91825f);
float x1 = hide_float(-0.12958f);
float x1i = hide_float(0.0f);
float x1f = hide_float(-0.12958f);
float x2 = hide_float(-79615.1875f);
float x2i = hide_float(-79615.0f);
float x2f = hide_float(-0.1875f);
float x3 = hide_float(make_float(i3));
float x3i = hide_float(make_float(i3i));
float x3f = hide_float(0.5f);
float x4 = hide_float(make_float(i4));
float x4i = hide_float(make_float(i4));
float x4f = hide_float(0.0f);
float x5 = hide_float(make_float(i5));
float x5i = hide_float(make_float(i5));
float x5f = hide_float(0.0f);
vec_float4 x0_v = vec_splat_float(x0);
vec_float4 x0i_v = vec_splat_float(x0i);
vec_float4 x0f_v = vec_splat_float(x0f);
vec_float4 x1_v = vec_splat_float(x1);
vec_float4 x1i_v = vec_splat_float(x1i);
vec_float4 x1f_v = vec_splat_float(x1f);
vec_float4 x2_v = vec_splat_float(x2);
vec_float4 x2i_v = vec_splat_float(x2i);
vec_float4 x2f_v = vec_splat_float(x2f);
vec_float4 x3_v = vec_splat_float(x3);
vec_float4 x3i_v = vec_splat_float(x3i);
vec_float4 x3f_v = vec_splat_float(x3f);
vec_float4 x4_v = vec_splat_float(x4);
vec_float4 x4i_v = vec_splat_float(x4i);
vec_float4 x4f_v = vec_splat_float(x4f);
vec_float4 x5_v = vec_splat_float(x5);
vec_float4 x5i_v = vec_splat_float(x5i);
vec_float4 x5f_v = vec_splat_float(x5f);
vec_float4 integer_v, fraction_v;
TEST_START("modff4");
fraction_v = modff4(x0_v, &integer_v);
TEST_CHECK("20040916170647EJL", allequal_float4( integer_v, x0i_v ) && allequal_float4( fraction_v, x0f_v ), 0);
fraction_v = modff4(x1_v, &integer_v);
TEST_CHECK("20040916170650EJL", allequal_float4( integer_v, x1i_v ) && allequal_float4( fraction_v, x1f_v ), 0);
fraction_v = modff4(x2_v, &integer_v);
TEST_CHECK("20040916170653EJL", allequal_float4( integer_v, x2i_v ) && allequal_float4( fraction_v, x2f_v ), 0);
fraction_v = modff4(x3_v, &integer_v);
TEST_CHECK("20040916170656EJL", allequal_float4( integer_v, x3i_v ) && allequal_float4( fraction_v, x3f_v ), 0);
fraction_v = modff4(x4_v, &integer_v);
TEST_CHECK("20040916170658EJL", allequal_float4( integer_v, x4i_v ) && allequal_float4( fraction_v, x4f_v ), 0);
fraction_v = modff4(x5_v, &integer_v);
TEST_CHECK("20040916170701EJL", allequal_float4( integer_v, x5i_v ) && allequal_float4( fraction_v, x5f_v ), 0);
TEST_SET_DONE();
TEST_EXIT();
}

View File

@@ -0,0 +1,86 @@
/* Testcase for negatef4
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved.
Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "common-test.h"
#include "testutils.h"
#include "simdmath.h"
int main()
{
TEST_SET_START("20040930102649EJL","EJL", "negatef4");
unsigned int i3n = 0xff000000;
unsigned int i3p = 0x7f000000;
float x0n = hide_float(-0.0f);
float x0p = hide_float(0.0f);
float x1n = hide_float(-83532.96153153f);
float x1p = hide_float(83532.96153153f);
float x2n = hide_float(-0.0000000013152f);
float x2p = hide_float(0.0000000013152f);
float x3n = hide_float(make_float(i3n));
float x3p = hide_float(make_float(i3p));
vec_float4 x0n_v = vec_splat_float(x0n);
vec_float4 x0p_v = vec_splat_float(x0p);
vec_float4 x1n_v = vec_splat_float(x1n);
vec_float4 x1p_v = vec_splat_float(x1p);
vec_float4 x2n_v = vec_splat_float(x2n);
vec_float4 x2p_v = vec_splat_float(x2p);
vec_float4 x3n_v = vec_splat_float(x3n);
vec_float4 x3p_v = vec_splat_float(x3p);
vec_float4 res_v;
TEST_START("negatef4");
res_v = negatef4(x0n_v);
TEST_CHECK("20040930102652EJL", allequal_float4( res_v, x0p_v ), 0);
res_v = negatef4(x0p_v);
TEST_CHECK("20040930102653EJL", allequal_float4( res_v, x0n_v ), 0);
res_v = negatef4(x1n_v);
TEST_CHECK("20040930102655EJL", allequal_float4( res_v, x1p_v ), 0);
res_v = negatef4(x1p_v);
TEST_CHECK("20040930102657EJL", allequal_float4( res_v, x1n_v ), 0);
res_v = negatef4(x2n_v);
TEST_CHECK("20040930102659EJL", allequal_float4( res_v, x2p_v ), 0);
res_v = negatef4(x2p_v);
TEST_CHECK("20040930102701EJL", allequal_float4( res_v, x2n_v ), 0);
res_v = negatef4(x3n_v);
TEST_CHECK("20040930102703EJL", allequal_float4( res_v, x3p_v ), 0);
res_v = negatef4(x3p_v);
TEST_CHECK("20040930102705EJL", allequal_float4( res_v, x3n_v ), 0);
TEST_SET_DONE();
TEST_EXIT();
}

View File

@@ -0,0 +1,83 @@
/* Testcase for negatei4
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved.
Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "common-test.h"
#include "testutils.h"
#include "simdmath.h"
int main()
{
TEST_SET_START("20040930102649EJL","EJL", "negatei4");
int x0n = hide_int(0);
int x0p = hide_int(0);
int x1n = hide_int(-83532);
int x1p = hide_int(83532);
int x2n = hide_int(-13152);
int x2p = hide_int(13152);
int x3n = hide_int(-1);
int x3p = hide_int(1);
vec_int4 x0n_v = vec_splat_int(x0n);
vec_int4 x0p_v = vec_splat_int(x0p);
vec_int4 x1n_v = vec_splat_int(x1n);
vec_int4 x1p_v = vec_splat_int(x1p);
vec_int4 x2n_v = vec_splat_int(x2n);
vec_int4 x2p_v = vec_splat_int(x2p);
vec_int4 x3n_v = vec_splat_int(x3n);
vec_int4 x3p_v = vec_splat_int(x3p);
vec_int4 res_v;
TEST_START("negatei4");
res_v = negatei4(x0n_v);
TEST_CHECK("20040930102652EJL", allequal_int4( res_v, x0p_v ), 0);
res_v = negatei4(x0p_v);
TEST_CHECK("20040930102653EJL", allequal_int4( res_v, x0n_v ), 0);
res_v = negatei4(x1n_v);
TEST_CHECK("20040930102655EJL", allequal_int4( res_v, x1p_v ), 0);
res_v = negatei4(x1p_v);
TEST_CHECK("20040930102657EJL", allequal_int4( res_v, x1n_v ), 0);
res_v = negatei4(x2n_v);
TEST_CHECK("20040930102659EJL", allequal_int4( res_v, x2p_v ), 0);
res_v = negatei4(x2p_v);
TEST_CHECK("20040930102701EJL", allequal_int4( res_v, x2n_v ), 0);
res_v = negatei4(x3n_v);
TEST_CHECK("20040930102703EJL", allequal_int4( res_v, x3p_v ), 0);
res_v = negatei4(x3p_v);
TEST_CHECK("20040930102705EJL", allequal_int4( res_v, x3n_v ), 0);
TEST_SET_DONE();
TEST_EXIT();
}

View File

@@ -0,0 +1,108 @@
/* Testcase for recipf4
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved.
Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "common-test.h"
#include "testutils.h"
#include "simdmath.h"
int main()
{
TEST_SET_START("20040920142553EJL","EJL", "recipf4");
unsigned int i1 = 0xff000000; // -2^127
unsigned int i2 = 0xfe7fffff; // -2^126 - 1 ulp
unsigned int i2r = 0x80800001;
unsigned int i3 = 0x75013340; // random values
unsigned int i3r = 0x09fd9f35;
unsigned int i4 = 0x75e7753f;
unsigned int i4r = 0x090d9277;
unsigned int i5 = 0x4c7fed5a;
unsigned int i5r = 0x32800954;
unsigned int i6 = 0x3a0731f0;
unsigned int i6r = 0x44f2602e;
unsigned int i7 = 0x69784a07;
unsigned int i7r = 0x1583f9a3;
float x1 = hide_float(make_float(i1));
float x1r = hide_float(0.0f);
float x2 = hide_float(make_float(i2));
float x2r = hide_float(make_float(i2r));
float x3 = hide_float(make_float(i3));
float x3r = hide_float(make_float(i3r));
float x4 = hide_float(make_float(i4));
float x4r = hide_float(make_float(i4r));
float x5 = hide_float(make_float(i5));
float x5r = hide_float(make_float(i5r));
float x6 = hide_float(make_float(i6));
float x6r = hide_float(make_float(i6r));
float x7 = hide_float(make_float(i7));
float x7r = hide_float(make_float(i7r));
vec_float4 x1_v = vec_splat_float(x1);
vec_float4 x1r_v = vec_splat_float(x1r);
vec_float4 x2_v = vec_splat_float(x2);
vec_float4 x2r_v = vec_splat_float(x2r);
vec_float4 x3_v = vec_splat_float(x3);
vec_float4 x3r_v = vec_splat_float(x3r);
vec_float4 x4_v = vec_splat_float(x4);
vec_float4 x4r_v = vec_splat_float(x4r);
vec_float4 x5_v = vec_splat_float(x5);
vec_float4 x5r_v = vec_splat_float(x5r);
vec_float4 x6_v = vec_splat_float(x6);
vec_float4 x6r_v = vec_splat_float(x6r);
vec_float4 x7_v = vec_splat_float(x7);
vec_float4 x7r_v = vec_splat_float(x7r);
vec_float4 res_v;
TEST_START("recipf4");
res_v = recipf4(x1_v);
TEST_CHECK("20040920142600EJL", allequal_float4( res_v, x1r_v), 0);
res_v = recipf4(x2_v);
TEST_CHECK("20040920142602EJL", allequal_ulps_float4( res_v, x2r_v, 2 ), 0);
res_v = recipf4(x3_v);
TEST_CHECK("20040920142604EJL", allequal_ulps_float4( res_v, x3r_v, 2 ), 0);
res_v = recipf4(x4_v);
TEST_CHECK("20040920142606EJL", allequal_ulps_float4( res_v, x4r_v, 2 ), 0);
res_v = recipf4(x5_v);
TEST_CHECK("20040920142608EJL", allequal_ulps_float4( res_v, x5r_v, 2 ), 0);
res_v = recipf4(x6_v);
TEST_CHECK("20040920142609EJL", allequal_ulps_float4( res_v, x6r_v, 2 ), 0);
res_v = recipf4(x7_v);
TEST_CHECK("20040920142611EJL", allequal_ulps_float4( res_v, x7r_v, 2 ), 0);
TEST_SET_DONE();
TEST_EXIT();
}

View File

@@ -0,0 +1,95 @@
/* Testcase for rsqrtf4
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved.
Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "common-test.h"
#include "testutils.h"
#include "simdmath.h"
int main()
{
TEST_SET_START("20040928182349EJL","EJL", "rsqrtf4");
unsigned int i3 = 0x742c4455;
unsigned int i3r = 0x251c099a;
unsigned int i4 = 0x75e7753f;
unsigned int i4r = 0x243e5fe2;
unsigned int i5 = 0x4baa9e3c;
unsigned int i5r = 0x395dbbeb;
unsigned int i6 = 0x39344296;
unsigned int i6r = 0x429889eb;
unsigned int i7 = 0x68a586b0;
unsigned int i7r = 0x2ae11e67;
float x3 = hide_float(make_float(i3));
float x3r = hide_float(make_float(i3r));
float x4 = hide_float(make_float(i4));
float x4r = hide_float(make_float(i4r));
float x5 = hide_float(make_float(i5));
float x5r = hide_float(make_float(i5r));
float x6 = hide_float(make_float(i6));
float x6r = hide_float(make_float(i6r));
float x7 = hide_float(make_float(i7));
float x7r = hide_float(make_float(i7r));
vec_float4 x3_v = vec_splat_float(x3);
vec_float4 x3r_v = vec_splat_float(x3r);
vec_float4 x4_v = vec_splat_float(x4);
vec_float4 x4r_v = vec_splat_float(x4r);
vec_float4 x5_v = vec_splat_float(x5);
vec_float4 x5r_v = vec_splat_float(x5r);
vec_float4 x6_v = vec_splat_float(x6);
vec_float4 x6r_v = vec_splat_float(x6r);
vec_float4 x7_v = vec_splat_float(x7);
vec_float4 x7r_v = vec_splat_float(x7r);
vec_float4 res_v;
TEST_START("rsqrtf4");
res_v = rsqrtf4(x3_v);
TEST_CHECK("20040928182352EJL", allequal_ulps_float4( res_v, x3r_v, 2 ), 0);
res_v = rsqrtf4(x4_v);
TEST_CHECK("20040928182355EJL", allequal_ulps_float4( res_v, x4r_v, 2 ), 0);
res_v = rsqrtf4(x5_v);
TEST_CHECK("20040928182357EJL", allequal_ulps_float4( res_v, x5r_v, 2 ), 0);
res_v = rsqrtf4(x6_v);
TEST_CHECK("20040928182358EJL", allequal_ulps_float4( res_v, x6r_v, 2 ), 0);
res_v = rsqrtf4(x7_v);
TEST_CHECK("20040928182401EJL", allequal_ulps_float4( res_v, x7r_v, 2 ), 0);
TEST_SET_DONE();
TEST_EXIT();
}

View File

@@ -0,0 +1,100 @@
/* Testcase for sqrtf4
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved.
Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "common-test.h"
#include "testutils.h"
#include "simdmath.h"
int main()
{
TEST_SET_START("20040928182549EJL","EJL", "sqrtf4");
unsigned int i3 = 0x742c4455;
unsigned int i3r = 0x59d20034;
unsigned int i4 = 0x75e7753f;
unsigned int i4r = 0x5aac1fb5;
unsigned int i5 = 0x4baa9e3c;
unsigned int i5r = 0x4593c7d8;
unsigned int i6 = 0x39344296;
unsigned int i6r = 0x3c56d14c;
unsigned int i7 = 0x68a586b0;
unsigned int i7r = 0x54118f09;
float x0 = hide_float(0.0f);
float x0r = hide_float(0.0f);
float x3 = hide_float(make_float(i3));
float x3r = hide_float(make_float(i3r));
float x4 = hide_float(make_float(i4));
float x4r = hide_float(make_float(i4r));
float x5 = hide_float(make_float(i5));
float x5r = hide_float(make_float(i5r));
float x6 = hide_float(make_float(i6));
float x6r = hide_float(make_float(i6r));
float x7 = hide_float(make_float(i7));
float x7r = hide_float(make_float(i7r));
vec_float4 x0_v = vec_splat_float(x0);
vec_float4 x0r_v = vec_splat_float(x0r);
vec_float4 x3_v = vec_splat_float(x3);
vec_float4 x3r_v = vec_splat_float(x3r);
vec_float4 x4_v = vec_splat_float(x4);
vec_float4 x4r_v = vec_splat_float(x4r);
vec_float4 x5_v = vec_splat_float(x5);
vec_float4 x5r_v = vec_splat_float(x5r);
vec_float4 x6_v = vec_splat_float(x6);
vec_float4 x6r_v = vec_splat_float(x6r);
vec_float4 x7_v = vec_splat_float(x7);
vec_float4 x7r_v = vec_splat_float(x7r);
vec_float4 res_v;
TEST_START("sqrtf4");
res_v = sqrtf4(x0_v);
TEST_CHECK("20040928182551EJL", allequal_float4( res_v, x0r_v ), 0);
res_v = sqrtf4(x3_v);
TEST_CHECK("20040928182552EJL", allequal_ulps_float4( res_v, x3r_v, 2 ), 0);
res_v = sqrtf4(x4_v);
TEST_CHECK("20040928182554EJL", allequal_ulps_float4( res_v, x4r_v, 2 ), 0);
res_v = sqrtf4(x5_v);
TEST_CHECK("20040928182556EJL", allequal_ulps_float4( res_v, x5r_v, 2 ), 0);
res_v = sqrtf4(x6_v);
TEST_CHECK("20040928182557EJL", allequal_ulps_float4( res_v, x6r_v, 2 ), 0);
res_v = sqrtf4(x7_v);
TEST_CHECK("20040928182559EJL", allequal_ulps_float4( res_v, x7r_v, 2 ), 0);
TEST_SET_DONE();
TEST_EXIT();
}

View File

@@ -0,0 +1,67 @@
/* Common part of the testsuite
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved.
Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
unsigned int
hide_uint( unsigned int x )
{
return x;
}
int
hide_int( int x )
{
return x;
}
float
hide_float( float x )
{
return x;
}
double
hide_double( double x )
{
return x;
}
float
make_float( unsigned int x )
{
union
{
unsigned int i;
float f;
}fi;
fi.i = x;
return fi.f;
}

View File

@@ -0,0 +1,100 @@
/* Header file for common parts of the testsuite
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved.
Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
/* FIXME: Don't use altivec style initializers. */
#ifndef _TESTUTILS_H_
#include "floatingpoint_tests.h"
extern unsigned int hide_uint( unsigned int x );
extern int hide_int( int x );
extern float hide_float( float x );
extern float make_float( unsigned int x );
inline vec_int4 vec_splat_int( int x )
{
return (vec_int4){x, x, x, x};
}
inline vec_float4 vec_splat_float( float x )
{
return (vec_float4){x, x, x, x};
}
inline vec_uint4 bitDiff_f4(vec_float4 ref, vec_float4 vals) {
vec_int4 refi = (vec_int4)ref;
vec_int4 valsi = (vec_int4)vals;
vec_int4 diff = vec_sub( refi, valsi );
vec_int4 negdiff = vec_sub( vec_splat_int(0), diff );
vec_uint4 lz;
diff = vec_sel( negdiff, diff, vec_cmpgt( diff, vec_splat_int(0) ) );
lz = vec_sub( (vec_uint4)vec_splat_int(158), vec_sr( (vec_uint4)vec_ctf( diff, 0 ), (vec_uint4)vec_splat_int(23) ) );
lz = vec_sel( lz, (vec_uint4)vec_splat_int(32), vec_cmpeq( diff, vec_splat_int(0) ) );
return vec_sub( (vec_uint4)vec_splat_int(32), lz );
}
inline vec_uint4 ulpDiff_f4(vec_float4 ref, vec_float4 vals) {
vec_int4 refi = (vec_int4)ref;
vec_int4 valsi = (vec_int4)vals;
vec_int4 diff = vec_sub( refi, valsi );
vec_int4 negdiff = vec_sub( vec_splat_int(0), diff );
return (vec_uint4)( vec_sel( negdiff, diff, vec_cmpgt( diff, vec_splat_int(0) ) ) );
}
inline int allequal_int4( vec_int4 x, vec_int4 y )
{
return ( vec_all_eq( x, y ) );
}
inline int allequal_float4( vec_float4 x, vec_float4 y )
{
return ( vec_all_eq( x, y ) );
}
inline int allequal_ulps_float4( vec_float4 x, vec_float4 y, int tolerance )
{
vec_uint4 vtol = (vec_uint4)vec_splat_int( tolerance );
vec_uint4 ulps = ulpDiff_f4( x, y );
return vec_all_le( ulps, vtol );
}
inline int allequal_bits_float4( vec_float4 x, vec_float4 y, int tolerance )
{
vec_uint4 vtol = (vec_uint4)vec_splat_int( tolerance );
vec_uint4 bits = bitDiff_f4( x, y );
return vec_all_le( bits, vtol );
}
#endif

View File

@@ -0,0 +1,93 @@
/* Testcase for truncf4
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved.
Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "common-test.h"
#include "testutils.h"
#include "simdmath.h"
int main()
{
TEST_SET_START("20040916100012EJL","EJL", "truncf");
unsigned int i3 = 0x4affffff; // 2^23 - 0.5, largest truncatable value.
unsigned int i3i = 0x4afffffe;
unsigned int i4 = 0x4b000000; // 2^23, no fractional part.
unsigned int i5 = 0xcf000001; // -2^31, one more large, and negative, value.
float x0 = hide_float(0.91825f);
float x0i = hide_float(0.0f);
float x1 = hide_float(-0.12958f);
float x1i = hide_float(0.0f);
float x2 = hide_float(-79615.1875f);
float x2i = hide_float(-79615.0f);
float x3 = hide_float(make_float(i3));
float x3i = hide_float(make_float(i3i));
float x4 = hide_float(make_float(i4));
float x4i = hide_float(make_float(i4));
float x5 = hide_float(make_float(i5));
float x5i = hide_float(make_float(i5));
vec_float4 x0_v = vec_splat_float(x0);
vec_float4 x0i_v = vec_splat_float(x0i);
vec_float4 x1_v = vec_splat_float(x1);
vec_float4 x1i_v = vec_splat_float(x1i);
vec_float4 x2_v = vec_splat_float(x2);
vec_float4 x2i_v = vec_splat_float(x2i);
vec_float4 x3_v = vec_splat_float(x3);
vec_float4 x3i_v = vec_splat_float(x3i);
vec_float4 x4_v = vec_splat_float(x4);
vec_float4 x4i_v = vec_splat_float(x4i);
vec_float4 x5_v = vec_splat_float(x5);
vec_float4 x5i_v = vec_splat_float(x5i);
vec_float4 res_v;
TEST_START("truncf4");
res_v = truncf4(x0_v);
TEST_CHECK("20040916100023EJL", allequal_float4( res_v, x0i_v ), 0);
res_v = truncf4(x1_v);
TEST_CHECK("20040916100034EJL", allequal_float4( res_v, x1i_v ), 0);
res_v = truncf4(x2_v);
TEST_CHECK("20040916100043EJL", allequal_float4( res_v, x2i_v ), 0);
res_v = truncf4(x3_v);
TEST_CHECK("20040916100054EJL", allequal_float4( res_v, x3i_v ), 0);
res_v = truncf4(x4_v);
TEST_CHECK("20040916100103EJL", allequal_float4( res_v, x4i_v ), 0);
res_v = truncf4(x5_v);
TEST_CHECK("20040916100111EJL", allequal_float4( res_v, x5i_v ), 0);
TEST_SET_DONE();
TEST_EXIT();
}

View File

@@ -0,0 +1,39 @@
/* truncf4 - for each of four float slots, round towards zero to integer value.
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved.
Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#include <simdmath.h>
#include <altivec.h>
vector float
truncf4 (vector float x)
{
return vec_trunc( x );
}