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
|
|
|
|
2020-03-06 02:30:28 +08:00
|
|
|
#include "simdjson.h"
|
2020-03-05 01:04:59 +08:00
|
|
|
#include "arm64/simd.h"
|
2019-12-17 08:09:18 +08:00
|
|
|
#include "arm64/bitmanipulation.h"
|
2019-10-07 03:39:55 +08:00
|
|
|
|
2020-07-24 22:32:12 +08:00
|
|
|
namespace {
|
2020-07-24 23:09:34 +08:00
|
|
|
namespace arm64 {
|
2019-08-21 19:59:49 +08:00
|
|
|
|
2019-10-28 01:51:54 +08:00
|
|
|
using namespace simd;
|
|
|
|
|
2019-10-07 03:39:55 +08:00
|
|
|
// Holds backslashes and quotes locations.
|
2020-03-16 03:50:09 +08:00
|
|
|
struct backslash_and_quote {
|
|
|
|
public:
|
|
|
|
static constexpr uint32_t BYTES_PROCESSED = 32;
|
|
|
|
really_inline static backslash_and_quote copy_and_find(const uint8_t *src, uint8_t *dst);
|
|
|
|
|
|
|
|
really_inline bool has_quote_first() { return ((bs_bits - 1) & quote_bits) != 0; }
|
|
|
|
really_inline bool has_backslash() { return bs_bits != 0; }
|
|
|
|
really_inline int quote_index() { return trailing_zeroes(quote_bits); }
|
|
|
|
really_inline int backslash_index() { return trailing_zeroes(bs_bits); }
|
|
|
|
|
2019-10-07 03:39:55 +08:00
|
|
|
uint32_t bs_bits;
|
|
|
|
uint32_t quote_bits;
|
2020-03-16 03:50:09 +08:00
|
|
|
}; // struct backslash_and_quote
|
2019-10-07 03:39:55 +08:00
|
|
|
|
2020-03-16 03:50:09 +08:00
|
|
|
really_inline backslash_and_quote backslash_and_quote::copy_and_find(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
|
2020-04-11 07:37:00 +08:00
|
|
|
static_assert(SIMDJSON_PADDING >= (BYTES_PROCESSED - 1), "backslash and quote finder must process fewer than SIMDJSON_PADDING bytes");
|
2019-10-28 01:51:54 +08:00
|
|
|
simd8<uint8_t> v0(src);
|
|
|
|
simd8<uint8_t> v1(src + sizeof(v0));
|
|
|
|
v0.store(dst);
|
|
|
|
v1.store(dst + sizeof(v0));
|
|
|
|
|
|
|
|
// Getting a 64-bit bitmask is much cheaper than multiple 16-bit bitmasks on ARM; therefore, we
|
|
|
|
// smash them together into a 64-byte mask and get the bitmask from there.
|
|
|
|
uint64_t bs_and_quote = simd8x64<bool>(v0 == '\\', v1 == '\\', v0 == '"', v1 == '"').to_bitmask();
|
2019-07-31 05:18:10 +08:00
|
|
|
return {
|
2020-04-22 06:43:35 +08:00
|
|
|
uint32_t(bs_and_quote), // bs_bits
|
|
|
|
uint32_t(bs_and_quote >> 32) // quote_bits
|
2019-07-31 05:18:10 +08:00
|
|
|
};
|
2019-07-29 10:46:33 +08:00
|
|
|
}
|
|
|
|
|
2020-04-11 07:37:00 +08:00
|
|
|
} // namespace arm64
|
2020-07-24 23:09:34 +08:00
|
|
|
} // namespace {
|
2019-08-05 03:58:35 +08:00
|
|
|
|
2020-07-17 03:56:02 +08:00
|
|
|
#include "generic/stage2/stringparsing.h"
|
|
|
|
|
2020-03-05 01:04:59 +08:00
|
|
|
#endif // SIMDJSON_ARM64_STRINGPARSING_H
|