added updated version of simdmathlibrary-1.0.1

This commit is contained in:
ejcoumans
2007-07-27 18:53:58 +00:00
parent fddd6c5721
commit f360dd27d6
377 changed files with 9928 additions and 6136 deletions

View File

@@ -35,10 +35,10 @@ STATIC_TESTS = $(TESTS)
SHARED_TESTS = $(TESTS:=.shared)
ALL_TESTS = $(STATIC_TESTS) $(SHARED_TESTS)
INCLUDES_PPU = -I../../
INCLUDES_PPU = -I../../common
ARCH_PPU = 64
CROSS_PPU = ppu-
ARCH_PPU = 32
CROSS_PPU =
AR_PPU = $(CROSS_PPU)ar
CC_PPU = $(CROSS_PPU)gcc
CXX_PPU = $(CROSS_PPU)g++
@@ -111,21 +111,8 @@ shared_check:
../$(SHARED_LIB):
cd ../;$(MAKE) $(MAKE_DEFS) $(SHARED_LIB)
%.o: %.c common-test.h testutils.h
%.o: %.c ../../common/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

@@ -1,198 +0,0 @@
/* 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

@@ -1,189 +0,0 @@
/* 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

@@ -32,7 +32,17 @@
#ifndef _TESTUTILS_H_
#include "floatingpoint_tests.h"
#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
extern unsigned int hide_uint( unsigned int x );
extern int hide_int( int x );