From c4500ef41e4edb83661d5857f2e62497134d06b0 Mon Sep 17 00:00:00 2001 From: torss <37229901+torss@users.noreply.github.com> Date: Sun, 11 Mar 2018 02:14:37 +0100 Subject: [PATCH 01/20] Add rudimentary CMake support --- CMakeLists.txt | 91 +++++++++++++++++++++++++++++++++++ FastNoiseSIMD/FastNoiseSIMD.h | 14 +++--- 2 files changed, 98 insertions(+), 7 deletions(-) create mode 100644 CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..55eb64a --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,91 @@ +# This is currently very rudimentary and likely needs various improvements. + +cmake_minimum_required(VERSION 3.7) # Requiring 3.7 might be incorrect. +project(FastNoiseSIMD) + +set(CMAKE_CXX_STANDARD 11) # Requiring C++11 might be incorrect. +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) + +set(directory ${PROJECT_NAME}) +set(library_name ${PROJECT_NAME}) +set(file_prefix ${PROJECT_NAME}) + +set_property(DIRECTORY ${PROJECT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT ${library_name}) + +if(CMAKE_SYSTEM_PROCESSOR MATCHES "arm" OR CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64") + option(FN_COMPILE_NEON + "Only on arm or aarch64." + ON) +endif() + +option(FN_COMPILE_SSE2 + "" + ON) +option(FN_COMPILE_SSE41 + "" + ON) +option(FN_COMPILE_AVX2 + "This does not break support for pre AVX CPUs, AVX code is only run if support is detected." + OFF) +option(FN_COMPILE_AVX512 + "Only the latest compilers will support this." + OFF) +option(FN_USE_FMA + "Using FMA instructions with AVX(51)2/NEON provides a small performance increase but can cause \ +minute variations in noise output compared to other SIMD levels due to higher calculation precision." + ON) +option(FN_ALIGNED_SETS + "Using aligned sets of memory for float arrays allows faster storing of SIMD data." + ON) + +configure_file(${directory}/${file_prefix}.h include/${file_prefix}.h) + +set(flags) +if(${MSVC}) + if(${FN_COMPILE_AVX2} OR ${FN_COMPILE_AVX512}) + list(APPEND flags "/arch:AVX2") + endif() +elseif() + if(${FN_COMPILE_AVX2} OR ${FN_COMPILE_AVX512}) + list(APPEND flags "-march=core-avx2") + endif() +endif() + +add_library(${library_name} STATIC + ${directory}/${file_prefix}.cpp + ${directory}/${file_prefix}_avx2.cpp + ${directory}/${file_prefix}_avx512.cpp + ${directory}/${file_prefix}_internal.cpp + ${directory}/${file_prefix}_neon.cpp + ${directory}/${file_prefix}_sse2.cpp + ${directory}/${file_prefix}_sse41.cpp + ) + +target_include_directories(${library_name} PRIVATE + ${CMAKE_CURRENT_BINARY_DIR}/include + ${directory}/ + ) + +set(public_headers + ${CMAKE_CURRENT_BINARY_DIR}/include/${file_prefix}.h + # ${directory}/${file_prefix}_internal.h + ) +set_target_properties(${library_name} PROPERTIES + PUBLIC_HEADER "${public_headers}" + ) + +target_compile_options(${library_name} PRIVATE + "${flags}" + ) + +install(TARGETS ${library_name} + CONFIGURATIONS Debug + ARCHIVE DESTINATION lib/Debug + PUBLIC_HEADER DESTINATION include + ) +install(TARGETS ${library_name} + CONFIGURATIONS Release + ARCHIVE DESTINATION lib/Release + PUBLIC_HEADER DESTINATION include + ) diff --git a/FastNoiseSIMD/FastNoiseSIMD.h b/FastNoiseSIMD/FastNoiseSIMD.h index 22a3945..00dc65c 100644 --- a/FastNoiseSIMD/FastNoiseSIMD.h +++ b/FastNoiseSIMD/FastNoiseSIMD.h @@ -34,29 +34,29 @@ #if defined(__arm__) || defined(__aarch64__) #define FN_ARM //#define FN_IOS -#define FN_COMPILE_NEON +#cmakedefine FN_COMPILE_NEON #else // Comment out lines to not compile for certain instruction sets -#define FN_COMPILE_SSE2 -#define FN_COMPILE_SSE41 +#cmakedefine FN_COMPILE_SSE2 +#cmakedefine FN_COMPILE_SSE41 // To compile AVX2 set C++ code generation to use /arch:AVX(2) on FastNoiseSIMD_avx2.cpp // Note: This does not break support for pre AVX CPUs, AVX code is only run if support is detected -#define FN_COMPILE_AVX2 +#cmakedefine FN_COMPILE_AVX2 // Only the latest compilers will support this -//#define FN_COMPILE_AVX512 +#cmakedefine FN_COMPILE_AVX512 // Using FMA instructions with AVX(51)2/NEON provides a small performance increase but can cause // minute variations in noise output compared to other SIMD levels due to higher calculation precision // Intel compiler will always generate FMA instructions, use /Qfma- or -no-fma to disable -#define FN_USE_FMA +#cmakedefine FN_USE_FMA #endif // Using aligned sets of memory for float arrays allows faster storing of SIMD data // Comment out to allow unaligned float arrays to be used as sets -#define FN_ALIGNED_SETS +#cmakedefine FN_ALIGNED_SETS // SSE2/NEON support is guaranteed on 64bit CPUs so no fallback is needed #if !(defined(_WIN64) || defined(__x86_64__) || defined(__ppc64__) || defined(__aarch64__) || defined(FN_IOS)) || defined(_DEBUG) From 1c35a41d1c90561436a8314c1ac2999430110f47 Mon Sep 17 00:00:00 2001 From: torss <37229901+torss@users.noreply.github.com> Date: Sun, 11 Mar 2018 02:18:15 +0100 Subject: [PATCH 02/20] Add .cmake postfix to FastNoiseSIMD.h filename --- CMakeLists.txt | 2 +- FastNoiseSIMD/{FastNoiseSIMD.h => FastNoiseSIMD.cmake.h} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename FastNoiseSIMD/{FastNoiseSIMD.h => FastNoiseSIMD.cmake.h} (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 55eb64a..8785eee 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,7 +39,7 @@ option(FN_ALIGNED_SETS "Using aligned sets of memory for float arrays allows faster storing of SIMD data." ON) -configure_file(${directory}/${file_prefix}.h include/${file_prefix}.h) +configure_file(${directory}/${file_prefix}.cmake.h include/${file_prefix}.h) set(flags) if(${MSVC}) diff --git a/FastNoiseSIMD/FastNoiseSIMD.h b/FastNoiseSIMD/FastNoiseSIMD.cmake.h similarity index 100% rename from FastNoiseSIMD/FastNoiseSIMD.h rename to FastNoiseSIMD/FastNoiseSIMD.cmake.h From 8a2e6d7873bbc9af0042459f07ab3c76863d2825 Mon Sep 17 00:00:00 2001 From: KdotJPG Date: Sun, 26 Jan 2020 22:00:41 -0500 Subject: [PATCH 03/20] Add OpenSimplex2 alternative to Simplex --- FastNoiseSIMD/FastNoiseSIMD.cpp | 15 +++++ FastNoiseSIMD/FastNoiseSIMD.h | 9 ++- FastNoiseSIMD/FastNoiseSIMD_internal.cpp | 84 +++++++++++++++++++++++- FastNoiseSIMD/FastNoiseSIMD_internal.h | 5 ++ 4 files changed, 109 insertions(+), 4 deletions(-) diff --git a/FastNoiseSIMD/FastNoiseSIMD.cpp b/FastNoiseSIMD/FastNoiseSIMD.cpp index cbac32a..5a25b62 100644 --- a/FastNoiseSIMD/FastNoiseSIMD.cpp +++ b/FastNoiseSIMD/FastNoiseSIMD.cpp @@ -422,6 +422,12 @@ void FastNoiseSIMD::FillNoiseSet(float* noiseSet, int xStart, int yStart, int zS case SimplexFractal: FillSimplexFractalSet(noiseSet, xStart, yStart, zStart, xSize, ySize, zSize, scaleModifier); break; + case OpenSimplex2: + FillOpenSimplex2Set(noiseSet, xStart, yStart, zStart, xSize, ySize, zSize, scaleModifier); + break; + case OpenSimplex2Fractal: + FillOpenSimplex2FractalSet(noiseSet, xStart, yStart, zStart, xSize, ySize, zSize, scaleModifier); + break; case WhiteNoise: FillWhiteNoiseSet(noiseSet, xStart, yStart, zStart, xSize, ySize, zSize, scaleModifier); break; @@ -461,6 +467,12 @@ void FastNoiseSIMD::FillNoiseSet(float* noiseSet, FastNoiseVectorSet* vectorSet, case SimplexFractal: FillSimplexFractalSet(noiseSet, vectorSet, xOffset, yOffset, zOffset); break; + case OpenSimplex2: + FillOpenSimplex2Set(noiseSet, vectorSet, xOffset, yOffset, zOffset); + break; + case OpenSimplex2Fractal: + FillOpenSimplex2FractalSet(noiseSet, vectorSet, xOffset, yOffset, zOffset); + break; case WhiteNoise: FillWhiteNoiseSet(noiseSet, vectorSet, xOffset, yOffset, zOffset); break; @@ -508,6 +520,9 @@ GET_SET(PerlinFractal) GET_SET(Simplex) GET_SET(SimplexFractal) +GET_SET(OpenSimplex2) +GET_SET(OpenSimplex2Fractal) + GET_SET(Cellular) GET_SET(Cubic) diff --git a/FastNoiseSIMD/FastNoiseSIMD.h b/FastNoiseSIMD/FastNoiseSIMD.h index 22a3945..002e099 100644 --- a/FastNoiseSIMD/FastNoiseSIMD.h +++ b/FastNoiseSIMD/FastNoiseSIMD.h @@ -102,7 +102,7 @@ class FastNoiseSIMD { public: - enum NoiseType { Value, ValueFractal, Perlin, PerlinFractal, Simplex, SimplexFractal, WhiteNoise, Cellular, Cubic, CubicFractal }; + enum NoiseType { Value, ValueFractal, Perlin, PerlinFractal, Simplex, SimplexFractal, OpenSimplex2, OpenSimplex2Fractal, WhiteNoise, Cellular, Cubic, CubicFractal }; enum FractalType { FBM, Billow, RigidMulti }; enum PerturbType { None, Gradient, GradientFractal, Normalise, Gradient_Normalise, GradientFractal_Normalise }; @@ -279,6 +279,13 @@ class FastNoiseSIMD virtual void FillSimplexSet(float* noiseSet, FastNoiseVectorSet* vectorSet, float xOffset = 0.0f, float yOffset = 0.0f, float zOffset = 0.0f) = 0; virtual void FillSimplexFractalSet(float* noiseSet, FastNoiseVectorSet* vectorSet, float xOffset = 0.0f, float yOffset = 0.0f, float zOffset = 0.0f) = 0; + float* GetOpenSimplex2Set(int xStart, int yStart, int zStart, int xSize, int ySize, int zSize, float scaleModifier = 1.0f); + float* GetOpenSimplex2FractalSet(int xStart, int yStart, int zStart, int xSize, int ySize, int zSize, float scaleModifier = 1.0f); + virtual void FillOpenSimplex2Set(float* noiseSet, int xStart, int yStart, int zStart, int xSize, int ySize, int zSize, float scaleModifier = 1.0f) = 0; + virtual void FillOpenSimplex2FractalSet(float* noiseSet, int xStart, int yStart, int zStart, int xSize, int ySize, int zSize, float scaleModifier = 1.0f) = 0; + virtual void FillOpenSimplex2Set(float* noiseSet, FastNoiseVectorSet* vectorSet, float xOffset = 0.0f, float yOffset = 0.0f, float zOffset = 0.0f) = 0; + virtual void FillOpenSimplex2FractalSet(float* noiseSet, FastNoiseVectorSet* vectorSet, float xOffset = 0.0f, float yOffset = 0.0f, float zOffset = 0.0f) = 0; + float* GetCellularSet(int xStart, int yStart, int zStart, int xSize, int ySize, int zSize, float scaleModifier = 1.0f); virtual void FillCellularSet(float* noiseSet, int xStart, int yStart, int zStart, int xSize, int ySize, int zSize, float scaleModifier = 1.0f) = 0; virtual void FillCellularSet(float* noiseSet, FastNoiseVectorSet* vectorSet, float xOffset = 0.0f, float yOffset = 0.0f, float zOffset = 0.0f) = 0; diff --git a/FastNoiseSIMD/FastNoiseSIMD_internal.cpp b/FastNoiseSIMD/FastNoiseSIMD_internal.cpp index 5f850bc..67bd076 100644 --- a/FastNoiseSIMD/FastNoiseSIMD_internal.cpp +++ b/FastNoiseSIMD/FastNoiseSIMD_internal.cpp @@ -191,8 +191,8 @@ static SIMDf VECTORCALL FUNC(FLOOR)(SIMDf a) SIMDf fval = SIMDf_CONVERT_TO_FLOAT(SIMDi_CONVERT_TO_INT(a)); return vsubq_f32(fval, - SIMDf_CAST_TO_FLOAT(vandq_s32(SIMDf_LESS_THAN(a, fval), - SIMDi_CAST_TO_INT(SIMDf_NUM(1))))); + SIMDf_CAST_TO_FLOAT(vandq_s32(SIMDf_LESS_THAN(a, fval), + SIMDi_CAST_TO_INT(SIMDf_NUM(1))))); } #define SIMDf_FLOOR(a) FUNC(FLOOR)(a) #else @@ -446,7 +446,7 @@ static float FUNC(INV_SQRT)(float x) int i = *(int*)&x; i = 0x5f3759df - (i >> 1); x = *(float*)&i; - x = x*(1.5f - xhalf*x*x); + x = x * (1.5f - xhalf * x*x); return x; } #define SIMDf_INV_SQRT(a) FUNC(INV_SQRT)(a) @@ -461,6 +461,7 @@ static float FUNC(INV_SQRT)(float x) #define SIMDf_XOR(a,b) SIMDf_CAST_TO_FLOAT(SIMDi_CAST_TO_INT(a) ^ SIMDi_CAST_TO_INT(b)) #define SIMDf_FLOOR(a) floorf(a) +#define SIMDf_ROUND(a) roundf(a) #define SIMDf_ABS(a) fabsf(a) #define SIMDf_BLENDV(a,b,mask) (mask ? (b) : (a)) #define SIMDf_GATHER(p,a) (*(reinterpret_cast(p)+(a))) @@ -566,15 +567,18 @@ static SIMDf SIMDf_NUM(10); static SIMDf SIMDf_NUM(15); static SIMDf SIMDf_NUM(32); static SIMDf SIMDf_NUM(999999); +static SIMDf SIMDf_NUM(_1); static SIMDf SIMDf_NUM(0_5); static SIMDf SIMDf_NUM(0_6); static SIMDf SIMDf_NUM(15_5); static SIMDf SIMDf_NUM(511_5); +static SIMDf SIMDf_NUM(32768_5); //static SIMDf SIMDf_NUM(cellJitter); static SIMDf SIMDf_NUM(F3); static SIMDf SIMDf_NUM(G3); +static SIMDf SIMDf_NUM(R3); static SIMDf SIMDf_NUM(G33); static SIMDf SIMDf_NUM(hash2Float); static SIMDf SIMDf_NUM(vectorSize); @@ -632,15 +636,18 @@ void FUNC(InitSIMDValues)() SIMDf_NUM(15) = SIMDf_SET(15.0f); SIMDf_NUM(32) = SIMDf_SET(32.0f); SIMDf_NUM(999999) = SIMDf_SET(999999.0f); + SIMDf_NUM(_1) = SIMDf_SET(-1.0f); SIMDf_NUM(0_5) = SIMDf_SET(0.5f); SIMDf_NUM(0_6) = SIMDf_SET(0.6f); SIMDf_NUM(15_5) = SIMDf_SET(15.5f); SIMDf_NUM(511_5) = SIMDf_SET(511.5f); + SIMDf_NUM(32768_5) = SIMDf_SET(32768.5f); //SIMDf_NUM(cellJitter) = SIMDf_SET(0.39614f); SIMDf_NUM(F3) = SIMDf_SET(1.f / 3.f); SIMDf_NUM(G3) = SIMDf_SET(1.f / 6.f); + SIMDf_NUM(R3) = SIMDf_SET(2.f / 3.f); SIMDf_NUM(G33) = SIMDf_SET((3.f / 6.f) - 1.f); SIMDf_NUM(hash2Float) = SIMDf_SET(1.f / 2147483648.f); SIMDf_NUM(vectorSize) = SIMDf_SET(VECTOR_SIZE); @@ -922,6 +929,65 @@ static SIMDf VECTORCALL FUNC(SimplexSingle)(SIMDi seed, SIMDf x, SIMDf y, SIMDf return SIMDf_MUL(SIMDf_NUM(32), SIMDf_MASK_ADD(n0, SIMDf_MASK_ADD(n1, SIMDf_MASK_ADD(n2, v3, v2), v1), v0)); } +static SIMDf VECTORCALL FUNC(OpenSimplex2Single)(SIMDi seed, SIMDf x, SIMDf y, SIMDf z) +{ + SIMDf f = SIMDf_MUL(SIMDf_NUM(R3), SIMDf_ADD(SIMDf_ADD(x, y), z)); + SIMDf xr = SIMDf_SUB(f, x); + SIMDf yr = SIMDf_SUB(f, y); + SIMDf zr = SIMDf_SUB(f, z); + + SIMDf val = SIMDf_NUM(0); + for (int i = 0; i < 2; i++) + { + SIMDf v0xr = SIMDf_FLOOR(SIMDf_ADD(xr, SIMDf_NUM(0_5))); + SIMDf v0yr = SIMDf_FLOOR(SIMDf_ADD(yr, SIMDf_NUM(0_5))); + SIMDf v0zr = SIMDf_FLOOR(SIMDf_ADD(zr, SIMDf_NUM(0_5))); + SIMDf d0xr = SIMDf_SUB(xr, v0xr); + SIMDf d0yr = SIMDf_SUB(yr, v0yr); + SIMDf d0zr = SIMDf_SUB(zr, v0zr); + + SIMDf score0xr = SIMDf_ABS(d0xr); + SIMDf score0yr = SIMDf_ABS(d0yr); + SIMDf score0zr = SIMDf_ABS(d0zr); + MASK dir0xr = SIMDf_LESS_EQUAL(SIMDf_MAX(score0yr, score0zr), score0xr); + MASK dir0yr = SIMDi_AND_NOT(dir0xr, SIMDf_LESS_EQUAL(SIMDf_MAX(score0zr, score0xr), score0yr)); + MASK dir0zr = SIMDi_NOT(SIMDi_OR(dir0xr, dir0yr)); + SIMDf v1xr = SIMDf_ADD(v0xr, SIMDf_BLENDV(SIMDf_NUM(0), SIMDf_BLENDV(SIMDf_NUM(1), SIMDf_NUM(_1), SIMDf_LESS_THAN(d0xr, SIMDf_NUM(0))), dir0xr)); + SIMDf v1yr = SIMDf_ADD(v0yr, SIMDf_BLENDV(SIMDf_NUM(0), SIMDf_BLENDV(SIMDf_NUM(1), SIMDf_NUM(_1), SIMDf_LESS_THAN(d0yr, SIMDf_NUM(0))), dir0yr)); + SIMDf v1zr = SIMDf_ADD(v0zr, SIMDf_BLENDV(SIMDf_NUM(0), SIMDf_BLENDV(SIMDf_NUM(1), SIMDf_NUM(_1), SIMDf_LESS_THAN(d0zr, SIMDf_NUM(0))), dir0zr)); + SIMDf d1xr = SIMDf_SUB(xr, v1xr); + SIMDf d1yr = SIMDf_SUB(yr, v1yr); + SIMDf d1zr = SIMDf_SUB(zr, v1zr); + + SIMDi hv0xr = SIMDi_MUL(SIMDi_CONVERT_TO_INT(v0xr), SIMDi_NUM(xPrime)); + SIMDi hv0yr = SIMDi_MUL(SIMDi_CONVERT_TO_INT(v0yr), SIMDi_NUM(yPrime)); + SIMDi hv0zr = SIMDi_MUL(SIMDi_CONVERT_TO_INT(v0zr), SIMDi_NUM(zPrime)); + SIMDi hv1xr = SIMDi_MUL(SIMDi_CONVERT_TO_INT(v1xr), SIMDi_NUM(xPrime)); + SIMDi hv1yr = SIMDi_MUL(SIMDi_CONVERT_TO_INT(v1yr), SIMDi_NUM(yPrime)); + SIMDi hv1zr = SIMDi_MUL(SIMDi_CONVERT_TO_INT(v1zr), SIMDi_NUM(zPrime)); + + SIMDf t0 = SIMDf_NMUL_ADD(d0zr, d0zr, SIMDf_NMUL_ADD(d0yr, d0yr, SIMDf_NMUL_ADD(d0xr, d0xr, SIMDf_NUM(0_6)))); + SIMDf t1 = SIMDf_NMUL_ADD(d1zr, d1zr, SIMDf_NMUL_ADD(d1yr, d1yr, SIMDf_NMUL_ADD(d1xr, d1xr, SIMDf_NUM(0_6)))); + MASK n0 = SIMDf_GREATER_THAN(t0, SIMDf_NUM(0)); + MASK n1 = SIMDf_GREATER_THAN(t1, SIMDf_NUM(0)); + t0 = SIMDf_MUL(t0, t0); + t1 = SIMDf_MUL(t1, t1); + + SIMDf v0 = SIMDf_MUL(SIMDf_MUL(t0, t0), FUNC(GradCoord)(seed, hv0xr, hv0yr, hv0zr, d0xr, d0yr, d0zr)); + SIMDf v1 = SIMDf_MUL(SIMDf_MUL(t1, t1), FUNC(GradCoord)(seed, hv1xr, hv1yr, hv1zr, d1xr, d1yr, d1zr)); + + val = SIMDf_MASK_ADD(n0, SIMDf_MASK_ADD(n1, val, v1), v0); + + if (i == 0) { + xr = SIMDf_ADD(xr, SIMDf_NUM(32768_5)); + yr = SIMDf_ADD(yr, SIMDf_NUM(32768_5)); + zr = SIMDf_ADD(zr, SIMDf_NUM(32768_5)); + } + } + + return SIMDf_MUL(SIMDf_NUM(32), val); +} + static SIMDf VECTORCALL FUNC(CubicSingle)(SIMDi seed, SIMDf x, SIMDf y, SIMDf z) { SIMDf xf1 = SIMDf_FLOOR(x); @@ -1376,6 +1442,9 @@ FILL_FRACTAL_SET(Perlin) FILL_SET(Simplex) FILL_FRACTAL_SET(Simplex) +FILL_SET(OpenSimplex2) +FILL_FRACTAL_SET(OpenSimplex2) + //FILL_SET(WhiteNoise) FILL_SET(Cubic) @@ -1491,6 +1560,9 @@ void SIMD_LEVEL_CLASS::Fill##func##FractalSet(float* noiseSet, FastNoiseVectorSe FILL_VECTOR_SET(Simplex) FILL_FRACTAL_VECTOR_SET(Simplex) + FILL_VECTOR_SET(OpenSimplex2) + FILL_FRACTAL_VECTOR_SET(OpenSimplex2) + FILL_VECTOR_SET(WhiteNoise) FILL_VECTOR_SET(Cubic) @@ -1765,6 +1837,12 @@ static SIMDf VECTORCALL FUNC(CellularLookup##distanceFunc##Single)(SIMDi seedV, case FastNoiseSIMD::SimplexFractal:\ CELLULAR_LOOKUP_FRACTAL_VALUE(Simplex);\ break; \ + case FastNoiseSIMD::OpenSimplex2:\ + result = FUNC(OpenSimplex2Single)(seedV, xF, yF, zF); \ + break;\ + case FastNoiseSIMD::OpenSimplex2Fractal:\ + CELLULAR_LOOKUP_FRACTAL_VALUE(OpenSimplex2);\ + break; \ case FastNoiseSIMD::Cubic:\ result = FUNC(CubicSingle)(seedV, xF, yF, zF); \ break;\ diff --git a/FastNoiseSIMD/FastNoiseSIMD_internal.h b/FastNoiseSIMD/FastNoiseSIMD_internal.h index a20e02d..ba37c1f 100644 --- a/FastNoiseSIMD/FastNoiseSIMD_internal.h +++ b/FastNoiseSIMD/FastNoiseSIMD_internal.h @@ -64,6 +64,11 @@ namespace FastNoiseSIMD_internal void FillSimplexSet(float* noiseSet, FastNoiseVectorSet* vectorSet, float xOffset = 0.0f, float yOffset = 0.0f, float zOffset = 0.0f) override; void FillSimplexFractalSet(float* noiseSet, FastNoiseVectorSet* vectorSet, float xOffset = 0.0f, float yOffset = 0.0f, float zOffset = 0.0f) override; + void FillOpenSimplex2Set(float* floatSet, int xStart, int yStart, int zStart, int xSize, int ySize, int zSize, float scaleModifier = 1.0f) override; + void FillOpenSimplex2FractalSet(float* floatSet, int xStart, int yStart, int zStart, int xSize, int ySize, int zSize, float scaleModifier = 1.0f) override; + void FillOpenSimplex2Set(float* noiseSet, FastNoiseVectorSet* vectorSet, float xOffset = 0.0f, float yOffset = 0.0f, float zOffset = 0.0f) override; + void FillOpenSimplex2FractalSet(float* noiseSet, FastNoiseVectorSet* vectorSet, float xOffset = 0.0f, float yOffset = 0.0f, float zOffset = 0.0f) override; + void FillCellularSet(float* floatSet, int xStart, int yStart, int zStart, int xSize, int ySize, int zSize, float scaleModifier = 1.0f) override; void FillCellularSet(float* noiseSet, FastNoiseVectorSet* vectorSet, float xOffset = 0.0f, float yOffset = 0.0f, float zOffset = 0.0f) override; From 46ecbe07e0d7c1f4deb5ff8d74caf126cdfb66ae Mon Sep 17 00:00:00 2001 From: c0rp3n Date: Sat, 8 Feb 2020 21:54:54 +0000 Subject: [PATCH 04/20] [CMake] Improve support and add find package support --- .gitignore | 17 ++ CMakeLists.txt | 170 ++++++++++-------- cmake/FastNoiseSIMD.pc.in | 7 + cmake/FastNoiseSIMDConfig.cmake.in | 6 + cmake/FastNoiseSIMD_config.h.in | 33 ++++ .../FastNoiseSIMD}/ARM/cpu-features.h | 0 .../FastNoiseSIMD/FastNoiseSIMD.h | 27 +-- include/FastNoiseSIMD/FastNoiseSIMD_config.h | 33 ++++ .../FastNoiseSIMD}/FastNoiseSIMD_internal.h | 0 {FastNoiseSIMD => src}/ARM/cpu-features.c | 0 {FastNoiseSIMD => src}/FastNoiseSIMD.cpp | 16 +- {FastNoiseSIMD => src}/FastNoiseSIMD_avx2.cpp | 4 +- .../FastNoiseSIMD_avx512.cpp | 4 +- .../FastNoiseSIMD_internal.cpp | 4 +- {FastNoiseSIMD => src}/FastNoiseSIMD_neon.cpp | 4 +- {FastNoiseSIMD => src}/FastNoiseSIMD_sse2.cpp | 4 +- .../FastNoiseSIMD_sse41.cpp | 4 +- 17 files changed, 213 insertions(+), 120 deletions(-) create mode 100644 cmake/FastNoiseSIMD.pc.in create mode 100644 cmake/FastNoiseSIMDConfig.cmake.in create mode 100644 cmake/FastNoiseSIMD_config.h.in rename {FastNoiseSIMD => include/FastNoiseSIMD}/ARM/cpu-features.h (100%) rename FastNoiseSIMD/FastNoiseSIMD.cmake.h => include/FastNoiseSIMD/FastNoiseSIMD.h (93%) create mode 100644 include/FastNoiseSIMD/FastNoiseSIMD_config.h rename {FastNoiseSIMD => include/FastNoiseSIMD}/FastNoiseSIMD_internal.h (100%) rename {FastNoiseSIMD => src}/ARM/cpu-features.c (100%) rename {FastNoiseSIMD => src}/FastNoiseSIMD.cpp (97%) rename {FastNoiseSIMD => src}/FastNoiseSIMD_avx2.cpp (95%) rename {FastNoiseSIMD => src}/FastNoiseSIMD_avx512.cpp (95%) rename {FastNoiseSIMD => src}/FastNoiseSIMD_internal.cpp (99%) rename {FastNoiseSIMD => src}/FastNoiseSIMD_neon.cpp (93%) rename {FastNoiseSIMD => src}/FastNoiseSIMD_sse2.cpp (94%) rename {FastNoiseSIMD => src}/FastNoiseSIMD_sse41.cpp (94%) diff --git a/.gitignore b/.gitignore index 850bcc7..183f9af 100644 --- a/.gitignore +++ b/.gitignore @@ -262,3 +262,20 @@ paket-files/ /TEST/FastNoiseSIMD Preview /cellModel.skp /cellModel.skb + +# CMake +CMakeLists.txt.user +CMakeCache.txt +CMakeFiles +CMakeScripts +Testing +Makefile +cmake_install.cmake +install_manifest.txt +compile_commands.json +CTestTestfile.cmake +_deps +[Bb]uild + +# VSCode +.vscode/ diff --git a/CMakeLists.txt b/CMakeLists.txt index 8785eee..adf988d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,91 +1,113 @@ # This is currently very rudimentary and likely needs various improvements. cmake_minimum_required(VERSION 3.7) # Requiring 3.7 might be incorrect. + project(FastNoiseSIMD) set(CMAKE_CXX_STANDARD 11) # Requiring C++11 might be incorrect. set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) -set(directory ${PROJECT_NAME}) -set(library_name ${PROJECT_NAME}) -set(file_prefix ${PROJECT_NAME}) - -set_property(DIRECTORY ${PROJECT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT ${library_name}) +set_property(DIRECTORY ${PROJECT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT FastNoiseSIMD) if(CMAKE_SYSTEM_PROCESSOR MATCHES "arm" OR CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64") - option(FN_COMPILE_NEON - "Only on arm or aarch64." - ON) + option(FN_COMPILE_NEON + "Only on arm or aarch64." + ON) endif() -option(FN_COMPILE_SSE2 - "" - ON) -option(FN_COMPILE_SSE41 - "" - ON) -option(FN_COMPILE_AVX2 - "This does not break support for pre AVX CPUs, AVX code is only run if support is detected." - OFF) -option(FN_COMPILE_AVX512 - "Only the latest compilers will support this." - OFF) -option(FN_USE_FMA - "Using FMA instructions with AVX(51)2/NEON provides a small performance increase but can cause \ -minute variations in noise output compared to other SIMD levels due to higher calculation precision." - ON) -option(FN_ALIGNED_SETS - "Using aligned sets of memory for float arrays allows faster storing of SIMD data." - ON) - -configure_file(${directory}/${file_prefix}.cmake.h include/${file_prefix}.h) - -set(flags) +option(FN_COMPILE_SSE2 "" ON) + +option(FN_COMPILE_SSE41 "" ON) + +option( + FN_COMPILE_AVX2 + "This does not break support for pre AVX CPUs, AVX code is only run if \ + support is detected." + OFF +) + +option(FN_COMPILE_AVX512 "Only the latest compilers will support this." OFF) + +option( + FN_USE_FMA + "Using FMA instructions with AVX(51)2/NEON provides a small performance \ + increase but can cause minute variations in noise output compared to other \ + SIMD levels due to higher calculation precision." + ON) + +option( + FN_ALIGNED_SETS + "Using aligned sets of memory for float arrays allows faster storing of \ + SIMD data." + ON) + +configure_file( + ${CMAKE_CURRENT_LIST_DIR}/cmake/FastNoiseSIMD_config.h.in + ${CMAKE_CURRENT_LIST_DIR}/include/FastNoiseSIMD/FastNoiseSIMD_config.h + @ONLY + ) + +add_library(FastNoiseSIMD STATIC + src/FastNoiseSIMD.cpp + src/FastNoiseSIMD_avx2.cpp + src/FastNoiseSIMD_avx512.cpp + src/FastNoiseSIMD_internal.cpp + src/FastNoiseSIMD_neon.cpp + src/FastNoiseSIMD_sse2.cpp + src/FastNoiseSIMD_sse41.cpp +) + +target_include_directories(FastNoiseSIMD PUBLIC + $ + $ +) + +set(FN_CXX_FLAGS) if(${MSVC}) - if(${FN_COMPILE_AVX2} OR ${FN_COMPILE_AVX512}) - list(APPEND flags "/arch:AVX2") - endif() + if(${FN_COMPILE_AVX2} OR ${FN_COMPILE_AVX512}) + list(APPEND FN_CXX_FLAGS "/arch:AVX2") + endif() elseif() - if(${FN_COMPILE_AVX2} OR ${FN_COMPILE_AVX512}) - list(APPEND flags "-march=core-avx2") - endif() + if(${FN_COMPILE_AVX2} OR ${FN_COMPILE_AVX512}) + list(APPEND FN_CXX_FLAGS "-march=core-avx2") + endif() endif() -add_library(${library_name} STATIC - ${directory}/${file_prefix}.cpp - ${directory}/${file_prefix}_avx2.cpp - ${directory}/${file_prefix}_avx512.cpp - ${directory}/${file_prefix}_internal.cpp - ${directory}/${file_prefix}_neon.cpp - ${directory}/${file_prefix}_sse2.cpp - ${directory}/${file_prefix}_sse41.cpp - ) - -target_include_directories(${library_name} PRIVATE - ${CMAKE_CURRENT_BINARY_DIR}/include - ${directory}/ - ) - -set(public_headers - ${CMAKE_CURRENT_BINARY_DIR}/include/${file_prefix}.h - # ${directory}/${file_prefix}_internal.h - ) -set_target_properties(${library_name} PROPERTIES - PUBLIC_HEADER "${public_headers}" - ) - -target_compile_options(${library_name} PRIVATE - "${flags}" - ) - -install(TARGETS ${library_name} - CONFIGURATIONS Debug - ARCHIVE DESTINATION lib/Debug - PUBLIC_HEADER DESTINATION include - ) -install(TARGETS ${library_name} - CONFIGURATIONS Release - ARCHIVE DESTINATION lib/Release - PUBLIC_HEADER DESTINATION include - ) +target_compile_options(FastNoiseSIMD PRIVATE "${FN_CXX_FLAGS}") + +# Only perform the installation steps when not being used as +# a subproject via `add_subdirectory`, or the destinations will break +if(NOT_SUBPROJECT) + set(FN_CMAKE_CONFIG_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/FastNoiseSIMD") + + configure_package_config_file( + ${CMAKE_CURRENT_LIST_DIR}/cmake/FastNoiseSIMDConfig.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/FastNoiseSIMDConfig.cmake + INSTALL_DESTINATION ${FN_CMAKE_CONFIG_DESTINATION} + ) + + # create and install an export set for FastNoiseSIMD target as FastNoiseSIMD + install( + TARGETS FastNoiseSIMD EXPORT FastNoiseSIMDTargets + DESTINATION ${CMAKE_INSTALL_LIBDIR} + ) + + + install(EXPORT FastNoiseSIMDTargets DESTINATION ${FN_CMAKE_CONFIG_DESTINATION}) + + write_basic_package_version_file( + "${CMAKE_CURRENT_BINARY_DIR}/FastNoiseSIMDConfigVersion.cmake" + COMPATIBILITY SameMajorVersion + ) + + install(TARGETS FastNoiseSIMD LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") + install(DIRECTORY "include/" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") + + install( + FILES + "${CMAKE_CURRENT_BINARY_DIR}/FastNoiseSIMDConfig.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/FastNoiseSIMDConfigVersion.cmake" + DESTINATION ${FN_CMAKE_CONFIG_DESTINATION} + ) +endif() diff --git a/cmake/FastNoiseSIMD.pc.in b/cmake/FastNoiseSIMD.pc.in new file mode 100644 index 0000000..c45a3d5 --- /dev/null +++ b/cmake/FastNoiseSIMD.pc.in @@ -0,0 +1,7 @@ +includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@ + +Name: FastNoiseSIMD +Description: +URL: https://github.com/c0rp3n/fastnoise-simd +Version: @FastNoiseSIMD_VERSION@ +Cflags: -I${includedir} \ No newline at end of file diff --git a/cmake/FastNoiseSIMDConfig.cmake.in b/cmake/FastNoiseSIMDConfig.cmake.in new file mode 100644 index 0000000..45ffb2a --- /dev/null +++ b/cmake/FastNoiseSIMDConfig.cmake.in @@ -0,0 +1,6 @@ +@PACKAGE_INIT@ + +# Provide path for scripts +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}") + +include(${CMAKE_CURRENT_LIST_DIR}/FastNoiseSIMDTargets.cmake) \ No newline at end of file diff --git a/cmake/FastNoiseSIMD_config.h.in b/cmake/FastNoiseSIMD_config.h.in new file mode 100644 index 0000000..a2c5b3d --- /dev/null +++ b/cmake/FastNoiseSIMD_config.h.in @@ -0,0 +1,33 @@ +#ifndef FASTNOISE_SIMD_CONFIG_H +#define FASTNOISE_SIMD_CONFIG_H + +#pragma once + +#if defined(__arm__) || defined(__aarch64__) +#define FN_ARM +//#define FN_IOS +#cmakedefine FN_COMPILE_NEON +#else + +// Comment out lines to not compile for certain instruction sets +#cmakedefine FN_COMPILE_SSE2 +#cmakedefine FN_COMPILE_SSE41 + +// To compile AVX2 set C++ code generation to use /arch:AVX(2) on FastNoiseSIMD_avx2.cpp +// Note: This does not break support for pre AVX CPUs, AVX code is only run if support is detected +#cmakedefine FN_COMPILE_AVX2 + +// Only the latest compilers will support this +#cmakedefine FN_COMPILE_AVX512 + +// Using FMA instructions with AVX(51)2/NEON provides a small performance increase but can cause +// minute variations in noise output compared to other SIMD levels due to higher calculation precision +// Intel compiler will always generate FMA instructions, use /Qfma- or -no-fma to disable +#cmakedefine FN_USE_FMA +#endif + +// Using aligned sets of memory for float arrays allows faster storing of SIMD data +// Comment out to allow unaligned float arrays to be used as sets +#cmakedefine FN_ALIGNED_SETS + +#endif diff --git a/FastNoiseSIMD/ARM/cpu-features.h b/include/FastNoiseSIMD/ARM/cpu-features.h similarity index 100% rename from FastNoiseSIMD/ARM/cpu-features.h rename to include/FastNoiseSIMD/ARM/cpu-features.h diff --git a/FastNoiseSIMD/FastNoiseSIMD.cmake.h b/include/FastNoiseSIMD/FastNoiseSIMD.h similarity index 93% rename from FastNoiseSIMD/FastNoiseSIMD.cmake.h rename to include/FastNoiseSIMD/FastNoiseSIMD.h index 00dc65c..507605c 100644 --- a/FastNoiseSIMD/FastNoiseSIMD.cmake.h +++ b/include/FastNoiseSIMD/FastNoiseSIMD.h @@ -31,32 +31,7 @@ #ifndef FASTNOISE_SIMD_H #define FASTNOISE_SIMD_H -#if defined(__arm__) || defined(__aarch64__) -#define FN_ARM -//#define FN_IOS -#cmakedefine FN_COMPILE_NEON -#else - -// Comment out lines to not compile for certain instruction sets -#cmakedefine FN_COMPILE_SSE2 -#cmakedefine FN_COMPILE_SSE41 - -// To compile AVX2 set C++ code generation to use /arch:AVX(2) on FastNoiseSIMD_avx2.cpp -// Note: This does not break support for pre AVX CPUs, AVX code is only run if support is detected -#cmakedefine FN_COMPILE_AVX2 - -// Only the latest compilers will support this -#cmakedefine FN_COMPILE_AVX512 - -// Using FMA instructions with AVX(51)2/NEON provides a small performance increase but can cause -// minute variations in noise output compared to other SIMD levels due to higher calculation precision -// Intel compiler will always generate FMA instructions, use /Qfma- or -no-fma to disable -#cmakedefine FN_USE_FMA -#endif - -// Using aligned sets of memory for float arrays allows faster storing of SIMD data -// Comment out to allow unaligned float arrays to be used as sets -#cmakedefine FN_ALIGNED_SETS +#include "FastNoiseSIMD_config.h" // SSE2/NEON support is guaranteed on 64bit CPUs so no fallback is needed #if !(defined(_WIN64) || defined(__x86_64__) || defined(__ppc64__) || defined(__aarch64__) || defined(FN_IOS)) || defined(_DEBUG) diff --git a/include/FastNoiseSIMD/FastNoiseSIMD_config.h b/include/FastNoiseSIMD/FastNoiseSIMD_config.h new file mode 100644 index 0000000..72addc6 --- /dev/null +++ b/include/FastNoiseSIMD/FastNoiseSIMD_config.h @@ -0,0 +1,33 @@ +#ifndef FASTNOISE_SIMD_CONFIG_H +#define FASTNOISE_SIMD_CONFIG_H + +#pragma once + +#if defined(__arm__) || defined(__aarch64__) +#define FN_ARM +//#define FN_IOS +/* #undef FN_COMPILE_NEON */ +#else + +// Comment out lines to not compile for certain instruction sets +#define FN_COMPILE_SSE2 +#define FN_COMPILE_SSE41 + +// To compile AVX2 set C++ code generation to use /arch:AVX(2) on FastNoiseSIMD_avx2.cpp +// Note: This does not break support for pre AVX CPUs, AVX code is only run if support is detected +#define FN_COMPILE_AVX2 + +// Only the latest compilers will support this +#define FN_COMPILE_AVX512 + +// Using FMA instructions with AVX(51)2/NEON provides a small performance increase but can cause +// minute variations in noise output compared to other SIMD levels due to higher calculation precision +// Intel compiler will always generate FMA instructions, use /Qfma- or -no-fma to disable +#define FN_USE_FMA +#endif + +// Using aligned sets of memory for float arrays allows faster storing of SIMD data +// Comment out to allow unaligned float arrays to be used as sets +#define FN_ALIGNED_SETS + +#endif diff --git a/FastNoiseSIMD/FastNoiseSIMD_internal.h b/include/FastNoiseSIMD/FastNoiseSIMD_internal.h similarity index 100% rename from FastNoiseSIMD/FastNoiseSIMD_internal.h rename to include/FastNoiseSIMD/FastNoiseSIMD_internal.h diff --git a/FastNoiseSIMD/ARM/cpu-features.c b/src/ARM/cpu-features.c similarity index 100% rename from FastNoiseSIMD/ARM/cpu-features.c rename to src/ARM/cpu-features.c diff --git a/FastNoiseSIMD/FastNoiseSIMD.cpp b/src/FastNoiseSIMD.cpp similarity index 97% rename from FastNoiseSIMD/FastNoiseSIMD.cpp rename to src/FastNoiseSIMD.cpp index cbac32a..f1bda81 100644 --- a/FastNoiseSIMD/FastNoiseSIMD.cpp +++ b/src/FastNoiseSIMD.cpp @@ -26,7 +26,7 @@ // off every 'zix'.) // -#include "FastNoiseSIMD.h" +#include "FastNoiseSIMD/FastNoiseSIMD.h" #include #include #include @@ -34,32 +34,32 @@ #ifdef FN_COMPILE_NO_SIMD_FALLBACK #define SIMD_LEVEL_H FN_NO_SIMD_FALLBACK -#include "FastNoiseSIMD_internal.h" +#include "FastNoiseSIMD/FastNoiseSIMD_internal.h" #endif #ifdef FN_COMPILE_SSE2 #define SIMD_LEVEL_H FN_SSE2 -#include "FastNoiseSIMD_internal.h" +#include "FastNoiseSIMD/FastNoiseSIMD_internal.h" #endif #ifdef FN_COMPILE_SSE41 #define SIMD_LEVEL_H FN_SSE41 -#include "FastNoiseSIMD_internal.h" +#include "FastNoiseSIMD/FastNoiseSIMD_internal.h" #endif #ifdef FN_COMPILE_AVX2 #define SIMD_LEVEL_H FN_AVX2 -#include "FastNoiseSIMD_internal.h" +#include "FastNoiseSIMD/FastNoiseSIMD_internal.h" #endif #ifdef FN_COMPILE_AVX512 #define SIMD_LEVEL_H FN_AVX512 -#include "FastNoiseSIMD_internal.h" +#include "FastNoiseSIMD/FastNoiseSIMD_internal.h" #endif #ifdef FN_COMPILE_NEON #define SIMD_LEVEL_H FN_NEON -#include "FastNoiseSIMD_internal.h" +#include "FastNoiseSIMD/FastNoiseSIMD_internal.h" #endif // CPUid @@ -67,7 +67,7 @@ #include #elif defined(FN_ARM) #if !defined(__aarch64__) && !defined(FN_IOS) -#include "ARM/cpu-features.h" +#include "FastNoiseSIMD/ARM/cpu-features.h" #endif #else #include diff --git a/FastNoiseSIMD/FastNoiseSIMD_avx2.cpp b/src/FastNoiseSIMD_avx2.cpp similarity index 95% rename from FastNoiseSIMD/FastNoiseSIMD_avx2.cpp rename to src/FastNoiseSIMD_avx2.cpp index e8b4d09..c2aee1d 100644 --- a/FastNoiseSIMD/FastNoiseSIMD_avx2.cpp +++ b/src/FastNoiseSIMD_avx2.cpp @@ -26,7 +26,7 @@ // off every 'zix'.) // -#include "FastNoiseSIMD.h" +#include "FastNoiseSIMD/FastNoiseSIMD.h" // DISABLE WHOLE PROGRAM OPTIMIZATION for this file when using MSVC @@ -41,7 +41,7 @@ #endif #define SIMD_LEVEL_H FN_AVX2 -#include "FastNoiseSIMD_internal.h" +#include "FastNoiseSIMD/FastNoiseSIMD_internal.h" #include //AVX2 FMA3 #define SIMD_LEVEL FN_AVX2 diff --git a/FastNoiseSIMD/FastNoiseSIMD_avx512.cpp b/src/FastNoiseSIMD_avx512.cpp similarity index 95% rename from FastNoiseSIMD/FastNoiseSIMD_avx512.cpp rename to src/FastNoiseSIMD_avx512.cpp index 78a00a7..03b8b9f 100644 --- a/FastNoiseSIMD/FastNoiseSIMD_avx512.cpp +++ b/src/FastNoiseSIMD_avx512.cpp @@ -26,7 +26,7 @@ // off every 'zix'.) // -#include "FastNoiseSIMD.h" +#include "FastNoiseSIMD/FastNoiseSIMD.h" // DISABLE WHOLE PROGRAM OPTIMIZATION for this file when using MSVC @@ -41,7 +41,7 @@ #endif #define SIMD_LEVEL_H FN_AVX512 -#include "FastNoiseSIMD_internal.h" +#include "FastNoiseSIMD/FastNoiseSIMD_internal.h" #ifdef _WIN32 #include //AVX512 #else diff --git a/FastNoiseSIMD/FastNoiseSIMD_internal.cpp b/src/FastNoiseSIMD_internal.cpp similarity index 99% rename from FastNoiseSIMD/FastNoiseSIMD_internal.cpp rename to src/FastNoiseSIMD_internal.cpp index 5f850bc..7884525 100644 --- a/FastNoiseSIMD/FastNoiseSIMD_internal.cpp +++ b/src/FastNoiseSIMD_internal.cpp @@ -26,7 +26,7 @@ // off every 'zix'.) // -#include "FastNoiseSIMD.h" +#include "FastNoiseSIMD/FastNoiseSIMD.h" #include #if defined(SIMD_LEVEL) || defined(FN_COMPILE_NO_SIMD_FALLBACK) @@ -34,7 +34,7 @@ #ifndef SIMD_LEVEL #define SIMD_LEVEL FN_NO_SIMD_FALLBACK #define SIMD_LEVEL_H FN_NO_SIMD_FALLBACK -#include "FastNoiseSIMD_internal.h" +#include "FastNoiseSIMD/FastNoiseSIMD_internal.h" #include #define FN_ALIGNED_SETS #endif diff --git a/FastNoiseSIMD/FastNoiseSIMD_neon.cpp b/src/FastNoiseSIMD_neon.cpp similarity index 93% rename from FastNoiseSIMD/FastNoiseSIMD_neon.cpp rename to src/FastNoiseSIMD_neon.cpp index cd44b61..ec37c8d 100644 --- a/FastNoiseSIMD/FastNoiseSIMD_neon.cpp +++ b/src/FastNoiseSIMD_neon.cpp @@ -26,11 +26,11 @@ // off every 'zix'.) // -#include "FastNoiseSIMD.h" +#include "FastNoiseSIMD/FastNoiseSIMD.h" #ifdef FN_COMPILE_NEON #define SIMD_LEVEL_H FN_NEON -#include "FastNoiseSIMD_internal.h" +#include "FastNoiseSIMD/FastNoiseSIMD_internal.h" #include #define SIMD_LEVEL FN_NEON diff --git a/FastNoiseSIMD/FastNoiseSIMD_sse2.cpp b/src/FastNoiseSIMD_sse2.cpp similarity index 94% rename from FastNoiseSIMD/FastNoiseSIMD_sse2.cpp rename to src/FastNoiseSIMD_sse2.cpp index 21ac5a0..80370e4 100644 --- a/FastNoiseSIMD/FastNoiseSIMD_sse2.cpp +++ b/src/FastNoiseSIMD_sse2.cpp @@ -26,14 +26,14 @@ // off every 'zix'.) // -#include "FastNoiseSIMD.h" +#include "FastNoiseSIMD/FastNoiseSIMD.h" // DISABLE WHOLE PROGRAM OPTIMIZATION for this file when using MSVC // Depending on the compiler this file may need to have SSE2 code generation compiler flags enabled #ifdef FN_COMPILE_SSE2 #define SIMD_LEVEL_H FN_SSE2 -#include "FastNoiseSIMD_internal.h" +#include "FastNoiseSIMD/FastNoiseSIMD_internal.h" #include //SSE2 #define SIMD_LEVEL FN_SSE2 diff --git a/FastNoiseSIMD/FastNoiseSIMD_sse41.cpp b/src/FastNoiseSIMD_sse41.cpp similarity index 94% rename from FastNoiseSIMD/FastNoiseSIMD_sse41.cpp rename to src/FastNoiseSIMD_sse41.cpp index a61c22c..12499ac 100644 --- a/FastNoiseSIMD/FastNoiseSIMD_sse41.cpp +++ b/src/FastNoiseSIMD_sse41.cpp @@ -26,14 +26,14 @@ // off every 'zix'.) // -#include "FastNoiseSIMD.h" +#include "FastNoiseSIMD/FastNoiseSIMD.h" // DISABLE WHOLE PROGRAM OPTIMIZATION for this file when using MSVC // Depending on the compiler this file may need to have SSE4.1 code generation compiler flags enabled #ifdef FN_COMPILE_SSE41 #define SIMD_LEVEL_H FN_SSE41 -#include "FastNoiseSIMD_internal.h" +#include "FastNoiseSIMD/FastNoiseSIMD_internal.h" #include //SSE4.1 #define SIMD_LEVEL FN_SSE41 From a4691af60d5423e9641a55d6664718148b3d0e0b Mon Sep 17 00:00:00 2001 From: c0rp3n Date: Sat, 8 Feb 2020 22:00:16 +0000 Subject: [PATCH 05/20] [CMake] Add version and description and some cleanup --- CMakeLists.txt | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index adf988d..e96bf1f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,8 +1,16 @@ -# This is currently very rudimentary and likely needs various improvements. +cmake_minimum_required(VERSION 3.10) -cmake_minimum_required(VERSION 3.7) # Requiring 3.7 might be incorrect. +# detect if FastNoiseSIMD is being bundled, +# disable testsuite in that case +if(NOT DEFINED PROJECT_NAME) + set(NOT_SUBPROJECT ON) +endif() -project(FastNoiseSIMD) +project(FastNoiseSIMD + VERSION 0.7.0 + DESCRIPTION "C++ SIMD Noise Library" + LANGUAGES CXX +) set(CMAKE_CXX_STANDARD 11) # Requiring C++11 might be incorrect. set(CMAKE_CXX_STANDARD_REQUIRED ON) @@ -34,19 +42,21 @@ option( "Using FMA instructions with AVX(51)2/NEON provides a small performance \ increase but can cause minute variations in noise output compared to other \ SIMD levels due to higher calculation precision." - ON) + ON +) option( FN_ALIGNED_SETS "Using aligned sets of memory for float arrays allows faster storing of \ SIMD data." - ON) + ON +) configure_file( ${CMAKE_CURRENT_LIST_DIR}/cmake/FastNoiseSIMD_config.h.in ${CMAKE_CURRENT_LIST_DIR}/include/FastNoiseSIMD/FastNoiseSIMD_config.h @ONLY - ) +) add_library(FastNoiseSIMD STATIC src/FastNoiseSIMD.cpp @@ -97,8 +107,8 @@ if(NOT_SUBPROJECT) install(EXPORT FastNoiseSIMDTargets DESTINATION ${FN_CMAKE_CONFIG_DESTINATION}) write_basic_package_version_file( - "${CMAKE_CURRENT_BINARY_DIR}/FastNoiseSIMDConfigVersion.cmake" - COMPATIBILITY SameMajorVersion + "${CMAKE_CURRENT_BINARY_DIR}/FastNoiseSIMDConfigVersion.cmake" + COMPATIBILITY SameMajorVersion ) install(TARGETS FastNoiseSIMD LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") From 6d22f5c2bc6d0fd2b9154005c0020d8a2c9622a4 Mon Sep 17 00:00:00 2001 From: c0rp3n Date: Sat, 8 Feb 2020 22:06:34 +0000 Subject: [PATCH 06/20] [CI] Add appveyor and travis support --- .travis.yml | 28 ++++++++++++++++++++++++++++ appveyor.yml | 15 +++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 .travis.yml create mode 100644 appveyor.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..5a86a6f --- /dev/null +++ b/.travis.yml @@ -0,0 +1,28 @@ +sudo: required + +# Enable C++ support +language: cpp + +# Use Linux by default +os: linux + +# Use Ubuntu 18.04 for GCC 7.4.0 +dist: bionic + +# Compiler selection +compiler: gcc + +install: + - DEPS_DIR="${TRAVIS_BUILD_DIR}/deps" + - mkdir -p ${DEPS_DIR} && cd ${DEPS_DIR} + - | + CMAKE_URL="https://cmake.org/files/v3.16/cmake-3.16.2-Linux-x86_64.tar.gz" + mkdir cmake && travis_retry wget --no-check-certificate --quiet -O - ${CMAKE_URL} | tar --strip-components=1 -xz -C cmake + export PATH=${DEPS_DIR}/cmake/bin:${PATH} + +# Build steps +script: + - cd ${TRAVIS_BUILD_DIR} + - mkdir build + - cd build + - cmake -DFN_COMPILE_AVX2=ON -DFN_COMPILE_AVX512=ON .. && make diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 0000000..6ee5f87 --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,15 @@ +version: 1.0.{build} +image: Visual Studio 2019 +configuration: Debug +clone_depth: 50 +platform: x64 + +before_build: + - mkdir build + - cd build + - cmake -DFN_COMPILE_AVX2=ON -DFN_COMPILE_AVX512=ON -G "Visual Studio 16 2019" .. + +build: + project: build/FastNoiseSIMD.sln + parallel: true + verbosity: minimal From efd6d0be54b756a25c393ea5c7ec4be95877e44a Mon Sep 17 00:00:00 2001 From: c0rp3n Date: Sat, 8 Feb 2020 22:10:36 +0000 Subject: [PATCH 07/20] [CMake] Didnt include cmake dependencies --- CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index e96bf1f..5590f9b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,6 +12,9 @@ project(FastNoiseSIMD LANGUAGES CXX ) +include(GNUInstallDirs) +include(CMakePackageConfigHelpers) + set(CMAKE_CXX_STANDARD 11) # Requiring C++11 might be incorrect. set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) From bfa3814c20674cdad24a8f2e0399de747701ca47 Mon Sep 17 00:00:00 2001 From: c0rp3n Date: Sat, 8 Feb 2020 22:18:16 +0000 Subject: [PATCH 08/20] Update README.md [skip ci] --- README.md | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 299cc23..976c18d 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,17 @@ -# FastNoise SIMD +

