Skip to content

Commit

Permalink
Merge pull request #62 from juj/add_avx_tests
Browse files Browse the repository at this point in the history
Add AVX testing
  • Loading branch information
juj authored May 14, 2020
2 parents 559beba + 42acd0f commit 923e6e2
Show file tree
Hide file tree
Showing 11 changed files with 88 additions and 25 deletions.
43 changes: 42 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: 2.1

jobs:
build:
linux_test_scalar:
docker:
- image: "debian:stretch"
steps:
Expand All @@ -18,3 +18,44 @@ jobs:
- run:
name: Test
command: './build/MathGeoLib 10 10'
linux_test_avx:
docker:
- image: "debian:stretch"
steps:
- checkout
- run:
name: Installing via apt-get
command: 'apt-get update && apt-get install -y sudo gcc g++ cmake && rm -rf /var/lib/apt/lists/*'
- run:
name: CMake
command: 'cmake -H. -Bbuild -DMATH_AVX=1 -DMATH_TESTS_EXECUTABLE=1 -DFAIL_USING_EXCEPTIONS=1 -DMATH_ENABLE_UNCOMMON_OPERATIONS=1'
- run:
name: Build
command: 'cmake --build build'
- run:
name: Test
command: './build/MathGeoLib 10 10'
linux_test_sse41:
docker:
- image: "debian:stretch"
steps:
- checkout
- run:
name: Installing via apt-get
command: 'apt-get update && apt-get install -y sudo gcc g++ cmake && rm -rf /var/lib/apt/lists/*'
- run:
name: CMake
command: 'cmake -H. -Bbuild -DMATH_SSE41=1 -DMATH_TESTS_EXECUTABLE=1 -DFAIL_USING_EXCEPTIONS=1 -DMATH_ENABLE_UNCOMMON_OPERATIONS=1'
- run:
name: Build
command: 'cmake --build build'
- run:
name: Test
command: './build/MathGeoLib 10 10'
workflows:
version: 2.1
builds:
jobs:
- linux_test_scalar
- linux_test_avx
- linux_test_sse41
6 changes: 3 additions & 3 deletions src/Geometry/Ray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,14 +362,14 @@ void Ray::ProjectToAxis(const vec &direction, float &outMin, float &outMax) cons
}

#if defined(MATH_ENABLE_STL_SUPPORT) || defined(MATH_CONTAINERLIB_SUPPORT)
String Ray::ToString() const
StringT Ray::ToString() const
{
char str[256];
sprintf(str, "Ray(Pos:(%.2f, %.2f, %.2f) Dir:(%.3f, %.3f, %.3f))", pos.x, pos.y, pos.z, dir.x, dir.y, dir.z);
return str;
}

String Ray::SerializeToString() const
StringT Ray::SerializeToString() const
{
char str[256];
char *s = SerializeFloat(pos.x, str); *s = ','; ++s;
Expand All @@ -383,7 +383,7 @@ String Ray::SerializeToString() const
return str;
}

String Ray::SerializeToCodeString() const
StringT Ray::SerializeToCodeString() const
{
return "Ray(" + pos.SerializeToCodeString() + "," + dir.SerializeToCodeString() + ")";
}
Expand Down
2 changes: 1 addition & 1 deletion src/Geometry/Triangle2D.h
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ class Triangle2D

/// Returns a string of C++ code that can be used to construct this object. Useful for generating test cases from badly behaving objects.
StringT SerializeToCodeString() const;
static Triangle2D FromString(const String &str) { return FromString(str.c_str()); }
static Triangle2D FromString(const StringT &str) { return FromString(str.c_str()); }
#endif

static Triangle2D FromString(const char *str, const char **outEndStr = 0);
Expand Down
2 changes: 1 addition & 1 deletion src/Math/MathTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
// If we have C99, take the types from there.
#if (__STDC_VERSION__ >= 199901L) || (_MSC_VER >= 1600)

#include <cstdint>
#include <stdint.h>

