From 1a3aeb31e0f03325ca4d8396555003ebf7e429df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Wed, 29 Jan 2025 00:32:16 -0300 Subject: [PATCH] Added SIMD to String::isAscii, check if this builds in every platform or I have to revert. Fixed emscripten 3 and 4 build issues (i had 2 mains defined :facepalm:). --- include/eepp/core/simd.hpp | 25 ++++++++++ src/eepp/core/string.cpp | 23 +++++++++- src/thirdparty/libvorbis/lib/barkmel.c | 63 -------------------------- 3 files changed, 46 insertions(+), 65 deletions(-) create mode 100644 include/eepp/core/simd.hpp delete mode 100644 src/thirdparty/libvorbis/lib/barkmel.c diff --git a/include/eepp/core/simd.hpp b/include/eepp/core/simd.hpp new file mode 100644 index 000000000..9e2f59389 --- /dev/null +++ b/include/eepp/core/simd.hpp @@ -0,0 +1,25 @@ +#pragma once + +#include + +#if EE_PLATFORM != EE_PLATFORM_EMSCRIPTEN + +#if __has_include( ) && __cplusplus >= 202002L +#include // C++23 std::simd +#define USE_STD_SIMD +#elif __has_include( ) +#include // 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 diff --git a/src/eepp/core/string.cpp b/src/eepp/core/string.cpp index 2d1c1e29b..02d22edd9 100644 --- a/src/eepp/core/string.cpp +++ b/src/eepp/core/string.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include @@ -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; + 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; } diff --git a/src/thirdparty/libvorbis/lib/barkmel.c b/src/thirdparty/libvorbis/lib/barkmel.c deleted file mode 100644 index 4b19935f3..000000000 --- a/src/thirdparty/libvorbis/lib/barkmel.c +++ /dev/null @@ -1,63 +0,0 @@ -/******************************************************************** - * * - * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. * - * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * - * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * - * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * - * * - * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2007 * - * by the Xiph.Org Foundation http://www.xiph.org/ * - * * - ******************************************************************** - - function: bark scale utility - - ********************************************************************/ - -#include -#include "scales.h" -int main(){ - int i; - double rate; - for(i=64;i<32000;i*=2){ - rate=48000.f; - fprintf(stderr,"rate=%gHz, block=%d, f(1)=%.2gHz bark(1)=%.2g (of %.2g)\n", - rate,i,rate/2 / (i/2),toBARK(rate/2 /(i/2)),toBARK(rate/2)); - - rate=44100.f; - fprintf(stderr,"rate=%gHz, block=%d, f(1)=%.2gHz bark(1)=%.2g (of %.2g)\n", - rate,i,rate/2 / (i/2),toBARK(rate/2 /(i/2)),toBARK(rate/2)); - - rate=32000.f; - fprintf(stderr,"rate=%gHz, block=%d, f(1)=%.2gHz bark(1)=%.2g (of %.2g)\n", - rate,i,rate/2 / (i/2),toBARK(rate/2 /(i/2)),toBARK(rate/2)); - - rate=22050.f; - fprintf(stderr,"rate=%gHz, block=%d, f(1)=%.2gHz bark(1)=%.2g (of %.2g)\n", - rate,i,rate/2 / (i/2),toBARK(rate/2 /(i/2)),toBARK(rate/2)); - - rate=16000.f; - fprintf(stderr,"rate=%gHz, block=%d, f(1)=%.2gHz bark(1)=%.2g (of %.2g)\n", - rate,i,rate/2 / (i/2),toBARK(rate/2 /(i/2)),toBARK(rate/2)); - - rate=11025.f; - fprintf(stderr,"rate=%gHz, block=%d, f(1)=%.2gHz bark(1)=%.2g (of %.2g)\n", - rate,i,rate/2 / (i/2),toBARK(rate/2 /(i/2)),toBARK(rate/2)); - - rate=8000.f; - fprintf(stderr,"rate=%gHz, block=%d, f(1)=%.2gHz bark(1)=%.2g (of %.2g)\n\n", - rate,i,rate/2 / (i/2),toBARK(rate/2 /(i/2)),toBARK(rate/2)); - - - } - { - float i; - int j; - for(i=0.,j=0;i<28;i+=1,j++){ - fprintf(stderr,"(%d) bark=%f %gHz (%d of 128)\n", - j,i,fromBARK(i),(int)(fromBARK(i)/22050.*128.)); - } - } - return(0); -} -