+ FastNoise SIMD +

+

+ + Travis Build Status + + + Appveyor Build Status + +
+ FastNoise SIMD is the SIMD implementation of my noise library FastNoise. +

+ FastNoise SIMD is the SIMD implementation of my noise library [FastNoise](https://github.com/Auburns/FastNoise). It aims to provide faster performance through the use of intrinsic(SIMD) CPU functions. Vectorisation of the code allows noise functions to process data in sets of 4/8/16 increasing performance by 700% in some cases (Simplex). After releasing FastNoise I got in contact with the author of [FastNoise SIMD](https://github.com/jackmott/FastNoise-SIMD) (naming is coincidence) and was inspired to work with SIMD functions myself. Through his code and discussions with him I created my implementation with even more optimisation thanks to the removal of lookup tables. From 920914d1a1bb3373bb6061907cc5e8fcf29de909 Mon Sep 17 00:00:00 2001 From: c0rp3n Date: Sat, 8 Feb 2020 22:19:49 +0000 Subject: [PATCH 09/20] [CMake] Fix linux build --- CMakeLists.txt | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5590f9b..3862fb1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -77,12 +77,10 @@ target_include_directories(FastNoiseSIMD PUBLIC ) set(FN_CXX_FLAGS) -if(${MSVC}) - if(${FN_COMPILE_AVX2} OR ${FN_COMPILE_AVX512}) +if(${FN_COMPILE_AVX2} OR ${FN_COMPILE_AVX512}) + if(${MSVC}) list(APPEND FN_CXX_FLAGS "/arch:AVX2") - endif() -elseif() - if(${FN_COMPILE_AVX2} OR ${FN_COMPILE_AVX512}) + else() list(APPEND FN_CXX_FLAGS "-march=core-avx2") endif() endif() From 5dc10f000695f5b1085ae9a72b7dd7584fa57d2d Mon Sep 17 00:00:00 2001 From: c0rp3n Date: Sat, 8 Feb 2020 22:21:01 +0000 Subject: [PATCH 10/20] Update README.md [skip ci] --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 976c18d..fec393f 100644 --- a/README.md +++ b/README.md @@ -3,10 +3,10 @@

- Travis Build Status + Travis Build Status - Appveyor Build Status + Appveyor Build Status
FastNoise SIMD is the SIMD implementation of my noise library FastNoise. From e7e57f027f490b1a23e7ef65a17eeb3f5b8fe82b Mon Sep 17 00:00:00 2001 From: c0rp3n Date: Sat, 8 Feb 2020 22:26:54 +0000 Subject: [PATCH 11/20] [CMake] Properly set arch --- CMakeLists.txt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3862fb1..86e1f96 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -77,7 +77,13 @@ target_include_directories(FastNoiseSIMD PUBLIC ) set(FN_CXX_FLAGS) -if(${FN_COMPILE_AVX2} OR ${FN_COMPILE_AVX512}) +if(${FN_COMPILE_AVX512}) + if(${MSVC}) + list(APPEND FN_CXX_FLAGS "/arch:AVX512") + else() + list(APPEND FN_CXX_FLAGS "-march=skylake-avx512") + endif() +elseif(${FN_COMPILE_AVX2}) if(${MSVC}) list(APPEND FN_CXX_FLAGS "/arch:AVX2") else() From 15ba7007f00c71c7f91f1f52822f39a622d17a2a Mon Sep 17 00:00:00 2001 From: c0rp3n Date: Sat, 8 Feb 2020 22:32:45 +0000 Subject: [PATCH 12/20] Update README.md [skip ci] --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index fec393f..3ba978b 100644 --- a/README.md +++ b/README.md @@ -9,12 +9,12 @@ Appveyor Build Status
- FastNoise SIMD is the SIMD implementation of my noise library FastNoise. + FastNoise SIMD is the SIMD implementation of FastNoise.

-FastNoise SIMD is the SIMD implementation of my noise library [FastNoise](https://github.com/Auburns/FastNoise). It aims to provide faster performance through the use of intrinsic(SIMD) CPU functions. Vectorisation of the code allows noise functions to process data in sets of 4/8/16 increasing performance by 700% in some cases (Simplex). +FastNoise SIMD aims to provide faster performance through the use of intrinsic(SIMD) CPU functions. Vectorisation of the code allows noise functions to process data in sets of 4/8/16 increasing performance by 700% in some cases (Simplex). -After releasing FastNoise I got in contact with the author of [FastNoise SIMD](https://github.com/jackmott/FastNoise-SIMD) (naming is coincidence) and was inspired to work with SIMD functions myself. Through his code and discussions with him I created my implementation with even more optimisation thanks to the removal of lookup tables. +Inspired by [FastNoise SIMD](https://github.com/jackmott/FastNoise-SIMD) (naming is coincidence). FastNoise SIMD was created with even more optimisation thanks to the removal of lookup tables. Runtime detection of highest supported instruction set ensures the fastest possible performance with only 1 compile needed. If no support is found it will fallback to standard types (float/int). From c7bfd61629cc02dd5e797c0a2779e7df8c4da683 Mon Sep 17 00:00:00 2001 From: c0rp3n Date: Sun, 9 Feb 2020 19:01:25 +0000 Subject: [PATCH 13/20] Move FastNoiseSIMD_internal.h as it is not a public header --- src/FastNoiseSIMD.cpp | 12 ++++++------ src/FastNoiseSIMD_avx2.cpp | 2 +- src/FastNoiseSIMD_avx512.cpp | 2 +- src/FastNoiseSIMD_internal.cpp | 2 +- .../FastNoiseSIMD => src}/FastNoiseSIMD_internal.h | 0 src/FastNoiseSIMD_neon.cpp | 2 +- src/FastNoiseSIMD_sse2.cpp | 2 +- src/FastNoiseSIMD_sse41.cpp | 2 +- 8 files changed, 12 insertions(+), 12 deletions(-) rename {include/FastNoiseSIMD => src}/FastNoiseSIMD_internal.h (100%) diff --git a/src/FastNoiseSIMD.cpp b/src/FastNoiseSIMD.cpp index f1bda81..75c00d0 100644 --- a/src/FastNoiseSIMD.cpp +++ b/src/FastNoiseSIMD.cpp @@ -34,32 +34,32 @@ #ifdef FN_COMPILE_NO_SIMD_FALLBACK #define SIMD_LEVEL_H FN_NO_SIMD_FALLBACK -#include "FastNoiseSIMD/FastNoiseSIMD_internal.h" +#include "FastNoiseSIMD_internal.h" #endif #ifdef FN_COMPILE_SSE2 #define SIMD_LEVEL_H FN_SSE2 -#include "FastNoiseSIMD/FastNoiseSIMD_internal.h" +#include "FastNoiseSIMD_internal.h" #endif #ifdef FN_COMPILE_SSE41 #define SIMD_LEVEL_H FN_SSE41 -#include "FastNoiseSIMD/FastNoiseSIMD_internal.h" +#include "FastNoiseSIMD_internal.h" #endif #ifdef FN_COMPILE_AVX2 #define SIMD_LEVEL_H FN_AVX2 -#include "FastNoiseSIMD/FastNoiseSIMD_internal.h" +#include "FastNoiseSIMD_internal.h" #endif #ifdef FN_COMPILE_AVX512 #define SIMD_LEVEL_H FN_AVX512 -#include "FastNoiseSIMD/FastNoiseSIMD_internal.h" +#include "FastNoiseSIMD_internal.h" #endif #ifdef FN_COMPILE_NEON #define SIMD_LEVEL_H FN_NEON -#include "FastNoiseSIMD/FastNoiseSIMD_internal.h" +#include "FastNoiseSIMD_internal.h" #endif // CPUid diff --git a/src/FastNoiseSIMD_avx2.cpp b/src/FastNoiseSIMD_avx2.cpp index c2aee1d..2e68e3a 100644 --- a/src/FastNoiseSIMD_avx2.cpp +++ b/src/FastNoiseSIMD_avx2.cpp @@ -41,7 +41,7 @@ #endif #define SIMD_LEVEL_H FN_AVX2 -#include "FastNoiseSIMD/FastNoiseSIMD_internal.h" +#include "FastNoiseSIMD_internal.h" #include //AVX2 FMA3 #define SIMD_LEVEL FN_AVX2 diff --git a/src/FastNoiseSIMD_avx512.cpp b/src/FastNoiseSIMD_avx512.cpp index 03b8b9f..2d52b29 100644 --- a/src/FastNoiseSIMD_avx512.cpp +++ b/src/FastNoiseSIMD_avx512.cpp @@ -41,7 +41,7 @@ #endif #define SIMD_LEVEL_H FN_AVX512 -#include "FastNoiseSIMD/FastNoiseSIMD_internal.h" +#include "FastNoiseSIMD_internal.h" #ifdef _WIN32 #include //AVX512 #else diff --git a/src/FastNoiseSIMD_internal.cpp b/src/FastNoiseSIMD_internal.cpp index 7884525..42f4c29 100644 --- a/src/FastNoiseSIMD_internal.cpp +++ b/src/FastNoiseSIMD_internal.cpp @@ -34,7 +34,7 @@ #ifndef SIMD_LEVEL #define SIMD_LEVEL FN_NO_SIMD_FALLBACK #define SIMD_LEVEL_H FN_NO_SIMD_FALLBACK -#include "FastNoiseSIMD/FastNoiseSIMD_internal.h" +#include "FastNoiseSIMD_internal.h" #include #define FN_ALIGNED_SETS #endif diff --git a/include/FastNoiseSIMD/FastNoiseSIMD_internal.h b/src/FastNoiseSIMD_internal.h similarity index 100% rename from include/FastNoiseSIMD/FastNoiseSIMD_internal.h rename to src/FastNoiseSIMD_internal.h diff --git a/src/FastNoiseSIMD_neon.cpp b/src/FastNoiseSIMD_neon.cpp index ec37c8d..f11fdca 100644 --- a/src/FastNoiseSIMD_neon.cpp +++ b/src/FastNoiseSIMD_neon.cpp @@ -30,7 +30,7 @@ #ifdef FN_COMPILE_NEON #define SIMD_LEVEL_H FN_NEON -#include "FastNoiseSIMD/FastNoiseSIMD_internal.h" +#include "FastNoiseSIMD_internal.h" #include #define SIMD_LEVEL FN_NEON diff --git a/src/FastNoiseSIMD_sse2.cpp b/src/FastNoiseSIMD_sse2.cpp index 80370e4..c366674 100644 --- a/src/FastNoiseSIMD_sse2.cpp +++ b/src/FastNoiseSIMD_sse2.cpp @@ -33,7 +33,7 @@ // Depending on the compiler this file may need to have SSE2 code generation compiler flags enabled #ifdef FN_COMPILE_SSE2 #define SIMD_LEVEL_H FN_SSE2 -#include "FastNoiseSIMD/FastNoiseSIMD_internal.h" +#include "FastNoiseSIMD_internal.h" #include //SSE2 #define SIMD_LEVEL FN_SSE2 diff --git a/src/FastNoiseSIMD_sse41.cpp b/src/FastNoiseSIMD_sse41.cpp index 12499ac..0cf7133 100644 --- a/src/FastNoiseSIMD_sse41.cpp +++ b/src/FastNoiseSIMD_sse41.cpp @@ -33,7 +33,7 @@ // Depending on the compiler this file may need to have SSE4.1 code generation compiler flags enabled #ifdef FN_COMPILE_SSE41 #define SIMD_LEVEL_H FN_SSE41 -#include "FastNoiseSIMD/FastNoiseSIMD_internal.h" +#include "FastNoiseSIMD_internal.h" #include //SSE4.1 #define SIMD_LEVEL FN_SSE41 From 0237cd424bb3c271d543bc4fbe051d837e9c2bd4 Mon Sep 17 00:00:00 2001 From: KdotJPG Date: Sun, 9 Feb 2020 16:19:15 -0500 Subject: [PATCH 14/20] Undo whitespace changes the IDE made without me noticing --- FastNoiseSIMD/FastNoiseSIMD_internal.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/FastNoiseSIMD/FastNoiseSIMD_internal.cpp b/FastNoiseSIMD/FastNoiseSIMD_internal.cpp index 67bd076..3a45aef 100644 --- a/FastNoiseSIMD/FastNoiseSIMD_internal.cpp +++ b/FastNoiseSIMD/FastNoiseSIMD_internal.cpp @@ -191,8 +191,8 @@ static SIMDf VECTORCALL FUNC(FLOOR)(SIMDf a) SIMDf fval = SIMDf_CONVERT_TO_FLOAT(SIMDi_CONVERT_TO_INT(a)); return vsubq_f32(fval, - SIMDf_CAST_TO_FLOAT(vandq_s32(SIMDf_LESS_THAN(a, fval), - SIMDi_CAST_TO_INT(SIMDf_NUM(1))))); + SIMDf_CAST_TO_FLOAT(vandq_s32(SIMDf_LESS_THAN(a, fval), + SIMDi_CAST_TO_INT(SIMDf_NUM(1))))); } #define SIMDf_FLOOR(a) FUNC(FLOOR)(a) #else @@ -446,7 +446,7 @@ static float FUNC(INV_SQRT)(float x) int i = *(int*)&x; i = 0x5f3759df - (i >> 1); x = *(float*)&i; - x = x * (1.5f - xhalf * x*x); + x = x*(1.5f - xhalf*x*x); return x; } #define SIMDf_INV_SQRT(a) FUNC(INV_SQRT)(a) From 9723945961c2e87ba9bce1fbca501bca4dfe6337 Mon Sep 17 00:00:00 2001 From: c0rp3n Date: Mon, 10 Feb 2020 12:05:43 +0000 Subject: [PATCH 15/20] Add base unit test --- .travis.yml | 4 +++- CMakeLists.txt | 9 +++++++++ appveyor.yml | 12 +++++++++++- install-catch2.sh | 6 ++++++ test/main.cpp | 2 ++ test/simplex_noise.cpp | 19 +++++++++++++++++++ test/tests.cmake | 13 +++++++++++++ 7 files changed, 63 insertions(+), 2 deletions(-) create mode 100755 install-catch2.sh create mode 100644 test/main.cpp create mode 100644 test/simplex_noise.cpp create mode 100644 test/tests.cmake diff --git a/.travis.yml b/.travis.yml index 5a86a6f..c4fd581 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,10 +19,12 @@ install: CMAKE_URL="https://cmake.org/files/v3.16/cmake-3.16.2-Linux-x86_64.tar.gz" mkdir cmake && travis_retry wget --no-check-certificate --quiet -O - ${CMAKE_URL} | tar --strip-components=1 -xz -C cmake export PATH=${DEPS_DIR}/cmake/bin:${PATH} + - ../install-catch2.sh # Build steps script: - cd ${TRAVIS_BUILD_DIR} - mkdir build - cd build - - cmake -DFN_COMPILE_AVX2=ON -DFN_COMPILE_AVX512=ON .. && make + - cmake -DFN_COMPILE_AVX2=ON -DFN_COMPILE_AVX512=OFF -DBUILD_TESTING=ON .. && make + - ctest diff --git a/CMakeLists.txt b/CMakeLists.txt index 86e1f96..6744f4d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,6 +15,11 @@ project(FastNoiseSIMD include(GNUInstallDirs) include(CMakePackageConfigHelpers) +if(BUILD_TESTING) + # Catch2 needed for testing + find_package(Catch2 CONFIG REQUIRED) +endif() + set(CMAKE_CXX_STANDARD 11) # Requiring C++11 might be incorrect. set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) @@ -93,6 +98,10 @@ endif() target_compile_options(FastNoiseSIMD PRIVATE "${FN_CXX_FLAGS}") +if(BUILD_TESTING) + include(test/tests.cmake) +endif() + # Only perform the installation steps when not being used as # a subproject via `add_subdirectory`, or the destinations will break if(NOT_SUBPROJECT) diff --git a/appveyor.yml b/appveyor.yml index 6ee5f87..394306d 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -4,12 +4,22 @@ configuration: Debug clone_depth: 50 platform: x64 +cache: + - c:\tools\vcpkg\installed + +install: + - vcpkg install Catch2:x64-windows + - vcpkg integrate install + before_build: - mkdir build - cd build - - cmake -DFN_COMPILE_AVX2=ON -DFN_COMPILE_AVX512=ON -G "Visual Studio 16 2019" .. + - cmake -DFN_COMPILE_AVX2=ON -DFN_COMPILE_AVX512=OFF -DBUILD_TESTING=ON -G "Visual Studio 16 2019" .. build: project: build/FastNoiseSIMD.sln parallel: true verbosity: minimal + +test_script: + - ctest diff --git a/install-catch2.sh b/install-catch2.sh new file mode 100755 index 0000000..960b6ac --- /dev/null +++ b/install-catch2.sh @@ -0,0 +1,6 @@ +#!/bin/sh +git clone https://github.com/catchorg/Catch2.git +mkdir Catch2/build +cd Catch2/build +cmake -DBUILD_TESTING=OFF .. +make && sudo make install diff --git a/test/main.cpp b/test/main.cpp new file mode 100644 index 0000000..0fac309 --- /dev/null +++ b/test/main.cpp @@ -0,0 +1,2 @@ +#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() +#include diff --git a/test/simplex_noise.cpp b/test/simplex_noise.cpp new file mode 100644 index 0000000..984a278 --- /dev/null +++ b/test/simplex_noise.cpp @@ -0,0 +1,19 @@ +#include + +#include "FastNoiseSIMD/FastNoiseSIMD.h" + +TEST_CASE("simplex", "[FastNoiseSIMD]") +{ + FastNoiseSIMD* noise = FastNoiseSIMD::NewFastNoiseSIMD(); + + int x = 16; + int y = 16; + int z = 16; + int x_size = 8; + int y_size = 8; + int z_size = 8; + float* simplex_set = noise->GetSimplexSet(x, y, z, x_size, y_size, z_size); + + noise->FreeNoiseSet(simplex_set); + delete noise; +} diff --git a/test/tests.cmake b/test/tests.cmake new file mode 100644 index 0000000..8fc2ad7 --- /dev/null +++ b/test/tests.cmake @@ -0,0 +1,13 @@ +add_executable(FastNoiseSIMD_tests + test/simplex_noise.cpp + test/main.cpp +) + +target_link_libraries(FastNoiseSIMD_tests + FastNoiseSIMD + Catch2::Catch2 +) + +include(CTest) +include(Catch) +catch_discover_tests(FastNoiseSIMD_tests) From 8a822ee56033f8c7f6888ce19daa21a521858ae5 Mon Sep 17 00:00:00 2001 From: c0rp3n Date: Mon, 10 Feb 2020 12:37:01 +0000 Subject: [PATCH 16/20] [CI] Travis CMake pass vcpkg flags --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 394306d..6b50cd6 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -14,7 +14,7 @@ install: before_build: - mkdir build - cd build - - cmake -DFN_COMPILE_AVX2=ON -DFN_COMPILE_AVX512=OFF -DBUILD_TESTING=ON -G "Visual Studio 16 2019" .. + - cmake -DFN_COMPILE_AVX2=ON -DFN_COMPILE_AVX512=OFF -DBUILD_TESTING=ON -DCMAKE_TOOLCHAIN_FILE=c:/tools/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows -G "Visual Studio 16 2019" .. build: project: build/FastNoiseSIMD.sln From 4d2dc4e95c58ec12580b1ab37e6768264d111efc Mon Sep 17 00:00:00 2001 From: c0rp3n Date: Thu, 13 Feb 2020 12:11:37 +0000 Subject: [PATCH 17/20] Add d postfix to libs and fix msvc build options --- CMakeLists.txt | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6744f4d..1d51831 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,9 +20,16 @@ if(BUILD_TESTING) find_package(Catch2 CONFIG REQUIRED) endif() -set(CMAKE_CXX_STANDARD 11) # Requiring C++11 might be incorrect. -set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_CXX_EXTENSIONS OFF) +# Do stuff depending on the compiler +if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") + set(CMAKE_CXX_FLAGS "-W -Wall -Wextra -Wpedantic -Wunused-value -Wold-style-cast") + set(CMAKE_CXX_FLAGS_DEBUG "-g -O0") + set(CMAKE_CXX_FLAGS_RELEASE "-O3") +elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") + set(CMAKE_CXX_FLAGS "/W4") + set(CMAKE_CXX_FLAGS_DEBUG "/O0 /ZI") + set(CMAKE_CXX_FLAGS_RELEASE "/O2 /Ob2") +endif() set_property(DIRECTORY ${PROJECT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT FastNoiseSIMD) @@ -76,6 +83,13 @@ add_library(FastNoiseSIMD STATIC src/FastNoiseSIMD_sse41.cpp ) +set_target_properties(FastNoiseSIMD + PROPERTIES + CXX_STANDARD 11 + CXX_STANDARD_REQUIRED ON + CMAKE_DEBUG_POSTFIX "d" +) + target_include_directories(FastNoiseSIMD PUBLIC $ $ From cdf75128468a43d0302cef7c44b3f3b6417fd824 Mon Sep 17 00:00:00 2001 From: c0rp3n Date: Thu, 13 Feb 2020 12:12:23 +0000 Subject: [PATCH 18/20] Remove config header --- .gitignore | 3 ++ include/FastNoiseSIMD/FastNoiseSIMD_config.h | 33 -------------------- 2 files changed, 3 insertions(+), 33 deletions(-) delete mode 100644 include/FastNoiseSIMD/FastNoiseSIMD_config.h diff --git a/.gitignore b/.gitignore index 183f9af..fe63609 100644 --- a/.gitignore +++ b/.gitignore @@ -279,3 +279,6 @@ _deps # VSCode .vscode/ + +# FastNoiseSIMD +FastNoiseSIMD_config.h diff --git a/include/FastNoiseSIMD/FastNoiseSIMD_config.h b/include/FastNoiseSIMD/FastNoiseSIMD_config.h deleted file mode 100644 index 72addc6..0000000 --- a/include/FastNoiseSIMD/FastNoiseSIMD_config.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef FASTNOISE_SIMD_CONFIG_H -#define FASTNOISE_SIMD_CONFIG_H - -#pragma once - -#if defined(__arm__) || defined(__aarch64__) -#define FN_ARM -//#define FN_IOS -/* #undef FN_COMPILE_NEON */ -#else - -// Comment out lines to not compile for certain instruction sets -#define FN_COMPILE_SSE2 -#define FN_COMPILE_SSE41 - -// To compile AVX2 set C++ code generation to use /arch:AVX(2) on FastNoiseSIMD_avx2.cpp -// Note: This does not break support for pre AVX CPUs, AVX code is only run if support is detected -#define FN_COMPILE_AVX2 - -// Only the latest compilers will support this -#define FN_COMPILE_AVX512 - -// Using FMA instructions with AVX(51)2/NEON provides a small performance increase but can cause -// minute variations in noise output compared to other SIMD levels due to higher calculation precision -// Intel compiler will always generate FMA instructions, use /Qfma- or -no-fma to disable -#define FN_USE_FMA -#endif - -// Using aligned sets of memory for float arrays allows faster storing of SIMD data -// Comment out to allow unaligned float arrays to be used as sets -#define FN_ALIGNED_SETS - -#endif From 0ff1b3ac4f35aa6bf6cd6b88f42cbdfd882ca65a Mon Sep 17 00:00:00 2001 From: torss <37229901+torss@users.noreply.github.com> Date: Thu, 5 Mar 2020 01:09:15 +0100 Subject: [PATCH 19/20] Fix minor README.md typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3ba978b..1c61780 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,7 @@ Timings below are x1000 ns to generate 32x32x32 points of noise on a single thre | Cellular | 851 | 1283 | 2679 | 2959 | 2979 | 58125 | | Cubic | 615 | 952 | 1970 | 3516 | 2979 | | -Comparision of fractals and sampling performance [here](https://github.com/Auburns/FastNoiseSIMD/wiki/In-depth-SIMD-level). +Comparison of fractals and sampling performance [here](https://github.com/Auburns/FastNoiseSIMD/wiki/In-depth-SIMD-level). # Examples ### Cellular Noise From 44cead511a2fc1c20f3e6b39e556b6133ffe4e76 Mon Sep 17 00:00:00 2001 From: torss <37229901+torss@users.noreply.github.com> Date: Thu, 5 Mar 2020 03:31:38 +0100 Subject: [PATCH 20/20] Add FN_SET_c0rp3n_CXX_FLAGS CMake option This was added because setting these flags for MSVC did cause a runtime library mismatch in a project using FastNoiseSIMD via add_subdirectory. --- CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1d51831..671928a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,6 +21,10 @@ if(BUILD_TESTING) endif() # Do stuff depending on the compiler +option(FN_SET_c0rp3n_CXX_FLAGS + "Set CMAKE_CXX_FLAGS[_DEBUG][_RELEASE] defaults from the c0rp3n/fastnoise-simd fork." + OFF) +if(FN_SET_c0rp3n_CXX_FLAGS) if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") set(CMAKE_CXX_FLAGS "-W -Wall -Wextra -Wpedantic -Wunused-value -Wold-style-cast") set(CMAKE_CXX_FLAGS_DEBUG "-g -O0") @@ -30,6 +34,7 @@ elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") set(CMAKE_CXX_FLAGS_DEBUG "/O0 /ZI") set(CMAKE_CXX_FLAGS_RELEASE "/O2 /Ob2") endif() +endif() set_property(DIRECTORY ${PROJECT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT FastNoiseSIMD)