2019-08-21 19:59:49 +08:00
|
|
|
#ifndef SIMDJSON_ARM64_STRINGPARSING_H
|
|
|
|
#define SIMDJSON_ARM64_STRINGPARSING_H
|
2019-07-29 10:46:33 +08:00
|
|
|
|
2019-10-28 01:11:32 +08:00
|
|
|
#include "simdjson/portability.h"
|
|
|
|
|
2019-07-29 10:46:33 +08:00
|
|
|
#ifdef IS_ARM64
|
2019-08-21 19:59:49 +08:00
|
|
|
|
2019-10-07 03:39:55 +08:00
|
|
|
#include "simdjson/common_defs.h"
|
|
|
|
#include "simdjson/parsedjson.h"
|
2019-10-14 02:16:26 +08:00
|
|
|
#include "jsoncharutils.h"
|
2019-10-07 03:39:55 +08:00
|
|
|
|
|
|
|
#ifdef JSON_TEST_STRINGS
|
|
|
|
void found_string(const uint8_t *buf, const uint8_t *parsed_begin,
|
|
|
|
const uint8_t *parsed_end);
|
|
|
|
void found_bad_string(const uint8_t *buf);
|
|
|
|
#endif
|
2019-08-21 19:59:49 +08:00
|
|
|
|
|
|
|
namespace simdjson::arm64 {
|
|
|
|
|
2019-10-07 03:39:55 +08:00
|
|
|
// Holds backslashes and quotes locations.
|
|
|
|
struct parse_string_helper {
|
|
|
|
uint32_t bs_bits;
|
|
|
|
uint32_t quote_bits;
|
|
|
|
really_inline uint32_t bytes_processed() const { return sizeof(uint8x16_t)*2; }
|
|
|
|
};
|
|
|
|
|
2019-08-21 19:59:49 +08:00
|
|
|
really_inline parse_string_helper find_bs_bits_and_quote_bits(const uint8_t *src, uint8_t *dst) {
|
2019-07-31 05:18:10 +08:00
|
|
|
// this can read up to 31 bytes beyond the buffer size, but we require
|
|
|
|
// SIMDJSON_PADDING of padding
|
|
|
|
static_assert(2 * sizeof(uint8x16_t) - 1 <= SIMDJSON_PADDING);
|
|
|
|
uint8x16_t v0 = vld1q_u8(src);
|
|
|
|
uint8x16_t v1 = vld1q_u8(src + 16);
|
|
|
|
vst1q_u8(dst, v0);
|
|
|
|
vst1q_u8(dst + 16, v1);
|
2019-07-29 10:46:33 +08:00
|
|
|
|
2019-07-31 05:18:10 +08:00
|
|
|
uint8x16_t bs_mask = vmovq_n_u8('\\');
|
|
|
|
uint8x16_t qt_mask = vmovq_n_u8('"');
|
|
|
|
const uint8x16_t bit_mask = {0x01, 0x02, 0x4, 0x8, 0x10, 0x20, 0x40, 0x80,
|
|
|
|
0x01, 0x02, 0x4, 0x8, 0x10, 0x20, 0x40, 0x80};
|
|
|
|
uint8x16_t cmp_bs_0 = vceqq_u8(v0, bs_mask);
|
|
|
|
uint8x16_t cmp_bs_1 = vceqq_u8(v1, bs_mask);
|
|
|
|
uint8x16_t cmp_qt_0 = vceqq_u8(v0, qt_mask);
|
|
|
|
uint8x16_t cmp_qt_1 = vceqq_u8(v1, qt_mask);
|
|
|
|
|
|
|
|
cmp_bs_0 = vandq_u8(cmp_bs_0, bit_mask);
|
|
|
|
cmp_bs_1 = vandq_u8(cmp_bs_1, bit_mask);
|
|
|
|
cmp_qt_0 = vandq_u8(cmp_qt_0, bit_mask);
|
|
|
|
cmp_qt_1 = vandq_u8(cmp_qt_1, bit_mask);
|
|
|
|
|
|
|
|
uint8x16_t sum0 = vpaddq_u8(cmp_bs_0, cmp_bs_1);
|
|
|
|
uint8x16_t sum1 = vpaddq_u8(cmp_qt_0, cmp_qt_1);
|
|
|
|
sum0 = vpaddq_u8(sum0, sum1);
|
|
|
|
sum0 = vpaddq_u8(sum0, sum0);
|
|
|
|
return {
|
2019-07-29 10:46:33 +08:00
|
|
|
vgetq_lane_u32(vreinterpretq_u32_u8(sum0), 0), // bs_bits
|
2019-07-31 05:18:10 +08:00
|
|
|
vgetq_lane_u32(vreinterpretq_u32_u8(sum0), 1) // quote_bits
|
|
|
|
};
|
2019-08-21 19:59:49 +08:00
|
|
|
|
2019-07-29 10:46:33 +08:00
|
|
|
}
|
|
|
|
|
2019-08-21 19:59:49 +08:00
|
|
|
#include "generic/stringparsing.h"
|
2019-08-05 07:57:55 +08:00
|
|
|
|
2019-08-21 19:59:49 +08:00
|
|
|
}
|
|
|
|
// namespace simdjson::amd64
|
2019-08-05 03:58:35 +08:00
|
|
|
|
2019-08-05 07:57:55 +08:00
|
|
|
#endif // IS_ARM64
|
2019-07-29 10:46:33 +08:00
|
|
|
#endif
|