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 🤦).
This commit is contained in:
Martín Lucas Golini
2025-01-29 00:32:16 -03:00
parent ad39ced875
commit 1a3aeb31e0
3 changed files with 46 additions and 65 deletions

View File

@@ -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

View File

@@ -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>
@@ -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;
}

View File

@@ -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 <stdio.h>
#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);
}