Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor math simd #2070

Merged
merged 1 commit into from
Aug 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions 1k/1kiss.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,7 @@ function setup_cmake($skipOS = $false, $scope = 'local') {
else {
& "$cmake_pkg_path" '--skip-license' '--prefix=/usr/local' 1>$null 2>$null
}
if (!$?) { Remove-Item $cmake_pkg_path -Force }
}

$cmake_prog, $_ = find_prog -name 'cmake' -path $cmake_bin -silent $true
Expand Down
8 changes: 7 additions & 1 deletion 1k/fetch.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,16 @@ function(_1kfetch_init)
set(_1kfetch_manifest "${_1kfetch_manifest}" CACHE STRING "" FORCE)
endif()

if(NOT EXISTS ${PWSH_PROG}) # try again
unset(PWSH_PROG CACHE)
find_program(PWSH_PROG NAMES pwsh powershell NO_PACKAGE_ROOT_PATH NO_CMAKE_PATH NO_CMAKE_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH NO_CMAKE_FIND_ROOT_PATH)
endif()

execute_process(COMMAND ${PWSH_PROG} ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/resolv-uri.ps1
-name "1kdist"
-manifest ${_1kfetch_manifest}
OUTPUT_VARIABLE _1kdist_url
RESULT_VARIABLE _1kdist_error
)

if(_1kdist_url)
Expand All @@ -33,7 +39,7 @@ function(_1kfetch_init)
set(_1kdist_base_url "${_1kdist_base_url}/${_1kdist_ver}" PARENT_SCOPE)
set(_1kdist_ver ${_1kdist_ver} PARENT_SCOPE)
else()
message(WARNING "Resolve 1kdist uri fail, the _1kfetch_dist will not work")
message(WARNING "Resolve 1kdist uri fail, ${_1kdist_error}, the _1kfetch_dist will not work")
endif()
endfunction()

Expand Down
2 changes: 1 addition & 1 deletion 3rdparty/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@

