Skip to content
Open
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
35 changes: 35 additions & 0 deletions include/m_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
#include "my_global.h" /* HAVE_* */

#include <string.h>
#if defined(__aarch64__)
#include <arm_neon.h>
#endif

#define bfill please_use_memset_rather_than_bfill
#ifdef bzero
Expand Down Expand Up @@ -340,6 +343,38 @@ static inline const uchar *skip_trailing_space(const uchar *ptr,size_t len)
end--;
return (end);
}
#elif defined(__aarch64__)
static inline const uchar *skip_trailing_space(const uchar *ptr, size_t len)
{
const uchar *end = ptr + len;
const size_t neno_vector_length = 16;
const uint8x16_t space_vec = vdupq_n_u8(0x20);
const uchar *current_end = end - neno_vector_length;
size_t vector_size = len >> 4;

while (vector_size > 0) {
uint8x16_t data_vec = vld1q_u8(current_end);
uint8x16_t result = vceqq_u8(data_vec, space_vec);

if (vminvq_u8(result) == 0) {
break;
}
vector_size--;
end -= neno_vector_length;
current_end -= neno_vector_length;
}

while (end - ptr >= 8) {
if (uint8korr(end-8) != 0x2020202020202020ULL) {
break;
}
end-= 8;
}
while (end > ptr && end[-1] == 0x20) {
end--;
}
return (end);
}
#else
/*
Reads 8 bytes at a time, ignoring alignment.
Expand Down
9 changes: 2 additions & 7 deletions storage/innobase/row/row0mysql.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1195,10 +1195,7 @@ row_mysql_store_col_in_innobase_format(
break;
case 1:
/* space=0x20 */
while (col_len > 0
&& ptr[col_len - 1] == 0x20) {
col_len--;
}
col_len = skip_trailing_space(ptr, col_len) - ptr;
}
}
} else if (comp && type == DATA_MYSQL
Expand Down Expand Up @@ -1234,9 +1231,7 @@ row_mysql_store_col_in_innobase_format(
n_chars = dtype_get_len(dtype) / dtype_get_mbmaxlen(dtype);

/* Strip space padding. */
while (col_len > n_chars && ptr[col_len - 1] == 0x20) {
col_len--;
}
col_len = skip_trailing_space(ptr + n_chars, col_len - n_chars) - ptr;
} else if (!row_format_col) {
/* if mysql data is from a MySQL key value
since the length is always stored in 2 bytes,
Expand Down
78 changes: 78 additions & 0 deletions strings/ctype-mb.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
#include <my_global.h>
#include "m_ctype.h"
#include "m_string.h"
#if defined(__aarch64__)
#include <arm_neon.h>
#endif


size_t my_caseup_str_mb(const CHARSET_INFO *cs, char *str)
Expand Down Expand Up @@ -383,6 +386,80 @@ int my_wildcmp_mb(const CHARSET_INFO *cs,
}


#if defined(__aarch64__)
size_t my_numchars_mb(const CHARSET_INFO *cs MY_ATTRIBUTE((unused)),
const char *pos, const char *end)
{
size_t count = 0;

if ((cs->state & MY_CS_UNICODE) && !(cs->state & MY_CS_NONASCII))
{
const uint8x16_t max_ascii = vdupq_n_u8(0x7F);
const size_t neon_vector_length = 16;

while (pos + neon_vector_length <= end)
{
uint8x16_t vec_src = vld1q_u8((const unsigned char *)pos);
// check if exists non-ascii character
// ascii -> non zero, non-ascii -> zero
uint8x16_t result = vcleq_u8(vec_src, max_ascii);
if (vminvq_u8(result) == 0)
{
// has non-ascii character
break;
}

count += neon_vector_length;
pos += neon_vector_length;
}
}

while (pos < end)
{
uint mb_len;
pos += (mb_len = my_ismbchar(cs, pos, end)) ? mb_len : 1;
count++;
}
return count;
}


size_t my_charpos_mb(const CHARSET_INFO *cs MY_ATTRIBUTE((unused)),
const char *pos, const char *end, size_t length)
{
const char *start = pos;

if ((cs->state & MY_CS_UNICODE) && !(cs->state & MY_CS_NONASCII))
{
const uint8x16_t max_ascii = vdupq_n_u8(0x7F);
const size_t neon_vector_length = 16;

while (length >= neon_vector_length && pos + neon_vector_length <= end)
{
uint8x16_t vec_src = vld1q_u8((const unsigned char *)pos);
// check if exists non-ascii character
// ascii -> non zero, non-ascii -> zero
uint8x16_t result = vcleq_u8(vec_src, max_ascii);
if (vminvq_u8(result) == 0)
{
// has non-ascii character
break;
}

length -= neon_vector_length;
pos += neon_vector_length;
}
}

while (length && pos < end)
{
uint mb_len;
pos += (mb_len = my_ismbchar(cs, pos, end)) ? mb_len : 1;
length--;
}
return (size_t) (length ? end+2-start : pos-start);
}
#else
size_t my_numchars_mb(const CHARSET_INFO *cs MY_ATTRIBUTE((unused)),
const char *pos, const char *end)
{
Expand Down Expand Up @@ -410,6 +487,7 @@ size_t my_charpos_mb(const CHARSET_INFO *cs MY_ATTRIBUTE((unused)),
}
return (size_t) (length ? end+2-start : pos-start);
}
#endif


size_t my_well_formed_len_mb(const CHARSET_INFO *cs, const char *b,
Expand Down
Loading