typedef uint8_t u8; ///< a single byte: 0-255.
typedef uint16_t u16; ///< 2 bytes: 0 - 65535.
Expand Down
4 changes: 2 additions & 2 deletions src/Math/Quat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ void Quat::Set(float x_, float y_, float z_, float w_)
void Quat::Set(const Quat &q)
{
#ifdef MATH_AUTOMATIC_SSE
v = q.v;
this->q = q.q;
#else
x = q.x;
y = q.y;
Expand All @@ -606,7 +606,7 @@ void Quat::Set(const Quat &q)
void Quat::Set(const float4 &vec)
{
#ifdef MATH_AUTOMATIC_SSE
v = vec.v;
q = vec.v;
#else
x = vec.x;
y = vec.y;
Expand Down
21 changes: 17 additions & 4 deletions src/Math/assume.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "../MathBuildConfig.h"
#ifdef MATH_ENABLE_STL_SUPPORT
#include <sstream>
#include <string>
#endif
#include "MathNamespace.h"
#include <stdio.h>
Expand Down Expand Up @@ -90,13 +91,13 @@ inline StringT ObjToString(const T &obj)
{
return obj.ToString();
}
/*

template<>
inline std::string ObjToString<const char*>(const char * const & obj)
inline StringT ObjToString<const char * const>(const char * const & obj)
{
return obj;
return StringT(obj);
}
*/

template<>
inline StringT ObjToString<StringT>(const StringT &obj)
{
Expand Down Expand Up @@ -157,6 +158,18 @@ inline StringT ObjToString<u32>(const u32 &obj)
#endif
}

template<>
inline StringT ObjToString<u64>(const u64 &obj)
{
#if defined(MATH_CONTAINERLIB_SUPPORT)
return String::FromUInt64(obj);
#else
std::stringstream ss;
ss << obj;
return ss.str();
#endif
}

MATH_END_NAMESPACE

// If MATH_ENABLE_INSECURE_OPTIMIZATIONS is defined, all input data is assumed to be correct and will
Expand Down
3 changes: 0 additions & 3 deletions src/Math/float2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,6 @@ void float2::ConvexHull(const float2 *pointArray, int numPoints, std::vector<flo
}
#endif

#ifdef MATH_ENABLE_STL_SUPPORT
/** This function implements the Graham's Scan algorithm for finding the convex hull of
a 2D point set. The running time is O(nlogn). For details, see
"Introduction to Algorithms, 2nd ed.", by Cormen, Leiserson, Rivest, p.824, or
Expand All @@ -537,8 +536,6 @@ bool float2::ConvexHullContains(const float2 *convexHull, int numPointsInConvexH
return true;
}

#endif // ~MATH_ENABLE_STL_SUPPORT

#define NEXT_P(ptr) ((ptr)+1 < (pEnd) ? (ptr)+1 : (p))

float float2::MinAreaRectInPlace(float2 *p, int n, float2 &center, float2 &uDir, float2 &vDir, float &minU, float &maxU, float &minV, float &maxV)
Expand Down
9 changes: 7 additions & 2 deletions src/Math/grisu3.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
http://www.cs.tufts.edu/~nr/cs257/archive/florian-loitsch/printf.pdf */
#pragma once

#include "../MathBuildConfig.h"

#include <stdint.h>

#ifdef __cplusplus
Expand Down Expand Up @@ -60,9 +62,12 @@ int i32_to_string(int i, char *dst);

#ifdef __cplusplus

#ifdef MATH_ENABLE_STL_SUPPORT
#if defined(MATH_ENABLE_STL_SUPPORT)
#include <string>
std::string dtoa_grisu3_string(double v);
#endif

#if defined(MATH_ENABLE_STL_SUPPORT) || defined(MATH_CONTAINERLIB_SUPPORT)
StringT dtoa_grisu3_string(double v);
#endif

#endif
9 changes: 6 additions & 3 deletions src/Math/grisu3_cpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
http://www.cs.tufts.edu/~nr/cs257/archive/florian-loitsch/printf.pdf */

#include "grisu3.h"
#ifdef MATH_ENABLE_STL_SUPPORT
#include <string>
#include "../MathBuildConfig.h"
#if defined(MATH_CONTAINERLIB_SUPPORT)
#include "Container/UString.h"
#endif
#if defined(MATH_ENABLE_STL_SUPPORT) || defined(MATH_CONTAINERLIB_SUPPORT)
#include <assert.h>

std::string dtoa_grisu3_string(double v)
StringT dtoa_grisu3_string(double v)
{
char str[32];
int len = dtoa_grisu3(v, str);
Expand Down
8 changes: 6 additions & 2 deletions src/MathBuildConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
// features requiring STL are disabled (but the library can still be built).
// Due to large increase in code size, when building for HTML5 platform, do not automatically
// enable STL support
#if !defined(MATH_ENABLE_STL_SUPPORT) && !defined(__EMSCRIPTEN__)
#if !defined(MATH_ENABLE_STL_SUPPORT) && !defined(MATH_DISABLE_STL_SUPPORT)
#define MATH_ENABLE_STL_SUPPORT
#endif

Expand Down Expand Up @@ -126,7 +126,7 @@
// If MATH_COLMAJOR_MATRICES is defined, matrices use a column-major memory layout. If undefined, matrices
// use a row-major memory layout.
#ifndef MATH_COLMAJOR_MATRICES
#define MATH_COLMAJOR_MATRICES
// #define MATH_COLMAJOR_MATRICES
#endif

#if defined(MATH_USE_DIRECT3D) && defined(MATH_USE_OPENGL)
Expand Down Expand Up @@ -227,11 +227,15 @@ typedef __m128 simd4f;
#define MATH_AUTOMATIC_SIMD_FLOAT3
#endif

#ifdef __cplusplus

#ifdef MATH_CONTAINERLIB_SUPPORT
class String;
#define StringT String
#else
#define StringT std::string
#endif

#endif

#include "Math/MathTypes.h"
6 changes: 3 additions & 3 deletions tests/KdTreeTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ UNIQUE_TEST(KdTree_SingleTriangle_AABBQuery)
// Build the tree
KdTree<Triangle> tree;

Triangle triangle(float3::zero, float3::unitX, float3::unitY);
Triangle triangle(POINT_VEC_SCALAR(0.f), POINT_VEC(1.f, 0.f, 0.f), POINT_VEC(0.f, 1.f, 0.f));

tree.AddObjects(&triangle, 1);
tree.Build();

// Query
AABB bbox(float3::one * -10, float3::one * 10);
AABB bbox(POINT_VEC_SCALAR(-10.f), POINT_VEC_SCALAR(10.f));

bool intersected = false;
auto callback = [&](const KdTree<Triangle>& tree, const KdTreeNode& leaf, const AABB& aabb)
auto callback = [&](const KdTree<Triangle>& tree, const KdTreeNode& leaf, const AABB& /*aabb*/)
{
auto bucket = tree.Bucket(leaf.bucketIndex);
auto triangle = tree.Object(*bucket);
Expand Down

0 comments on commit 923e6e2

Please sign in to comment.