Remove AltiVec code
The content of src/archutils/Darwin/VectorHelper.cpp is very old, these are AltiVec and SSE2 instructions. This is only actually used in RageSoundMixBuffer.cpp. This level of micro-optimization is not needed since platforms this old are not supported by ITGm.
This commit is contained in:
@@ -8,8 +8,7 @@ if(APPLE)
|
||||
"archutils/Darwin/MouseDevice.cpp"
|
||||
"archutils/Darwin/PumpDevice.cpp"
|
||||
"archutils/Darwin/SMMain.mm"
|
||||
"archutils/Darwin/SpecialDirs.mm"
|
||||
"archutils/Darwin/VectorHelper.cpp")
|
||||
"archutils/Darwin/SpecialDirs.mm")
|
||||
list(APPEND SMDATA_OS_DARWIN_HPP
|
||||
"archutils/Darwin/arch_setup.h"
|
||||
"archutils/Darwin/Crash.h"
|
||||
@@ -20,8 +19,7 @@ if(APPLE)
|
||||
"archutils/Darwin/MouseDevice.h"
|
||||
"archutils/Darwin/PumpDevice.h"
|
||||
"archutils/Darwin/SpecialDirs.h"
|
||||
"archutils/Darwin/StepMania.pch" # precompiled header.
|
||||
"archutils/Darwin/VectorHelper.h")
|
||||
"archutils/Darwin/StepMania.pch")
|
||||
|
||||
source_group("OS Specific\\\\Darwin"
|
||||
FILES
|
||||
|
||||
@@ -5,13 +5,6 @@
|
||||
#include <cmath>
|
||||
#include <cstdint>
|
||||
|
||||
#if defined(MACOSX)
|
||||
#include "archutils/Darwin/VectorHelper.h"
|
||||
#ifdef USE_VEC
|
||||
static bool g_bVector = Vector::CheckForVector();
|
||||
#endif
|
||||
#endif
|
||||
|
||||
RageSoundMixBuffer::RageSoundMixBuffer()
|
||||
{
|
||||
m_iBufSize = m_iBufUsed = 0;
|
||||
@@ -52,21 +45,12 @@ void RageSoundMixBuffer::write( const float *pBuf, unsigned iSize, int iSourceSt
|
||||
if( iSize == 0 )
|
||||
return;
|
||||
|
||||
/* iSize = 3, iDestStride = 2 uses 4 frames. Don't allocate the stride of the
|
||||
* last sample. */
|
||||
// iSize = 3, iDestStride = 2 uses 4 frames. Don't allocate the stride of the last sample.
|
||||
Extend( iSize * iDestStride - (iDestStride-1) );
|
||||
|
||||
/* Scale volume and add. */
|
||||
// Scale volume and add.
|
||||
float *pDestBuf = m_pMixbuf+m_iOffset;
|
||||
|
||||
#ifdef USE_VEC
|
||||
if( g_bVector && iSourceStride == 1 && iDestStride == 1 )
|
||||
{
|
||||
Vector::FastSoundWrite( pDestBuf, pBuf, iSize );
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
while( iSize )
|
||||
{
|
||||
*pDestBuf += *pBuf;
|
||||
|
||||
@@ -1,268 +0,0 @@
|
||||
#include "VectorHelper.h"
|
||||
#include <sys/sysctl.h>
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
#if defined(USE_VEC)
|
||||
#if defined(__VEC__)
|
||||
#include <vecLib/vecLib.h>
|
||||
|
||||
bool Vector::CheckForVector()
|
||||
{
|
||||
std::int32_t result = 0;
|
||||
std::size_t size = 4;
|
||||
|
||||
return !sysctlbyname( "hw.vectorunit", &result, &size, nullptr, 0 ) && result;
|
||||
}
|
||||
|
||||
/* for( unsigned pos = 0; pos < size; ++pos )
|
||||
* dest[pos] += src[pos];
|
||||
* Idea from: http://developer.apple.com/hardwaredrivers/ve/downloads/add.c */
|
||||
void Vector::FastSoundWrite( float *dest, const float *src, unsigned size )
|
||||
{
|
||||
if( size > 4 )
|
||||
{
|
||||
int index = 0;
|
||||
vUInt8 one = (vUInt8)(1);
|
||||
vUInt8 srcMask = vec_add( vec_lvsl(15, src), one );
|
||||
vUInt8 destMask = vec_add(vec_lvsl(15, dest), one );
|
||||
vUInt8 storeMask = vec_lvsr( 0, dest );
|
||||
vFloat load1Src = vec_ld( 0, src );
|
||||
vFloat load1Dest = vec_ld( 0, dest );
|
||||
vFloat store = (vFloat)(0.0f);
|
||||
|
||||
// If dest is misaligned, pull the first loop iteration out.
|
||||
if( std::intptr_t(dest) & 0xF )
|
||||
{
|
||||
vFloat load2Src = vec_ld( 15, src );
|
||||
vFloat load2Dest = vec_ld( 15, dest );
|
||||
|
||||
load1Src = vec_perm( load1Src, load2Src, srcMask );
|
||||
load1Dest = vec_perm( load1Dest, load2Dest, destMask );
|
||||
|
||||
load1Dest = vec_add( load1Dest, load1Src );
|
||||
store = vec_perm( load1Dest, load1Dest, storeMask );
|
||||
|
||||
while( (std::intptr_t(dest) + index) & 0xC )
|
||||
{
|
||||
vec_ste( store, index, dest );
|
||||
index += 4;
|
||||
}
|
||||
load1Src = load2Src;
|
||||
store = load1Dest;
|
||||
load1Dest = load2Dest;
|
||||
src += 4;
|
||||
dest += 4;
|
||||
size -= 4;
|
||||
/* Incrementing the index is supposed to have the same effect
|
||||
* as incrementing dest but since we read from dest as well
|
||||
* we don't want to increment twice so decrement the index. */
|
||||
// XXX: What in the world did I mean here?
|
||||
index -= 16;
|
||||
}
|
||||
while( size >= 32 )
|
||||
{
|
||||
vFloat load2Src = vec_ld( 15, src );
|
||||
vFloat load3Src = vec_ld( 31, src );
|
||||
vFloat load4Src = vec_ld( 47, src );
|
||||
vFloat load5Src = vec_ld( 63, src );
|
||||
vFloat load6Src = vec_ld( 79, src );
|
||||
vFloat load7Src = vec_ld( 95, src );
|
||||
vFloat load8Src = vec_ld( 111, src );
|
||||
vFloat load9Src = vec_ld( 127, src );
|
||||
vFloat load2Dest = vec_ld( 15, dest );
|
||||
vFloat load3Dest = vec_ld( 31, dest );
|
||||
vFloat load4Dest = vec_ld( 47, dest );
|
||||
vFloat load5Dest = vec_ld( 63, dest );
|
||||
vFloat load6Dest = vec_ld( 79, dest );
|
||||
vFloat load7Dest = vec_ld( 95, dest );
|
||||
vFloat load8Dest = vec_ld( 111, dest );
|
||||
vFloat load9Dest = vec_ld( 127, dest );
|
||||
|
||||
// Align the data.
|
||||
load1Src = vec_perm( load1Src, load2Src, srcMask );
|
||||
load2Src = vec_perm( load2Src, load3Src, srcMask );
|
||||
load3Src = vec_perm( load3Src, load4Src, srcMask );
|
||||
load4Src = vec_perm( load4Src, load5Src, srcMask );
|
||||
load5Src = vec_perm( load5Src, load6Src, srcMask );
|
||||
load6Src = vec_perm( load6Src, load7Src, srcMask );
|
||||
load7Src = vec_perm( load7Src, load8Src, srcMask );
|
||||
load8Src = vec_perm( load8Src, load9Src, srcMask );
|
||||
// Not load5Src, it's untouched and used later.
|
||||
load1Dest = vec_perm( load1Dest, load2Dest, destMask );
|
||||
load2Dest = vec_perm( load2Dest, load3Dest, destMask );
|
||||
load3Dest = vec_perm( load3Dest, load4Dest, destMask );
|
||||
load4Dest = vec_perm( load4Dest, load5Dest, destMask );
|
||||
load5Dest = vec_perm( load5Dest, load6Dest, destMask );
|
||||
load6Dest = vec_perm( load6Dest, load7Dest, destMask );
|
||||
load7Dest = vec_perm( load7Dest, load8Dest, destMask );
|
||||
load8Dest = vec_perm( load8Dest, load9Dest, destMask );
|
||||
// Not load9Dest.
|
||||
|
||||
load1Dest = vec_add( load1Dest, load1Src );
|
||||
load2Dest = vec_add( load2Dest, load2Src );
|
||||
load3Dest = vec_add( load3Dest, load3Src );
|
||||
load4Dest = vec_add( load4Dest, load4Src );
|
||||
load5Dest = vec_add( load5Dest, load5Src );
|
||||
load6Dest = vec_add( load6Dest, load6Src );
|
||||
load7Dest = vec_add( load7Dest, load7Src );
|
||||
load8Dest = vec_add( load8Dest, load8Src );
|
||||
|
||||
// Unalign the results.
|
||||
store = vec_perm( store, load1Dest, storeMask );
|
||||
load1Dest = vec_perm( load1Dest, load2Dest, storeMask );
|
||||
load2Dest = vec_perm( load2Dest, load3Dest, storeMask );
|
||||
load3Dest = vec_perm( load3Dest, load4Dest, storeMask );
|
||||
load4Dest = vec_perm( load4Dest, load5Dest, storeMask );
|
||||
load5Dest = vec_perm( load5Dest, load6Dest, storeMask );
|
||||
load6Dest = vec_perm( load6Dest, load7Dest, storeMask );
|
||||
load7Dest = vec_perm( load7Dest, load8Dest, storeMask );
|
||||
|
||||
// store the results
|
||||
vec_st( store, index + 0, dest );
|
||||
vec_st( load1Dest, index + 16, dest );
|
||||
vec_st( load2Dest, index + 32, dest );
|
||||
vec_st( load3Dest, index + 48, dest );
|
||||
vec_st( load4Dest, index + 64, dest );
|
||||
vec_st( load5Dest, index + 80, dest );
|
||||
vec_st( load6Dest, index + 96, dest );
|
||||
vec_st( load7Dest, index + 112, dest );
|
||||
|
||||
load1Src = load9Src;
|
||||
load1Dest = load9Dest;
|
||||
store = load8Dest;
|
||||
dest += 32;
|
||||
src += 32;
|
||||
size -= 32;
|
||||
}
|
||||
|
||||
/* This completely baffles gcc's loop unrolling. If I make it > 3 instead,
|
||||
* then gcc produces 4 identical copies of the loop without scheduling them
|
||||
* in a sane manner (hence the manual unrolling above) but this loop will
|
||||
* never be executed more than 3 times so that code will never be used.
|
||||
* This produces code the way gcc _should_ do it by unrolling and scheduling
|
||||
* and then producing the rolled version. */
|
||||
while( size & ~0x3 )
|
||||
{
|
||||
vFloat load2Src = vec_ld( 15, src );
|
||||
vFloat load2Dest = vec_ld( 15, dest );
|
||||
|
||||
load1Src = vec_perm( load1Src, load2Src, srcMask );
|
||||
load1Dest = vec_perm( load1Dest, load2Dest, destMask );
|
||||
load1Dest = vec_add( load1Dest, load1Src );
|
||||
|
||||
store = vec_perm( store, load1Dest, storeMask );
|
||||
vec_st( store, index, dest );
|
||||
|
||||
load1Src = load2Src;
|
||||
store = load1Dest;
|
||||
load1Dest = load2Dest;
|
||||
src += 4;
|
||||
dest += 4;
|
||||
size -= 4;
|
||||
}
|
||||
|
||||
// Store the remainder of the vector, if it was misaligned.
|
||||
if( index < 0 )
|
||||
{
|
||||
store = vec_perm( store, store, storeMask );
|
||||
while( index < 0 )
|
||||
{
|
||||
vec_ste( store, index, dest );
|
||||
index += 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* If we account for both misaligned dest and src, there is really no way to
|
||||
* do this in vector code so do the last at most 3 elements in scalar code. */
|
||||
while( size-- )
|
||||
*(dest++) += *(src++);
|
||||
}
|
||||
|
||||
#elif defined(__SSE2__)
|
||||
#include <xmmintrin.h>
|
||||
// This is portable to other systems since it uses Intel's intrinsics.
|
||||
|
||||
bool Vector::CheckForVector()
|
||||
{
|
||||
// MMX, SSE, and SSE2 must be present, we don't use SSE3 so no need to check for it.
|
||||
return true;
|
||||
}
|
||||
|
||||
void Vector::FastSoundWrite( float *dest, const float *src, unsigned size )
|
||||
{
|
||||
while( (std::intptr_t(dest) & 0xF) && size )
|
||||
{
|
||||
// Misaligned stores are slow.
|
||||
*(dest++) += *(src++);
|
||||
--size;
|
||||
}
|
||||
|
||||
// Misaligned loads are slower so specialize to aligned loads when possible.
|
||||
if( std::intptr_t(src) & 0xF )
|
||||
{
|
||||
while( size >= 8 )
|
||||
{
|
||||
__m128 data1 = _mm_loadu_ps( src + 0 );
|
||||
__m128 data2 = _mm_loadu_ps( src + 4 );
|
||||
|
||||
data1 = _mm_add_ps( data1, *(__m128 *)(dest + 0) );
|
||||
data2 = _mm_add_ps( data2, *(__m128 *)(dest + 4) );
|
||||
_mm_store_ps( dest + 0, data1 );
|
||||
_mm_store_ps( dest + 4, data2 );
|
||||
src += 8;
|
||||
dest += 8;
|
||||
size -= 8;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while( size >= 8 )
|
||||
{
|
||||
__m128 data1 = _mm_load_ps( src + 0 );
|
||||
__m128 data2 = _mm_load_ps( src + 4 );
|
||||
|
||||
data1 = _mm_add_ps( data1, *(__m128 *)(dest + 0) );
|
||||
data2 = _mm_add_ps( data2, *(__m128 *)(dest + 4) );
|
||||
_mm_store_ps( dest + 0, data1 );
|
||||
_mm_store_ps( dest + 4, data2 );
|
||||
src += 8;
|
||||
dest += 8;
|
||||
size -= 8;
|
||||
}
|
||||
}
|
||||
while( size-- )
|
||||
*(dest++) += *(src++);
|
||||
}
|
||||
|
||||
#else
|
||||
#error huh?
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* (c) 2006-2007 Steve Checkoway
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, and/or sell copies of the Software, and to permit persons to
|
||||
* whom the Software is furnished to do so, provided that the above
|
||||
* copyright notice(s) and this permission notice appear in all copies of
|
||||
* the Software and that both the above copyright notice(s) and this
|
||||
* permission notice appear in supporting documentation.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
|
||||
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
|
||||
* INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
|
||||
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
|
||||
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
* PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
@@ -1,38 +0,0 @@
|
||||
#ifndef VECTOR_HELPER_H
|
||||
#define VECTOR_HELPER_H
|
||||
|
||||
#if ( defined(__VEC__) || (defined(__SSE__) && defined(__SSE2__)) ) && defined(__GNUC__)
|
||||
namespace Vector
|
||||
{
|
||||
bool CheckForVector();
|
||||
void FastSoundWrite( float *dest, const float *src, unsigned size );
|
||||
}
|
||||
#define USE_VEC
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* (c) 2006 Steve Checkoway
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, and/or sell copies of the Software, and to permit persons to
|
||||
* whom the Software is furnished to do so, provided that the above
|
||||
* copyright notice(s) and this permission notice appear in all copies of
|
||||
* the Software and that both the above copyright notice(s) and this
|
||||
* permission notice appear in supporting documentation.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
|
||||
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
|
||||
* INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
|
||||
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
|
||||
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
* PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
@@ -8,8 +8,3 @@ Once I create smaller test inputs, I'll commit them; the current set is about
|
||||
files you have.
|
||||
|
||||
This is only compiled in the Unix build environment.
|
||||
|
||||
test_vector is for testing VectorHelper against the reference scalar
|
||||
code. It can be compiled using:
|
||||
g++ -g -I.. ../archutils/Darwin/VectorHelper.cpp test_vector.cpp -faltivec
|
||||
You can replace -faltivec with -msse2 on intel. Might requires -O3 to inline.
|
||||
|
||||
@@ -1,330 +0,0 @@
|
||||
#define _XOPEN_SOURCE 600
|
||||
#include <cassert>
|
||||
#include <cmath>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <algorithm>
|
||||
#include <archutils/Darwin/VectorHelper.h>
|
||||
|
||||
#if 0
|
||||
# error This depends on macOS and Apple's gcc.
|
||||
#endif
|
||||
#ifndef USE_VEC
|
||||
# error Enable altivec or sse.
|
||||
#endif
|
||||
#define SCALE(x, l1, h1, l2, h2) (((x) - (l1)) * ((h2) - (l2)) / ((h1) - (l1)) + (l2))
|
||||
|
||||
// This requires that allocated memory be 16 byte aligned. Apple's new
|
||||
// (and malloc) ensures this but most others only ensure that the
|
||||
// memory is type size aligned. Hack in posix_memalign. We could also
|
||||
// override the global new, but that's even more hassle.
|
||||
#ifdef __APPLE_CC__
|
||||
# define NEW(t,s) new t[(s)]
|
||||
# define DELETE(x) delete[] x
|
||||
#else
|
||||
static void *pStupid;
|
||||
# define NEW(t,s) (posix_memalign(&pStupid, 16, s*sizeof(t)), (t *)pStupid)
|
||||
# define DELETE(x) free((x))
|
||||
#endif
|
||||
|
||||
// The reference values.
|
||||
static void ScalarWrite( float *pDestBuf, const float *pSrcBuf, std::size_t iSize )
|
||||
{
|
||||
for( unsigned iPos = 0; iPos < iSize; ++iPos )
|
||||
pDestBuf[iPos] += pSrcBuf[iPos];
|
||||
}
|
||||
|
||||
#if 0
|
||||
static void ScalarRead( std::int16_t *pDestBuf, const std::int32_t *pSrcBuf, unsigned iSize )
|
||||
{
|
||||
for( unsigned iPos = 0; iPos < iSize; ++iPos )
|
||||
pDestBuf[iPos] = std::max( -32768, std::min(pSrcBuf[iPos]/256, 32767) );
|
||||
}
|
||||
#endif
|
||||
|
||||
static void RandBuffer( float *pBuffer, unsigned iSize )
|
||||
{
|
||||
while( iSize-- )
|
||||
*pBuffer++ = float(rand())/RAND_MAX;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static void Diagnostic( const T *pDestBuf, const T *pRefBuf, std::size_t size )
|
||||
{
|
||||
const int num = 10;
|
||||
for( int i = 0; i < num; ++i )
|
||||
fprintf( stderr, "%0*x ", sizeof(T)*2, pDestBuf[i] );
|
||||
puts( "" );
|
||||
for( int i = 0; i < num; ++i )
|
||||
fprintf( stderr, "%0*x ", sizeof(T)*2, pRefBuf[i] );
|
||||
puts( "" );
|
||||
for( std::size_t i = size - num; i < size; ++i )
|
||||
fprintf( stderr, "%0*x ", sizeof(T)*2, pDestBuf[i] );
|
||||
puts( "" );
|
||||
for( std::size_t i = size - num; i < size; ++i )
|
||||
fprintf( stderr, "%0*x ", sizeof(T)*2, pRefBuf[i] );
|
||||
puts( "" );
|
||||
}
|
||||
|
||||
template<>
|
||||
static void Diagnostic<float>( const float *pDestBuf, const float *pRefBuf, std::size_t size )
|
||||
|
||||
{
|
||||
const int num = 10;
|
||||
for( int i = 0; i < num; ++i )
|
||||
fprintf( stderr, "%f ", pDestBuf[i] );
|
||||
puts( "" );
|
||||
for( int i = 0; i < num; ++i )
|
||||
fprintf( stderr, "%f ", pRefBuf[i] );
|
||||
puts( "" );
|
||||
for( std::size_t i = size - num; i < size; ++i )
|
||||
fprintf( stderr, "%f ", pDestBuf[i] );
|
||||
puts( "" );
|
||||
for( std::size_t i = size - num; i < size; ++i )
|
||||
fprintf( stderr, "%f ", pRefBuf[i] );
|
||||
puts( "" );
|
||||
}
|
||||
|
||||
static bool TestWrite( float *pSrcBuf, float *pDestBuf, float *pRefBuf, std::size_t iSize )
|
||||
{
|
||||
RandBuffer( pSrcBuf, iSize );
|
||||
memset( pDestBuf, 0, iSize * 4 );
|
||||
memset( pRefBuf, 0, iSize * 4 );
|
||||
Vector::FastSoundWrite( pDestBuf, pSrcBuf, iSize );
|
||||
ScalarWrite( pRefBuf, pSrcBuf, iSize );
|
||||
return !memcmp( pRefBuf, pDestBuf, iSize * 4 );
|
||||
}
|
||||
|
||||
static bool CheckAlignedWrite()
|
||||
{
|
||||
const std::size_t size = 1024;
|
||||
float *pSrcBuf = NEW( float, size );
|
||||
float *pDestBuf = NEW( float, size );
|
||||
float *pRefBuf = NEW( float, size );
|
||||
bool ret = true;
|
||||
std::size_t s;
|
||||
|
||||
// Test unaligned ends
|
||||
for( int i = 0; i < 16 && ret; ++i )
|
||||
{
|
||||
s = size - i;
|
||||
ret = TestWrite( pSrcBuf, pDestBuf, pRefBuf, s );
|
||||
}
|
||||
if( !ret )
|
||||
Diagnostic( pDestBuf, pRefBuf, s );
|
||||
DELETE( pSrcBuf );
|
||||
DELETE( pDestBuf );
|
||||
DELETE( pRefBuf );
|
||||
return ret;
|
||||
}
|
||||
|
||||
static bool CheckMisalignedSrcWrite()
|
||||
{
|
||||
const std::size_t size = 1024;
|
||||
float *pSrcBuf = NEW( float, size );
|
||||
float *pDestBuf = NEW( float, size );
|
||||
float *pRefBuf = NEW( float, size );
|
||||
bool ret = true;
|
||||
|
||||
for( int j = 0; j < 8 && ret; ++j )
|
||||
{
|
||||
std::size_t s;
|
||||
for( int i = 0; i < 8 && ret; ++i )
|
||||
{
|
||||
s = size - i - j; // Source buffer is shrinking.
|
||||
ret = TestWrite( pSrcBuf+j, pDestBuf, pRefBuf, s );
|
||||
}
|
||||
if( !ret )
|
||||
Diagnostic( pDestBuf, pRefBuf, s );
|
||||
}
|
||||
DELETE( pSrcBuf );
|
||||
DELETE( pDestBuf );
|
||||
DELETE( pRefBuf );
|
||||
return ret;
|
||||
}
|
||||
|
||||
static bool CheckMisalignedDestWrite()
|
||||
{
|
||||
const std::size_t size = 1024;
|
||||
float *pSrcBuf = NEW( float, size );
|
||||
float *pDestBuf = NEW( float, size );
|
||||
float *pRefBuf = NEW( float, size );
|
||||
bool ret = true;
|
||||
|
||||
for( int j = 0; j < 4 && ret; ++j )
|
||||
{
|
||||
std::size_t s;
|
||||
for( int i = 0; i < 8 && ret; ++i )
|
||||
{
|
||||
s = size - i - j; // Dest buffer is shrinking.
|
||||
ret = TestWrite( pSrcBuf, pDestBuf+j, pRefBuf+j, s );
|
||||
}
|
||||
if( !ret )
|
||||
Diagnostic( pDestBuf+j, pRefBuf+j, s );
|
||||
}
|
||||
DELETE( pSrcBuf );
|
||||
DELETE( pDestBuf );
|
||||
DELETE( pRefBuf );
|
||||
return ret;
|
||||
}
|
||||
|
||||
static bool CheckMisalignedBothWrite()
|
||||
{
|
||||
const std::size_t size = 1024;
|
||||
float *pSrcBuf = NEW( float, size );
|
||||
float *pDestBuf = NEW( float, size );
|
||||
float *pRefBuf = NEW( float, size );
|
||||
bool ret = true;
|
||||
std::size_t s;
|
||||
|
||||
for( int j = 0; j < 4 && ret; ++j )
|
||||
{
|
||||
for( int i = 0; i < 8 && ret; ++i )
|
||||
{
|
||||
for( int k = 0; k < 8 && ret; ++k )
|
||||
{
|
||||
s = size - i - j - k; // Both buffers are shrinking.
|
||||
ret = TestWrite( pSrcBuf+i, pDestBuf+j, pRefBuf+j, s );
|
||||
}
|
||||
}
|
||||
if( !ret )
|
||||
Diagnostic( pDestBuf+j, pRefBuf+j, s );
|
||||
}
|
||||
DELETE( pSrcBuf );
|
||||
DELETE( pDestBuf );
|
||||
DELETE( pRefBuf );
|
||||
return ret;
|
||||
}
|
||||
|
||||
static bool cmp( const std::int16_t *p1, const std::int16_t *p2, std::size_t size )
|
||||
{
|
||||
return !memcmp( p1, p2, size * 2 );
|
||||
}
|
||||
|
||||
static bool cmp( const float *p1, const float *p2, std::size_t size )
|
||||
{
|
||||
const float epsilon = 0.000001;
|
||||
++size;
|
||||
while( --size )
|
||||
if( std::abs(*p1++ - *p2++) >= epsilon )
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
#if 0
|
||||
template<typename T>
|
||||
static bool CheckAlignedRead()
|
||||
{
|
||||
const std::size_t size = 1024;
|
||||
std::int32_t *pSrcBuf = NEW( std::int32_t, size );
|
||||
T *pDestBuf = NEW( T, size );
|
||||
T *pRefBuf = NEW( T, size );
|
||||
bool ret = true;
|
||||
|
||||
for( int i = 0; i < 8; ++i )
|
||||
{
|
||||
RandBuffer( pSrcBuf, size-i );
|
||||
Vector::FastSoundRead( pDestBuf, pSrcBuf, size-i );
|
||||
ScalarRead( pRefBuf, pSrcBuf, size-i );
|
||||
|
||||
if( !(ret = cmp(pRefBuf, pDestBuf, size-i)) )
|
||||
{
|
||||
fprintf( stderr, "%d: \n", i );
|
||||
Diagnostic( pDestBuf, pRefBuf, size-i );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
DELETE( pSrcBuf );
|
||||
DELETE( pDestBuf );
|
||||
DELETE( pRefBuf );
|
||||
return ret;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static bool CheckMisalignedRead()
|
||||
{
|
||||
const std::size_t size = 1024;
|
||||
std::int32_t *pSrcBuf = NEW( std::int32_t, size );
|
||||
T *pDestBuf = NEW( T, size );
|
||||
T *pRefBuf = NEW( T, size );
|
||||
bool ret = true;
|
||||
|
||||
for( int j = 0; j < 8; ++j )
|
||||
{
|
||||
for( int i = 0; i < 8; ++i )
|
||||
{
|
||||
RandBuffer( pSrcBuf, size-i );
|
||||
Vector::FastSoundRead( pDestBuf+j, pSrcBuf, size-i-j );
|
||||
ScalarRead( pRefBuf+j, pSrcBuf, size-i-j );
|
||||
|
||||
if( !(ret = cmp(pRefBuf+j, pDestBuf+j, size-i-j)) )
|
||||
{
|
||||
fprintf( stderr, "%d, %d: \n", j, i );
|
||||
Diagnostic( pDestBuf+j, pRefBuf+j, size-i-j );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DELETE( pSrcBuf );
|
||||
DELETE( pDestBuf );
|
||||
DELETE( pRefBuf );
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
int main()
|
||||
{
|
||||
srand( time(NULL) );
|
||||
if( !Vector::CheckForVector() )
|
||||
{
|
||||
fputs( "No vector unit accessable.\n", stderr );
|
||||
return 1;
|
||||
}
|
||||
if( !CheckAlignedWrite() )
|
||||
{
|
||||
fputs( "Failed aligned write.\n", stderr );
|
||||
return 1;
|
||||
}
|
||||
if( !CheckMisalignedSrcWrite() )
|
||||
{
|
||||
fputs( "Failed misaligned source write.\n", stderr );
|
||||
return 1;
|
||||
}
|
||||
if( !CheckMisalignedDestWrite() )
|
||||
{
|
||||
fputs( "Failed misaligned destination write\n", stderr );
|
||||
return 1;
|
||||
}
|
||||
if( !CheckMisalignedBothWrite() )
|
||||
{
|
||||
fputs( "Failed misaligned source and destination write.\n", stderr );
|
||||
return 1;
|
||||
}
|
||||
#if 0
|
||||
if( !CheckAlignedRead<std::int16_t>() )
|
||||
{
|
||||
fputs( "Failed aligned read.\n", stderr );
|
||||
return 1;
|
||||
}
|
||||
if( !CheckAlignedRead<float>() )
|
||||
{
|
||||
fputs( "Failed aligned float read.\n", stderr );
|
||||
return 1;
|
||||
}
|
||||
if( !CheckMisalignedRead<std::int16_t>() )
|
||||
{
|
||||
fputs( "Failed misaligned read.\n", stderr );
|
||||
return 1;
|
||||
}
|
||||
if( !CheckMisalignedRead<float>() )
|
||||
{
|
||||
fputs( "Failed misaligned float read.\n", stderr );
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
puts( "Passed." );
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user