Skip to content

Commit

Permalink
Added SIMD to String::isAscii, check if this builds in every platform…
Browse files Browse the repository at this point in the history
… or I have to revert.

Fixed emscripten 3 and 4 build issues (i had 2 mains defined 🤦).
  • Loading branch information
SpartanJ committed Jan 29, 2025
1 parent ad39ced commit 1a3aeb3
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 65 deletions.
25 changes: 25 additions & 0 deletions include/eepp/core/simd.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#pragma once

#include <eepp/config.hpp>

#if EE_PLATFORM != EE_PLATFORM_EMSCRIPTEN

#if __has_include( <simd>) && __cplusplus >= 202002L
#include <simd> // C++23 std::simd
#define USE_STD_SIMD
#elif __has_include( <experimental/simd>)
#include <experimental/simd> // Parallelism TS v2
#define USE_EXPERIMENTAL_SIMD
#endif

#ifdef USE_STD_SIMD
namespace simd = std;
#elif defined( USE_EXPERIMENTAL_SIMD )
namespace simd = std::experimental;
#endif

#if defined( USE_STD_SIMD ) || defined( USE_EXPERIMENTAL_SIMD )
#define EE_STD_SIMD
#endif

#endif
23 changes: 21 additions & 2 deletions src/eepp/core/string.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <eepp/core/string.hpp>
#include <eepp/core/utf.hpp>
#include <eepp/core/simd.hpp>

#include <thirdparty/fast_float/include/fast_float/fast_float.h>
#include <thirdparty/utf8cpp/utf8.h>
Expand Down Expand Up @@ -1256,9 +1257,27 @@ bool String::contains( const String& needle ) const {
}

bool String::isAscii() const {
for ( const auto& ch : mString )
if ( ch > 127 )
auto data = mString.data();
size_t len = mString.size();
size_t i = 0;

#ifdef EE_STD_SIMD
using simd_type = simd::native_simd<char32_t>;
constexpr size_t simd_size = simd_type::size();
const simd_type ascii_limit = 127;
for ( ; i + simd_size - 1 < len; i += simd_size ) {
simd_type chunk;
chunk.copy_from( &data[i], simd::element_aligned );
auto mask = chunk > ascii_limit;
if ( simd::any_of( mask ) )
return false;
}
#endif

for ( ; i < len; ++i )
if ( data[i] > 127 )
return false;

return true;
}

Expand Down
63 changes: 0 additions & 63 deletions src/thirdparty/libvorbis/lib/barkmel.c

This file was deleted.

0 comments on commit 1a3aeb3

Please sign in to comment.