forked from simdjson/simdjson
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
18ab3c6
commit ab23f36
Showing
26 changed files
with
838 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#ifndef SIMDJSON_LASX_H | ||
#define SIMDJSON_LASX_H | ||
|
||
#include "simdjson/lasx/begin.h" | ||
#include "simdjson/generic/amalgamated.h" | ||
#include "simdjson/lasx/end.h" | ||
|
||
#endif // SIMDJSON_LASX_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#ifndef SIMDJSON_LASX_BASE_H | ||
#define SIMDJSON_LASX_BASE_H | ||
|
||
#ifndef SIMDJSON_CONDITIONAL_INCLUDE | ||
#include "simdjson/base.h" | ||
#endif // SIMDJSON_CONDITIONAL_INCLUDE | ||
|
||
namespace simdjson { | ||
/** | ||
* Implementation for LASX. | ||
*/ | ||
namespace lasx { | ||
|
||
class implementation; | ||
|
||
namespace { | ||
namespace simd { | ||
template <typename T> struct simd8; | ||
template <typename T> struct simd8x64; | ||
} // namespace simd | ||
} // unnamed namespace | ||
|
||
} // namespace lasx | ||
} // namespace simdjson | ||
|
||
#endif // SIMDJSON_LASX_BASE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#define SIMDJSON_IMPLEMENTATION lasx | ||
#include "simdjson/lasx/base.h" | ||
#include "simdjson/lasx/intrinsics.h" | ||
#include "simdjson/lasx/bitmanipulation.h" | ||
#include "simdjson/lasx/bitmask.h" | ||
#include "simdjson/lasx/numberparsing_defs.h" | ||
#include "simdjson/lasx/simd.h" | ||
#include "simdjson/lasx/stringparsing_defs.h" | ||
|
||
#define SIMDJSON_SKIP_BACKSLASH_SHORT_CIRCUIT 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#ifndef SIMDJSON_LASX_BITMANIPULATION_H | ||
#define SIMDJSON_LASX_BITMANIPULATION_H | ||
|
||
#ifndef SIMDJSON_CONDITIONAL_INCLUDE | ||
#include "simdjson/lasx/base.h" | ||
#include "simdjson/lasx/intrinsics.h" | ||
#include "simdjson/lasx/bitmask.h" | ||
#endif // SIMDJSON_CONDITIONAL_INCLUDE | ||
|
||
namespace simdjson { | ||
namespace lasx { | ||
namespace { | ||
|
||
// We sometimes call trailing_zero on inputs that are zero, | ||
// but the algorithms do not end up using the returned value. | ||
// Sadly, sanitizers are not smart enough to figure it out. | ||
SIMDJSON_NO_SANITIZE_UNDEFINED | ||
// This function can be used safely even if not all bytes have been | ||
// initialized. | ||
// See issue https://github.com/simdjson/simdjson/issues/1965 | ||
SIMDJSON_NO_SANITIZE_MEMORY | ||
simdjson_inline int trailing_zeroes(uint64_t input_num) { | ||
return __builtin_ctzll(input_num); | ||
} | ||
|
||
/* result might be undefined when input_num is zero */ | ||
simdjson_inline uint64_t clear_lowest_bit(uint64_t input_num) { | ||
return input_num & (input_num-1); | ||
} | ||
|
||
/* result might be undefined when input_num is zero */ | ||
simdjson_inline int leading_zeroes(uint64_t input_num) { | ||
return __builtin_clzll(input_num); | ||
} | ||
|
||
/* result might be undefined when input_num is zero */ | ||
simdjson_inline int count_ones(uint64_t input_num) { | ||
return __lasx_xvpickve2gr_w(__lasx_xvpcnt_d(__m256i(v4u64{input_num, 0, 0, 0})), 0); | ||
} | ||
|
||
simdjson_inline bool add_overflow(uint64_t value1, uint64_t value2, uint64_t *result) { | ||
return __builtin_uaddll_overflow(value1, value2, | ||
reinterpret_cast<unsigned long long *>(result)); | ||
} | ||
|
||
} // unnamed namespace | ||
} // namespace lasx | ||
} // namespace simdjson | ||
|
||
#endif // SIMDJSON_LASX_BITMANIPULATION_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#ifndef SIMDJSON_LASX_BITMASK_H | ||
#define SIMDJSON_LASX_BITMASK_H | ||
|
||
#ifndef SIMDJSON_CONDITIONAL_INCLUDE | ||
#include "simdjson/lasx/base.h" | ||
#endif // SIMDJSON_CONDITIONAL_INCLUDE | ||
|
||
namespace simdjson { | ||
namespace lasx { | ||
namespace { | ||
|
||
// | ||
// Perform a "cumulative bitwise xor," flipping bits each time a 1 is encountered. | ||
// | ||
// For example, prefix_xor(00100100) == 00011100 | ||
// | ||
simdjson_inline uint64_t prefix_xor(uint64_t bitmask) { | ||
bitmask ^= bitmask << 1; | ||
bitmask ^= bitmask << 2; | ||
bitmask ^= bitmask << 4; | ||
bitmask ^= bitmask << 8; | ||
bitmask ^= bitmask << 16; | ||
bitmask ^= bitmask << 32; | ||
return bitmask; | ||
} | ||
|
||
} // unnamed namespace | ||
} // namespace lasx | ||
} // namespace simdjson | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#ifndef SIMDJSON_CONDITIONAL_INCLUDE | ||
#include "simdjson/lasx/base.h" | ||
#endif // SIMDJSON_CONDITIONAL_INCLUDE | ||
|
||
#undef SIMDJSON_SKIP_BACKSLASH_SHORT_CIRCUIT | ||
#undef SIMDJSON_IMPLEMENTATION |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#ifndef SIMDJSON_LASX_IMPLEMENTATION_H | ||
#define SIMDJSON_LASX_IMPLEMENTATION_H | ||
|
||
#ifndef SIMDJSON_CONDITIONAL_INCLUDE | ||
#include "simdjson/base.h" | ||
#include "simdjson/implementation.h" | ||
#include "simdjson/internal/instruction_set.h" | ||
#endif // SIMDJSON_CONDITIONAL_INCLUDE | ||
|
||
namespace simdjson { | ||
namespace lasx { | ||
|
||
/** | ||
* @private | ||
*/ | ||
class implementation final : public simdjson::implementation { | ||
public: | ||
simdjson_inline implementation() : simdjson::implementation("lasx", "LoongArch ASX", internal::instruction_set::LASX) {} | ||
simdjson_warn_unused error_code create_dom_parser_implementation( | ||
size_t capacity, | ||
size_t max_length, | ||
std::unique_ptr<internal::dom_parser_implementation>& dst | ||
) const noexcept final; | ||
simdjson_warn_unused error_code minify(const uint8_t *buf, size_t len, uint8_t *dst, size_t &dst_len) const noexcept final; | ||
simdjson_warn_unused bool validate_utf8(const char *buf, size_t len) const noexcept final; | ||
}; | ||
|
||
} // namespace lasx | ||
} // namespace simdjson | ||
|
||
#endif // SIMDJSON_LASX_IMPLEMENTATION_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#ifndef SIMDJSON_LASX_INTRINSICS_H | ||
#define SIMDJSON_LASX_INTRINSICS_H | ||
|
||
#ifndef SIMDJSON_CONDITIONAL_INCLUDE | ||
#include "simdjson/lasx/base.h" | ||
#endif // SIMDJSON_CONDITIONAL_INCLUDE | ||
|
||
// This should be the correct header whether | ||
// you use visual studio or other compilers. | ||
#include <lasxintrin.h> | ||
|
||
static_assert(sizeof(__m256i) <= simdjson::SIMDJSON_PADDING, "insufficient padding for LoongArch ASX"); | ||
|
||
#endif // SIMDJSON_LASX_INTRINSICS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#ifndef SIMDJSON_LASX_NUMBERPARSING_DEFS_H | ||
#define SIMDJSON_LASX_NUMBERPARSING_DEFS_H | ||
|
||
#ifndef SIMDJSON_CONDITIONAL_INCLUDE | ||
#include "simdjson/lasx/base.h" | ||
#include "simdjson/lasx/intrinsics.h" | ||
#include "simdjson/internal/numberparsing_tables.h" | ||
#endif // SIMDJSON_CONDITIONAL_INCLUDE | ||
|
||
#include <cstring> | ||
|
||
namespace simdjson { | ||
namespace lasx { | ||
namespace numberparsing { | ||
|
||
// we don't have appropriate instructions, so let us use a scalar function | ||
// credit: https://johnnylee-sde.github.io/Fast-numeric-string-to-int/ | ||
/** @private */ | ||
static simdjson_inline uint32_t parse_eight_digits_unrolled(const uint8_t *chars) { | ||
uint64_t val; | ||
std::memcpy(&val, chars, sizeof(uint64_t)); | ||
val = (val & 0x0F0F0F0F0F0F0F0F) * 2561 >> 8; | ||
val = (val & 0x00FF00FF00FF00FF) * 6553601 >> 16; | ||
return uint32_t((val & 0x0000FFFF0000FFFF) * 42949672960001 >> 32); | ||
} | ||
|
||
simdjson_inline internal::value128 full_multiplication(uint64_t value1, uint64_t value2) { | ||
internal::value128 answer; | ||
__uint128_t r = (static_cast<__uint128_t>(value1)) * value2; | ||
answer.low = uint64_t(r); | ||
answer.high = uint64_t(r >> 64); | ||
return answer; | ||
} | ||
|
||
} // namespace numberparsing | ||
} // namespace lasx | ||
} // namespace simdjson | ||
|
||
#define SIMDJSON_SWAR_NUMBER_PARSING 1 | ||
|
||
#endif // SIMDJSON_LASX_NUMBERPARSING_DEFS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#ifndef SIMDJSON_LASX_ONDEMAND_H | ||
#define SIMDJSON_LASX_ONDEMAND_H | ||
|
||
#include "simdjson/lasx/begin.h" | ||
#include "simdjson/generic/ondemand/amalgamated.h" | ||
#include "simdjson/lasx/end.h" | ||
|
||
#endif // SIMDJSON_LASX_ONDEMAND_H |
Oops, something went wrong.