Skip to content
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
93 changes: 47 additions & 46 deletions ext/json/simd/simd.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,45 +7,45 @@ typedef enum {
#ifdef JSON_ENABLE_SIMD

#ifdef __clang__
#if __has_builtin(__builtin_ctzll)
#define HAVE_BUILTIN_CTZLL 1
#else
#define HAVE_BUILTIN_CTZLL 0
#endif
# if __has_builtin(__builtin_ctzll)
# define HAVE_BUILTIN_CTZLL 1
# else
# define HAVE_BUILTIN_CTZLL 0
# endif
#elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))
#define HAVE_BUILTIN_CTZLL 1
# define HAVE_BUILTIN_CTZLL 1
#else
#define HAVE_BUILTIN_CTZLL 0
# define HAVE_BUILTIN_CTZLL 0
#endif

static inline uint32_t trailing_zeros64(uint64_t input)
{
#if HAVE_BUILTIN_CTZLL
return __builtin_ctzll(input);
return __builtin_ctzll(input);
#else
uint32_t trailing_zeros = 0;
uint64_t temp = input;
while ((temp & 1) == 0 && temp > 0) {
trailing_zeros++;
temp >>= 1;
}
return trailing_zeros;
uint32_t trailing_zeros = 0;
uint64_t temp = input;
while ((temp & 1) == 0 && temp > 0) {
trailing_zeros++;
temp >>= 1;
}
return trailing_zeros;
#endif
}

static inline int trailing_zeros(int input)
{
#if HAVE_BUILTIN_CTZLL
#if HAVE_BUILTIN_CTZLL
return __builtin_ctz(input);
#else
#else
int trailing_zeros = 0;
int temp = input;
while ((temp & 1) == 0 && temp > 0) {
trailing_zeros++;
temp >>= 1;
trailing_zeros++;
temp >>= 1;
}
return trailing_zeros;
#endif
#endif
}

#if (defined(__GNUC__ ) || defined(__clang__))
Expand Down Expand Up @@ -79,37 +79,38 @@ static inline FORCE_INLINE uint64_t neon_match_mask(uint8x16_t matches)

static inline FORCE_INLINE uint64_t compute_chunk_mask_neon(const char *ptr)
{
uint8x16_t chunk = vld1q_u8((const unsigned char *)ptr);
uint8x16_t chunk = vld1q_u8((const unsigned char *)ptr);

// Trick: c < 32 || c == 34 can be factored as c ^ 2 < 33
// https://lemire.me/blog/2025/04/13/detect-control-characters-quotes-and-backslashes-efficiently-using-swar/
const uint8x16_t too_low_or_dbl_quote = vcltq_u8(veorq_u8(chunk, vdupq_n_u8(2)), vdupq_n_u8(33));
// Trick: c < 32 || c == 34 can be factored as c ^ 2 < 33
// https://lemire.me/blog/2025/04/13/detect-control-characters-quotes-and-backslashes-efficiently-using-swar/
const uint8x16_t too_low_or_dbl_quote = vcltq_u8(veorq_u8(chunk, vdupq_n_u8(2)), vdupq_n_u8(33));

uint8x16_t has_backslash = vceqq_u8(chunk, vdupq_n_u8('\\'));
uint8x16_t needs_escape = vorrq_u8(too_low_or_dbl_quote, has_backslash);
return neon_match_mask(needs_escape);
uint8x16_t has_backslash = vceqq_u8(chunk, vdupq_n_u8('\\'));
uint8x16_t needs_escape = vorrq_u8(too_low_or_dbl_quote, has_backslash);
return neon_match_mask(needs_escape);
}

static inline FORCE_INLINE int string_scan_simd_neon(const char **ptr, const char *end, uint64_t *mask)
{
while (*ptr + sizeof(uint8x16_t) <= end) {
uint64_t chunk_mask = compute_chunk_mask_neon(*ptr);
if (chunk_mask) {
*mask = chunk_mask;
return 1;
}
*ptr += sizeof(uint8x16_t);
uint64_t chunk_mask = compute_chunk_mask_neon(*ptr);
if (chunk_mask) {
*mask = chunk_mask;
return 1;
}
*ptr += sizeof(uint8x16_t);
}
return 0;
}

uint8x16x4_t load_uint8x16_4(const unsigned char *table) {
uint8x16x4_t tab;
tab.val[0] = vld1q_u8(table);
tab.val[1] = vld1q_u8(table+16);
tab.val[2] = vld1q_u8(table+32);
tab.val[3] = vld1q_u8(table+48);
return tab;
static inline uint8x16x4_t load_uint8x16_4(const unsigned char *table)
{
uint8x16x4_t tab;
tab.val[0] = vld1q_u8(table);
tab.val[1] = vld1q_u8(table+16);
tab.val[2] = vld1q_u8(table+32);
tab.val[3] = vld1q_u8(table+48);
return tab;
}

#endif /* ARM Neon Support.*/
Expand Down Expand Up @@ -150,12 +151,12 @@ static inline TARGET_SSE2 FORCE_INLINE int compute_chunk_mask_sse2(const char *p
static inline TARGET_SSE2 FORCE_INLINE int string_scan_simd_sse2(const char **ptr, const char *end, int *mask)
{
while (*ptr + sizeof(__m128i) <= end) {
int chunk_mask = compute_chunk_mask_sse2(*ptr);
if (chunk_mask) {
*mask = chunk_mask;
return 1;
}
*ptr += sizeof(__m128i);
int chunk_mask = compute_chunk_mask_sse2(*ptr);
if (chunk_mask) {
*mask = chunk_mask;
return 1;
}
*ptr += sizeof(__m128i);
}

return 0;
Expand Down
8 changes: 4 additions & 4 deletions ext/openssl/lib/openssl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@

require 'openssl.so'

require_relative 'openssl/bn'
require_relative 'openssl/asn1'
require_relative 'openssl/pkey'
require_relative 'openssl/bn'
require_relative 'openssl/cipher'
require_relative 'openssl/digest'
require_relative 'openssl/hmac'
require_relative 'openssl/x509'
require_relative 'openssl/ssl'
require_relative 'openssl/pkcs5'
require_relative 'openssl/pkey'
require_relative 'openssl/ssl'
require_relative 'openssl/version'
require_relative 'openssl/x509'

module OpenSSL
# call-seq:
Expand Down
7 changes: 3 additions & 4 deletions ext/openssl/ossl_bn.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,9 @@ ossl_bn_new(const BIGNUM *bn)
VALUE obj;

obj = NewBN(cBN);
newbn = bn ? BN_dup(bn) : BN_new();
if (!newbn) {
ossl_raise(eBNError, NULL);
}
newbn = BN_dup(bn);
if (!newbn)
ossl_raise(eBNError, "BN_dup");
SetBN(obj, newbn);

return obj;
Expand Down
4 changes: 2 additions & 2 deletions ext/openssl/ossl_engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ ossl_engine_load_privkey(int argc, VALUE *argv, VALUE self)
GetEngine(self, e);
pkey = ENGINE_load_private_key(e, sid, NULL, sdata);
if (!pkey) ossl_raise(eEngineError, NULL);
obj = ossl_pkey_new(pkey);
obj = ossl_pkey_wrap(pkey);
OSSL_PKEY_SET_PRIVATE(obj);

return obj;
Expand Down Expand Up @@ -350,7 +350,7 @@ ossl_engine_load_pubkey(int argc, VALUE *argv, VALUE self)
pkey = ENGINE_load_public_key(e, sid, NULL, sdata);
if (!pkey) ossl_raise(eEngineError, NULL);

return ossl_pkey_new(pkey);
return ossl_pkey_wrap(pkey);
}

/*
Expand Down
2 changes: 1 addition & 1 deletion ext/openssl/ossl_ns_spki.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ ossl_spki_get_public_key(VALUE self)
ossl_raise(eSPKIError, NULL);
}

return ossl_pkey_new(pkey); /* NO DUP - OK */
return ossl_pkey_wrap(pkey);
}

/*
Expand Down
Loading