mirror of
https://github.com/simdjson/simdjson
synced 2026-06-08 17:27:07 +00:00
5510089d45
* Rename simdjson_really_inline -> simdjson_inline I want to change the simdjson_really_inline macro to sometimes not force inlining. After that upcoming change, the name simdjson_really_inline will no longer makes sense. Rename simdjson_really_inline to simdjson_inline. This patch should not change semantics; simdjson_inline still forces inlining as before. Some functions still need to be really inlined for ABI reasons. (GCC's -Wpsabi complains otherwise.) Leave those functions marked as simdjson_really_inline. * Improve build times for debug builds simdjson_inline is used for most simdjson functions. It forces inlining. In unoptimized/debug builds, this can lead to a lot of machine code being generated (especially with Address Sanitizer), causing slow compilation. Change simdjson_inline to force inlining only for optimized builds. Sometimes, the programmer might want a slightly-optimized build and want fast compilation (e.g. GCC's -Og mode). Allow simdjson users to define the simdjson_inline macro themselves (e.g. on the command line: -Dsimdjson_inline=inline) in cases where the default behavior is undesired. This patch reduced build times by over 75% for ondemand_object_tests.cpp with GCC 9.4.0 and CMAKE_BUILD_TYPE=Debug on my AMD 5950X: Before: 6.885 6.683 6.971 6.957 6.949 seconds (5 samples) After: 1.492 1.551 1.494 1.490 1.531 seconds (5 samples)
66 lines
1.9 KiB
C++
66 lines
1.9 KiB
C++
#ifndef SIMDJSON_PPC64_STRINGPARSING_H
|
|
#define SIMDJSON_PPC64_STRINGPARSING_H
|
|
|
|
#include "simdjson/base.h"
|
|
#include "simdjson/ppc64/bitmanipulation.h"
|
|
#include "simdjson/ppc64/simd.h"
|
|
|
|
namespace simdjson {
|
|
namespace SIMDJSON_IMPLEMENTATION {
|
|
namespace {
|
|
|
|
using namespace simd;
|
|
|
|
// Holds backslashes and quotes locations.
|
|
struct backslash_and_quote {
|
|
public:
|
|
static constexpr uint32_t BYTES_PROCESSED = 32;
|
|
simdjson_inline static backslash_and_quote
|
|
copy_and_find(const uint8_t *src, uint8_t *dst);
|
|
|
|
simdjson_inline bool has_quote_first() {
|
|
return ((bs_bits - 1) & quote_bits) != 0;
|
|
}
|
|
simdjson_inline bool has_backslash() { return bs_bits != 0; }
|
|
simdjson_inline int quote_index() {
|
|
return trailing_zeroes(quote_bits);
|
|
}
|
|
simdjson_inline int backslash_index() {
|
|
return trailing_zeroes(bs_bits);
|
|
}
|
|
|
|
uint32_t bs_bits;
|
|
uint32_t quote_bits;
|
|
}; // struct backslash_and_quote
|
|
|
|
simdjson_inline backslash_and_quote
|
|
backslash_and_quote::copy_and_find(const uint8_t *src, uint8_t *dst) {
|
|
// this can read up to 31 bytes beyond the buffer size, but we require
|
|
// SIMDJSON_PADDING of padding
|
|
static_assert(SIMDJSON_PADDING >= (BYTES_PROCESSED - 1),
|
|
"backslash and quote finder must process fewer than "
|
|
"SIMDJSON_PADDING bytes");
|
|
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
|
|
// PPC; 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();
|
|
return {
|
|
uint32_t(bs_and_quote), // bs_bits
|
|
uint32_t(bs_and_quote >> 32) // quote_bits
|
|
};
|
|
}
|
|
|
|
} // unnamed namespace
|
|
} // namespace SIMDJSON_IMPLEMENTATION
|
|
} // namespace simdjson
|
|
|
|
#include "simdjson/generic/stringparsing.h"
|
|
|
|
#endif // SIMDJSON_PPC64_STRINGPARSING_H
|