## yasio
- [![Upstream](https://img.shields.io/github/v/release/yasio/yasio?label=Upstream)](https://github.com/yasio/yasio)
- Version: 4.2.3
- Version: 4.2.4
- License: MIT WITH Anti-996

## zlib
Expand Down
24 changes: 14 additions & 10 deletions 3rdparty/yasio/yasio/bindings/yasio_ni.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ YASIO_NI_API void yasio_init_globals(void(YASIO_INTEROP_DECL* pfn)(int level, co
YASIO_NI_API void yasio_cleanup_globals() { io_service::cleanup_globals(); }

struct yasio_io_event {
int kind; //
int channel;
void* thandle;
int kind; // event kind
int channel; // channel index
void* thandle; // transport
union {
void* msg;
int status; //
void* hmsg; // io_packet*
int ec; // error code
};
void* user;
void* user; // user data
};

YASIO_NI_API void* yasio_create_service(int channel_count, void(YASIO_INTEROP_DECL* event_cb)(yasio_io_event* event), void* user)
Expand All @@ -82,9 +82,9 @@ YASIO_NI_API void* yasio_create_service(int channel_count, void(YASIO_INTEROP_DE
event.thandle = e->transport();
event.user = user;
if (event.kind == yasio::YEK_ON_PACKET)
event.msg = !is_packet_empty(pkt) ? &pkt : nullptr;
event.hmsg = !is_packet_empty(pkt) ? &pkt : nullptr;
else
event.status = e->status();
event.ec = e->status();
event_cb(&event);
});
return service;
Expand Down Expand Up @@ -157,8 +157,12 @@ YASIO_NI_API void yasio_set_option(void* service_ptr, int opt, const char* pszAr
std::array<cxx17::string_view, YASIO_MAX_OPTION_ARGC> args;
int argc = 0;
yasio::split_if(&strArgs.front(), ';', [&](char* s, char* e) {
*e = '\0'; // to c style string
args[argc++] = cxx17::string_view(s, e - s);
if (e) {
*e = '\0'; // to c style string
args[argc++] = cxx17::string_view(s, e - s);
} else {
args[argc++] = cxx17::string_view{s};
}
return (argc < YASIO_MAX_OPTION_ARGC);
});

Expand Down
2 changes: 1 addition & 1 deletion 3rdparty/yasio/yasio/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ SOFTWARE.
/*
** The yasio version macros
*/
#define YASIO_VERSION_NUM 0x040203
#define YASIO_VERSION_NUM 0x040204

/*
** The macros used by io_service.
Expand Down
10 changes: 5 additions & 5 deletions 3rdparty/yasio/yasio/impl/eventfd_select_interrupter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#if defined(__GLIBC__) && (__GLIBC__ == 2 && __GLIBC_MINOR__ < 8)
# include <asm/unistd.h>
#else // __GLIBC__ == 2 && __GLIBC_MINOR__ < 8
#if defined(__GLIBC__) && (__GLIBC__ == 2 && __GLIBC_MINOR__ < 8) && !defined(__UCLIBC__)
# include <asm/unistd.h> // for syscall without API: eventfd
#else
# include <sys/eventfd.h>
#endif // __GLIBC__ == 2 && __GLIBC_MINOR__ < 8
#endif

#include <unistd.h>

Expand Down Expand Up @@ -105,7 +105,7 @@ class eventfd_select_interrupter {
// Open the descriptors. Throws on error.
inline void open_descriptors()
{
#if defined(__GLIBC__) && (__GLIBC__ == 2 && __GLIBC_MINOR__ < 8)
#if defined(__GLIBC__) && (__GLIBC__ == 2 && __GLIBC_MINOR__ < 8) && !defined(__UCLIBC__)
write_descriptor_ = read_descriptor_ = syscall(__NR_eventfd, 0);
if (read_descriptor_ != -1)
{
Expand Down
3 changes: 3 additions & 0 deletions 3rdparty/yasio/yasio/logging.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ inline void yasio__print(std::string&& message) { ::write(::fileno(stdout), mess
# include <android/log.h>
# include <jni.h>
# define YASIO_LOG_TAG(tag, format, ...) __android_log_print(ANDROID_LOG_INFO, "yasio", (tag format), ##__VA_ARGS__)
#elif defined(__OHOS__)
# include <hilog/log.h>
# define YASIO_LOG_TAG(tag, format, ...) OH_LOG_INFO(LOG_APP, (tag format "\n"), ##__VA_ARGS__)
#else
# define YASIO_LOG_TAG(tag, format, ...) printf((tag format "\n"), ##__VA_ARGS__)
#endif
Expand Down
2 changes: 1 addition & 1 deletion 3rdparty/yasio/yasio/xxsocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ int xxsocket::pserve(const endpoint& ep)
if (!this->reopen(ep.af()))
return -1;

set_optval(SOL_SOCKET, SO_REUSEADDR, 1);
this->reuse_address(true);

int n = this->bind(ep);
if (n != 0)
Expand Down
1 change: 1 addition & 0 deletions CMakeOptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ default is: `navigator.hardwareConcurrency`
- AX_WASM_SHELL_FILE: specify the wasm shell file, by default use `${_AX_ROOT}/core/platform/wasm/shell_minimal.html`
- AX_WASM_ENABLE_DEVTOOLS: whether enable web devtools aka `pause`, `resume`, `step` buttons in webpage, default: `TRUE`
- AX_WASM_INITIAL_MEMORY: set the wasm initial memory size, default `1024MB`
- AX_WASM_ISA_SIMD: specify the wasm simd intrinsics type, default `none`, supports `sse`, `neon`, note the `wasm-simd` not support by axmol yet

## The options for axmol apps

Expand Down
15 changes: 7 additions & 8 deletions cmake/Modules/AXConfigDefine.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -186,22 +186,21 @@ endfunction()

if(EMSCRIPTEN)
set(AX_WASM_THREADS "4" CACHE STRING "Wasm threads count")

set(_AX_WASM_THREADS_INT 0)
set(_threads_hint "")
if (AX_WASM_THREADS STREQUAL "auto") # not empty string or not 0
# Enable pthread support globally
set(_threads_hint "(auto)")
include(ProcessorCount)
set(_AX_WASM_THREADS_INT 0)
ProcessorCount(_AX_WASM_THREADS_INT)
elseif(AX_WASM_THREADS MATCHES "^([0-9]+)$" OR AX_WASM_THREADS STREQUAL "navigator.hardwareConcurrency")
set(_AX_WASM_THREADS_INT ${AX_WASM_THREADS})
set(AX_WASM_THREADS "${_AX_WASM_THREADS_INT}" CACHE STRING "Wasm threads count" FORCE)
endif()

message(STATUS "AX_WASM_THREADS=${AX_WASM_THREADS}")
message(STATUS "_AX_WASM_THREADS_INT=${_AX_WASM_THREADS_INT}")
message(STATUS "AX_WASM_THREADS=${AX_WASM_THREADS}${_threads_hint}")

if (_AX_WASM_THREADS_INT)
if(AX_WASM_THREADS MATCHES "^([0-9]+)$" OR AX_WASM_THREADS STREQUAL "navigator.hardwareConcurrency")
list(APPEND _ax_compile_options -pthread)
add_link_options(-pthread -sPTHREAD_POOL_SIZE=${_AX_WASM_THREADS_INT})
add_link_options(-pthread -sPTHREAD_POOL_SIZE=${AX_WASM_THREADS})
endif()

set(AX_WASM_INITIAL_MEMORY "1024MB" CACHE STRING "")
Expand Down
40 changes: 37 additions & 3 deletions core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -400,9 +400,43 @@ if(WINDOWS)
endif()
endif()

# AX_USE_SSE
if (AX_ISA_SIMD MATCHES "sse")
target_compile_definitions(${_AX_CORE_LIB} PUBLIC AX_USE_SSE=1)
# axmol math simd intrinsics support
set(_simdc_defines)
set(_simdc_options)
if (NOT WASM) # native platforms auto detect from cmake or preprocessor check
if (AX_ISA_SIMD MATCHES "sse")
list(APPEND _simdc_defines AX_SSE_INTRINSICS=1)
if (AX_ISA_SIMD MATCHES "sse4")
list(APPEND _simdc_defines __SSE4_1__=1)
if (LINUX)
list(APPEND _simdc_options -msse4.1)
endif()
endif()
endif()
else() # wasm requires user specify SIMD intrinsics manually
set(AX_WASM_ISA_SIMD "none" CACHE STRING "")
string(TOLOWER ${AX_WASM_ISA_SIMD} AX_WASM_ISA_SIMD)
if(AX_WASM_ISA_SIMD MATCHES "sse")
message(AUTHOR_WARNING "Using SSE intrinsics for WASM ...")
list(APPEND _simdc_defines AX_SSE_INTRINSICS=1 __SSE__=1 __SSE2__=1)
list(APPEND _simdc_options -msse -msse2)
if(AX_ISA_LEVEL GREATER_EQUAL 2)
list(APPEND _simdc_defines __SSE4_1__=1)
list(APPEND _simdc_options -msse4.1)
endif()
list(APPEND _simdc_options -msimd128)
elseif(AX_WASM_ISA_SIMD MATCHES "neon")
message(AUTHOR_WARNING "Using NEON intrinsics for WASM ...")
list(APPEND _simdc_defines AX_NEON_INTRINSICS=1)
list(APPEND _simdc_options -mfpu=neon -msimd128)
endif()
endif()

if(_simdc_defines)
target_compile_definitions(${_AX_CORE_LIB} PUBLIC ${_simdc_defines})
if(_simdc_options)
target_compile_options(${_AX_CORE_LIB} PUBLIC ${_simdc_options})
endif()
endif()

# engine extensions
Expand Down
14 changes: 12 additions & 2 deletions core/base/Configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ bool Configuration::init()
#if AX_ENABLE_PROFILERS
_valueDict["axmol.compiled_with_profiler"] = Value(true);
#else
_valueDict["axmol.compiled_with_profiler"] = Value(false);
_valueDict["axmol.compiled_with_profiler"] = Value(false);
#endif

#if AX_ENABLE_GL_STATE_CACHE == 0
Expand All @@ -83,7 +83,17 @@ bool Configuration::init()
#if _AX_DEBUG
_valueDict["axmol.build_type"] = Value("DEBUG");
#else
_valueDict["axmol.build_type"] = Value("RELEASE");
_valueDict["axmol.build_type"] = Value("RELEASE");
#endif

#if defined(AX_SSE_INTRINSICS)
# if defined(__SSE4_1__)
_valueDict["axmol.simd"] = Value("SSE41");
# else
_valueDict["axmol.simd"] = Value("SSE2");
# endif
#elif defined(AX_NEON_INTRINSICS)
_valueDict["axmol.simd"] = Value("NEON");
#endif

return true;
Expand Down
2 changes: 1 addition & 1 deletion core/base/Console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ bool Console::listenOnTCP(int port)
if (sock.pserve(ep) != 0)
{
int ec = xxsocket::get_last_errno();
AXLOGW("Console: open server failed, ec:{}", ec);
AXLOGW("Console: open server failed, ec:{}, {}", ec, xxsocket::strerror(ec));
return false;
}

Expand Down
41 changes: 3 additions & 38 deletions core/math/Mat4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

Original file from GamePlay3D: http://gameplay3d.org

This file was modified to fit the cocos2d-x project
This file was modified to fit the axmol project
*/

#include "math/Mat4.h"
Expand Down Expand Up @@ -459,11 +459,7 @@ void Mat4::add(float scalar)
void Mat4::add(float scalar, Mat4* dst)
{
GP_ASSERT(dst);
#ifdef AX_USE_SSE
MathUtil::addMatrix(col, scalar, dst->col);
#else
MathUtil::addMatrix(m, scalar, dst->m);
#endif
}

void Mat4::add(const Mat4& mat)
Expand All @@ -474,11 +470,7 @@ void Mat4::add(const Mat4& mat)
void Mat4::add(const Mat4& m1, const Mat4& m2, Mat4* dst)
{
GP_ASSERT(dst);
#ifdef AX_USE_SSE
MathUtil::addMatrix(m1.col, m2.col, dst->col);
#else
MathUtil::addMatrix(m1.m, m2.m, dst->m);
#endif
}

bool Mat4::decompose(Vec3* scale, Quaternion* rotation, Vec3* translation) const
Expand Down Expand Up @@ -751,11 +743,7 @@ void Mat4::multiply(float scalar, Mat4* dst) const
void Mat4::multiply(const Mat4& m, float scalar, Mat4* dst)
{
GP_ASSERT(dst);
#ifdef AX_USE_SSE
MathUtil::multiplyMatrix(m.col, scalar, dst->col);
#else
MathUtil::multiplyMatrix(m.m, scalar, dst->m);
#endif
}

void Mat4::multiply(const Mat4& mat)
Expand All @@ -766,20 +754,12 @@ void Mat4::multiply(const Mat4& mat)
void Mat4::multiply(const Mat4& m1, const Mat4& m2, Mat4* dst)
{
GP_ASSERT(dst);
#ifdef AX_USE_SSE
MathUtil::multiplyMatrix(m1.col, m2.col, dst->col);
#else
MathUtil::multiplyMatrix(m1.m, m2.m, dst->m);
#endif
}

void Mat4::negate()
{
#ifdef AX_USE_SSE
MathUtil::negateMatrix(col, col);
#else
MathUtil::negateMatrix(m, m);
#endif
}

Mat4 Mat4::getNegated() const
Expand Down Expand Up @@ -945,11 +925,7 @@ void Mat4::subtract(const Mat4& mat)
void Mat4::subtract(const Mat4& m1, const Mat4& m2, Mat4* dst)
{
GP_ASSERT(dst);
#ifdef AX_USE_SSE
MathUtil::subtractMatrix(m1.col, m2.col, dst->col);
#else
MathUtil::subtractMatrix(m1.m, m2.m, dst->m);
#endif
}

void Mat4::transformVector(Vec3* vector) const
Expand All @@ -967,7 +943,7 @@ void Mat4::transformVector(float x, float y, float z, float w, Vec3* dst) const
{
GP_ASSERT(dst);

MathUtil::transformVec4(m, x, y, z, w, (float*)dst);
MathUtil::transformVec4(m, x, y, z, w, reinterpret_cast<float*>(dst));
}

void Mat4::transformVector(Vec4* vector) const
Expand All @@ -979,14 +955,7 @@ void Mat4::transformVector(Vec4* vector) const
void Mat4::transformVector(const Vec4& vector, Vec4* dst) const
{
GP_ASSERT(dst);
#ifdef AX_USE_SSE
alignas(16) Vec4 inVal{vector};
alignas(16) Vec4 outVal;
MathUtil::transformVec4(col, reinterpret_cast<const __m128&>(inVal), reinterpret_cast<__m128&>(outVal));
*dst = outVal;
#else
MathUtil::transformVec4(m, (const float*)&vector, (float*)dst);
#endif
MathUtil::transformVec4(m, reinterpret_cast<const float*>(&vector), reinterpret_cast<float*>(dst));
}

void Mat4::translate(float x, float y, float z)
Expand All @@ -1013,11 +982,7 @@ void Mat4::translate(const Vec3& t, Mat4* dst) const

void Mat4::transpose()
{
#ifdef AX_USE_SSE
MathUtil::transposeMatrix(col, col);
#else
MathUtil::transposeMatrix(m, m);
#endif
}

Mat4 Mat4::getTransposed() const
Expand Down
Loading