mirror of
https://github.com/bkaradzic/bx.git
synced 2026-02-21 06:13:08 +01:00
Merge branch 'master' of github.com:bkaradzic/bx
This commit is contained in:
@@ -20,6 +20,9 @@ namespace bx
|
||||
///
|
||||
WriterI* getStdErr();
|
||||
|
||||
///
|
||||
WriterI* getNullOut();
|
||||
|
||||
///
|
||||
class FileReader : public FileReaderI
|
||||
{
|
||||
|
||||
@@ -28,25 +28,6 @@ namespace bx
|
||||
return (m_z<<16)+m_w;
|
||||
}
|
||||
|
||||
inline RngFib::RngFib(uint32_t _a, uint32_t _b)
|
||||
: m_a(_a)
|
||||
, m_b(_b)
|
||||
{
|
||||
}
|
||||
|
||||
inline void RngFib::reset(uint32_t _a, uint32_t _b)
|
||||
{
|
||||
m_a = _a;
|
||||
m_b = _b;
|
||||
}
|
||||
|
||||
inline uint32_t RngFib::gen()
|
||||
{
|
||||
m_b = m_a+m_b;
|
||||
m_a = m_b-m_a;
|
||||
return m_a;
|
||||
}
|
||||
|
||||
inline RngShr3::RngShr3(uint32_t _jsr)
|
||||
: m_jsr(_jsr)
|
||||
{
|
||||
|
||||
@@ -112,7 +112,7 @@ BX_SIMD128_IMPLEMENT_TEST(xyzw , 0xf);
|
||||
}
|
||||
|
||||
template<>
|
||||
BX_SIMD_FORCE_INLINE simd128_langext_t simd_shuf_yBxA(simd128_langext_t _a, simd128_langext_t _b)
|
||||
BX_SIMD_FORCE_INLINE simd128_langext_t simd_shuf_AxBy(simd128_langext_t _a, simd128_langext_t _b)
|
||||
{
|
||||
simd128_langext_t result;
|
||||
result.vf = __builtin_shufflevector(_a.vf, _b.vf, 1, 5, 0, 4);
|
||||
|
||||
@@ -102,7 +102,7 @@ BX_SIMD128_IMPLEMENT_TEST(yzw, yzww);
|
||||
}
|
||||
|
||||
template<>
|
||||
BX_SIMD_FORCE_INLINE simd128_neon_t simd_shuf_yBxA(simd128_neon_t _a, simd128_neon_t _b)
|
||||
BX_SIMD_FORCE_INLINE simd128_neon_t simd_shuf_AxBy(simd128_neon_t _a, simd128_neon_t _b)
|
||||
{
|
||||
return __builtin_shuffle(_a, _b, (uint32x4_t){ 1, 5, 0, 4 });
|
||||
}
|
||||
|
||||
@@ -130,7 +130,7 @@ BX_SIMD128_IMPLEMENT_TEST(xyzw , 0xf);
|
||||
}
|
||||
|
||||
template<>
|
||||
BX_SIMD_FORCE_INLINE simd128_ref_t simd_shuf_yBxA(simd128_ref_t _a, simd128_ref_t _b)
|
||||
BX_SIMD_FORCE_INLINE simd128_ref_t simd_shuf_AxBy(simd128_ref_t _a, simd128_ref_t _b)
|
||||
{
|
||||
simd128_ref_t result;
|
||||
result.uxyzw[0] = _a.uxyzw[1];
|
||||
|
||||
@@ -90,7 +90,7 @@ BX_SIMD128_IMPLEMENT_TEST(xyzw , 0xf);
|
||||
}
|
||||
|
||||
template<>
|
||||
BX_SIMD_FORCE_INLINE simd128_sse_t simd_shuf_yBxA(simd128_sse_t _a, simd128_sse_t _b)
|
||||
BX_SIMD_FORCE_INLINE simd128_sse_t simd_shuf_AxBy(simd128_sse_t _a, simd128_sse_t _b)
|
||||
{
|
||||
return _mm_unpacklo_ps(_b, _a);
|
||||
}
|
||||
|
||||
@@ -30,24 +30,6 @@ namespace bx
|
||||
uint32_t m_w;
|
||||
};
|
||||
|
||||
/// George Marsaglia's FIB
|
||||
class RngFib
|
||||
{
|
||||
public:
|
||||
///
|
||||
RngFib(uint32_t _a = 9983651, uint32_t _b = 95746118);
|
||||
|
||||
///
|
||||
void reset(uint32_t _a = 9983651, uint32_t _b = 95746118);
|
||||
|
||||
///
|
||||
uint32_t gen();
|
||||
|
||||
private:
|
||||
uint32_t m_a;
|
||||
uint32_t m_b;
|
||||
};
|
||||
|
||||
/// George Marsaglia's SHR3
|
||||
class RngShr3
|
||||
{
|
||||
|
||||
@@ -101,7 +101,7 @@ BX_SIMD128_IMPLEMENT_TEST(xyzw);
|
||||
Ty simd_shuf_xAyB(Ty _a, Ty _b);
|
||||
|
||||
template<typename Ty>
|
||||
Ty simd_shuf_yBxA(Ty _a, Ty _b);
|
||||
Ty simd_shuf_AxBy(Ty _a, Ty _b);
|
||||
|
||||
template<typename Ty>
|
||||
Ty simd_shuf_zCwD(Ty _a, Ty _b);
|
||||
|
||||
@@ -303,6 +303,10 @@ extern "C" int printf(const char* _format, ...)
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct FILE
|
||||
{
|
||||
};
|
||||
|
||||
extern "C" int fprintf(FILE* _stream, const char* _format, ...)
|
||||
{
|
||||
BX_UNUSED(_stream, _format);
|
||||
|
||||
90
src/file.cpp
90
src/file.cpp
@@ -16,16 +16,51 @@
|
||||
|
||||
namespace bx
|
||||
{
|
||||
class NoopWriterImpl : public FileWriterI
|
||||
{
|
||||
public:
|
||||
NoopWriterImpl(void*)
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~NoopWriterImpl()
|
||||
{
|
||||
close();
|
||||
}
|
||||
|
||||
virtual bool open(const FilePath& _filePath, bool _append, Error* _err) override
|
||||
{
|
||||
BX_UNUSED(_filePath, _append, _err);
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual void close() override
|
||||
{
|
||||
}
|
||||
|
||||
virtual int64_t seek(int64_t _offset, Whence::Enum _whence) override
|
||||
{
|
||||
BX_UNUSED(_offset, _whence);
|
||||
return 0;
|
||||
}
|
||||
|
||||
virtual int32_t write(const void* _data, int32_t _size, Error* _err) override
|
||||
{
|
||||
BX_UNUSED(_data, _size, _err);
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
#if BX_CONFIG_CRT_FILE_READER_WRITER
|
||||
|
||||
# if BX_CRT_MSVC
|
||||
# define fseeko64 _fseeki64
|
||||
# define ftello64 _ftelli64
|
||||
# elif 0 \
|
||||
# elif 0 \
|
||||
|| BX_PLATFORM_ANDROID \
|
||||
|| BX_PLATFORM_BSD \
|
||||
|| BX_PLATFORM_IOS \
|
||||
|| BX_PLATFORM_OSX \
|
||||
|| BX_PLATFORM_BSD \
|
||||
|| BX_PLATFORM_IOS \
|
||||
|| BX_PLATFORM_OSX \
|
||||
|| BX_PLATFORM_QNX
|
||||
# define fseeko64 fseeko
|
||||
# define ftello64 ftello
|
||||
@@ -34,7 +69,7 @@ namespace bx
|
||||
# define ftello64 ftell
|
||||
# endif // BX_
|
||||
|
||||
class FileReaderImpl : public bx::FileReaderI
|
||||
class FileReaderImpl : public FileReaderI
|
||||
{
|
||||
public:
|
||||
FileReaderImpl(FILE* _file)
|
||||
@@ -114,7 +149,7 @@ namespace bx
|
||||
bool m_open;
|
||||
};
|
||||
|
||||
class FileWriterImpl : public bx::FileWriterI
|
||||
class FileWriterImpl : public FileWriterI
|
||||
{
|
||||
public:
|
||||
FileWriterImpl(FILE* _file)
|
||||
@@ -189,7 +224,7 @@ namespace bx
|
||||
|
||||
#else
|
||||
|
||||
class FileReaderImpl : public bx::FileReaderI
|
||||
class FileReaderImpl : public FileReaderI
|
||||
{
|
||||
public:
|
||||
FileReaderImpl(void*)
|
||||
@@ -224,40 +259,7 @@ namespace bx
|
||||
}
|
||||
};
|
||||
|
||||
class FileWriterImpl : public bx::FileWriterI
|
||||
{
|
||||
public:
|
||||
FileWriterImpl(void*)
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~FileWriterImpl()
|
||||
{
|
||||
close();
|
||||
}
|
||||
|
||||
virtual bool open(const FilePath& _filePath, bool _append, Error* _err) override
|
||||
{
|
||||
BX_UNUSED(_filePath, _append);
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual void close() override
|
||||
{
|
||||
}
|
||||
|
||||
virtual int64_t seek(int64_t _offset, Whence::Enum _whence) override
|
||||
{
|
||||
BX_UNUSED(_offset, _whence);
|
||||
return 0;
|
||||
}
|
||||
|
||||
virtual int32_t write(const void* _data, int32_t _size, Error* _err) override
|
||||
{
|
||||
BX_UNUSED(_data, _size, _err);
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
typedef NoopWriterImpl FileWriterImpl;
|
||||
|
||||
#endif // BX_CONFIG_CRT_FILE_READER_WRITER
|
||||
|
||||
@@ -351,6 +353,12 @@ namespace bx
|
||||
return &s_stdOut;
|
||||
}
|
||||
|
||||
WriterI* getNullOut()
|
||||
{
|
||||
static NoopWriterImpl s_nullOut(NULL);
|
||||
return &s_nullOut;
|
||||
}
|
||||
|
||||
bool stat(const char* _filePath, FileInfo& _fileInfo)
|
||||
{
|
||||
_fileInfo.m_size = 0;
|
||||
|
||||
@@ -10,52 +10,49 @@
|
||||
|
||||
TEST_CASE("easing", "")
|
||||
{
|
||||
if (BX_ENABLED(false) )
|
||||
bx::WriterI* writer = bx::getNullOut();
|
||||
|
||||
for (uint32_t ee = 0; ee < bx::Easing::Count; ++ee)
|
||||
{
|
||||
bx::WriterI* writer = bx::getStdOut();
|
||||
bx::writePrintf(writer, "\n\n%d\n", ee);
|
||||
|
||||
for (uint32_t ee = 0; ee < bx::Easing::Count; ++ee)
|
||||
const bx::EaseFn easing = bx::getEaseFunc(bx::Easing::Enum(ee) );
|
||||
|
||||
const int32_t nx = 64;
|
||||
const int32_t ny = 10;
|
||||
|
||||
bx::writePrintf(writer, "\t/// ^\n");
|
||||
|
||||
for (int32_t yy = ny+4; yy >= -5; --yy)
|
||||
{
|
||||
bx::writePrintf(writer, "\n\n%d\n", ee);
|
||||
const float ys = float(yy )/float(ny);
|
||||
const float ye = float(yy+1.0)/float(ny);
|
||||
|
||||
const bx::EaseFn easing = bx::getEaseFunc(bx::Easing::Enum(ee) );
|
||||
bx::writePrintf(writer, "\t/// %c", yy != 0 ? '|' : '+');
|
||||
|
||||
const int32_t nx = 64;
|
||||
const int32_t ny = 10;
|
||||
|
||||
bx::writePrintf(writer, "\t/// ^\n");
|
||||
|
||||
for (int32_t yy = ny+4; yy >= -5; --yy)
|
||||
for (int32_t xx = 0; xx < nx; ++xx)
|
||||
{
|
||||
const float ys = float(yy )/float(ny);
|
||||
const float ye = float(yy+1.0)/float(ny);
|
||||
|
||||
bx::writePrintf(writer, "\t/// %c", yy != 0 ? '|' : '+');
|
||||
|
||||
for (int32_t xx = 0; xx < nx; ++xx)
|
||||
int32_t jj = 0;
|
||||
for (; jj < 10; ++jj)
|
||||
{
|
||||
int32_t jj = 0;
|
||||
for (; jj < 10; ++jj)
|
||||
{
|
||||
const float tt = float(xx*10+jj)/10.0f/float(nx);
|
||||
const float vv = easing(tt);
|
||||
const float tt = float(xx*10+jj)/10.0f/float(nx);
|
||||
const float vv = easing(tt);
|
||||
|
||||
if (vv >= ys
|
||||
&& vv < ye)
|
||||
{
|
||||
bx::writePrintf(writer, "*");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (jj == 10)
|
||||
if (vv >= ys
|
||||
&& vv < ye)
|
||||
{
|
||||
bx::writePrintf(writer, "%c", yy != 0 ? ' ' : '-');
|
||||
bx::writePrintf(writer, "*");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bx::writePrintf(writer, "%s\n", yy != 0 ? "" : ">");
|
||||
if (jj == 10)
|
||||
{
|
||||
bx::writePrintf(writer, "%c", yy != 0 ? ' ' : '-');
|
||||
}
|
||||
}
|
||||
|
||||
bx::writePrintf(writer, "%s\n", yy != 0 ? "" : ">");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
88
tests/rng_test.cpp
Normal file
88
tests/rng_test.cpp
Normal file
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Copyright 2010-2017 Branimir Karadzic. All rights reserved.
|
||||
* License: https://github.com/bkaradzic/bx#license-bsd-2-clause
|
||||
*/
|
||||
|
||||
#include "test.h"
|
||||
|
||||
#include <bx/rng.h>
|
||||
#include <bx/file.h>
|
||||
|
||||
const uint32_t kMax = 10<<20;
|
||||
|
||||
template<typename Ty>
|
||||
void testRng(const char* _name, Ty* _rng)
|
||||
{
|
||||
uint32_t histBits[32];
|
||||
uint32_t histUint8[256];
|
||||
|
||||
bx::memSet(histBits, 0, sizeof(histBits) );
|
||||
bx::memSet(histUint8, 0, sizeof(histUint8) );
|
||||
|
||||
for (uint32_t ii = 0; ii < kMax; ++ii)
|
||||
{
|
||||
uint32_t val = _rng->gen();
|
||||
|
||||
for (uint32_t shift = 0; shift < 32; ++shift)
|
||||
{
|
||||
const uint32_t mask = 1<<shift;
|
||||
histBits[shift] += !!(0 != (val & mask) );
|
||||
}
|
||||
|
||||
const uint32_t mf000 = (val & 0xff000000)>>24;
|
||||
const uint32_t m0f00 = (val & 0x00ff0000)>>16;
|
||||
const uint32_t m00f0 = (val & 0x0000ff00)>> 8;
|
||||
const uint32_t m000f = (val & 0x000000ff)>> 0;
|
||||
|
||||
histUint8[mf000]++;
|
||||
histUint8[m0f00]++;
|
||||
histUint8[m00f0]++;
|
||||
histUint8[m000f]++;
|
||||
}
|
||||
|
||||
bx::WriterI* writer = bx::getNullOut();
|
||||
bx::writePrintf(writer, "%s\n", _name);
|
||||
|
||||
{
|
||||
bx::writePrintf(writer, "\tbits histogram:\n");
|
||||
uint32_t min = UINT32_MAX;
|
||||
uint32_t max = 0;
|
||||
|
||||
for (uint32_t ii = 0; ii < BX_COUNTOF(histBits); ++ii)
|
||||
{
|
||||
bx::writePrintf(writer, "\t\t%3d: %d\n", ii, histBits[ii]);
|
||||
min = bx::min(min, histBits[ii]);
|
||||
max = bx::max(max, histBits[ii]);
|
||||
}
|
||||
|
||||
bx::writePrintf(writer, "\tmin: %d, max: %d (diff: %d)\n", min, max, max-min);
|
||||
|
||||
REQUIRE(max-min < 8000);
|
||||
}
|
||||
|
||||
{
|
||||
bx::writePrintf(writer, "\tuint8_t histogram:\n");
|
||||
uint32_t min = UINT32_MAX;
|
||||
uint32_t max = 0;
|
||||
|
||||
for (uint32_t ii = 0; ii < BX_COUNTOF(histUint8); ++ii)
|
||||
{
|
||||
bx::writePrintf(writer, "\t\t%3d: %d\n", ii, histUint8[ii]);
|
||||
min = bx::min(min, histUint8[ii]);
|
||||
max = bx::max(max, histUint8[ii]);
|
||||
}
|
||||
|
||||
bx::writePrintf(writer, "\tmin: %d, max: %d (diff: %d)\n", min, max, max-min);
|
||||
|
||||
REQUIRE(max-min < 8000);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("Rng", "")
|
||||
{
|
||||
bx::RngMwc mwc;
|
||||
testRng("RngMwc", &mwc);
|
||||
|
||||
bx::RngShr3 shr3;
|
||||
testRng("RngShr3", &shr3);
|
||||
}
|
||||
@@ -235,13 +235,14 @@ TEST_CASE("simd_shuffle", "")
|
||||
const simd128_t ABCD = simd_ild(0x41414141, 0x42424242, 0x43434343, 0x44444444);
|
||||
simd_check_string("xyAB", simd_shuf_xyAB(xyzw, ABCD) );
|
||||
simd_check_string("ABxy", simd_shuf_ABxy(xyzw, ABCD) );
|
||||
simd_check_string("zwCD", simd_shuf_zwCD(xyzw, ABCD) );
|
||||
simd_check_string("CDzw", simd_shuf_CDzw(xyzw, ABCD) );
|
||||
simd_check_string("zwCD", simd_shuf_zwCD(xyzw, ABCD) );
|
||||
simd_check_string("xAyB", simd_shuf_xAyB(xyzw, ABCD) );
|
||||
simd_check_string("AxBy", simd_shuf_AxBy(xyzw, ABCD) );
|
||||
simd_check_string("zCwD", simd_shuf_zCwD(xyzw, ABCD) );
|
||||
simd_check_string("CzDw", simd_shuf_CzDw(xyzw, ABCD) );
|
||||
simd_check_string("xAzC", simd_shuf_xAzC(xyzw, ABCD) );
|
||||
simd_check_string("yBwD", simd_shuf_yBwD(xyzw, ABCD) );
|
||||
simd_check_string("CzDw", simd_shuf_CzDw(xyzw, ABCD) );
|
||||
}
|
||||
|
||||
TEST_CASE("simd_compare", "")
|
||||
|
||||
Reference in New Issue
Block a user