Skip to content

Commit 41f33ec

Browse files
committed
Permit 32-bit GCC compilation
1 parent 86241e2 commit 41f33ec

File tree

7 files changed

+72
-35
lines changed

7 files changed

+72
-35
lines changed

include/simdjson/portability.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,14 @@
3737

3838
#if defined(__x86_64__) || defined(_M_AMD64)
3939
#define SIMDJSON_IS_X86_64 1
40-
#endif
41-
#if defined(__aarch64__) || defined(_M_ARM64)
40+
#elif defined(__aarch64__) || defined(_M_ARM64)
4241
#define SIMDJSON_IS_ARM64 1
42+
#else
43+
#define SIMDJSON_IS_32BITS 1
4344
#endif
4445

45-
#if (!defined(SIMDJSON_IS_X86_64)) && (!defined(SIMDJSON_IS_ARM64))
46-
#ifdef SIMDJSON_REGULAR_VISUAL_STUDIO
46+
#ifdef SIMDJSON_IS_32BITS
47+
#if defined(SIMDJSON_REGULAR_VISUAL_STUDIO) || defined(__GNUC__)
4748
#pragma message("The simdjson library is designed\
4849
for 64-bit processors and it seems that you are not \
4950
compiling for a known 64-bit platform. All fast kernels \
@@ -54,7 +55,7 @@ use a 64-bit target such as x64 or 64-bit ARM.")
5455
for 64-bit processors. It seems that you are not \
5556
compiling for a known 64-bit platform."
5657
#endif
57-
#endif // (!defined(SIMDJSON_IS_X86_64)) && (!defined(SIMDJSON_IS_ARM64))
58+
#endif // SIMDJSON_IS_32BITS
5859
5960
// this is almost standard?
6061
#undef STRINGIFY_IMPLEMENTATION_

singleheader/amalgamate_demo.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* auto-generated on Tue 23 Jun 2020 20:51:12 EDT. Do not edit! */
1+
/* auto-generated on Thu Jun 25 16:43:19 PDT 2020. Do not edit! */
22

33
#include <iostream>
44
#include "simdjson.h"
@@ -43,3 +43,4 @@ int main(int argc, char *argv[]) {
4343
}
4444
return EXIT_SUCCESS;
4545
}
46+

singleheader/simdjson.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* auto-generated on Tue 23 Jun 2020 20:51:12 EDT. Do not edit! */
1+
/* auto-generated on Thu Jun 25 16:43:19 PDT 2020. Do not edit! */
22
/* begin file src/simdjson.cpp */
33
#include "simdjson.h"
44

@@ -934,9 +934,8 @@ struct value128 {
934934
uint64_t high;
935935
};
936936

937-
#if defined(SIMDJSON_REGULAR_VISUAL_STUDIO) && \
938-
!defined(_M_X64) && !defined(_M_ARM64)// _umul128 for x86, arm
939-
// this is a slow emulation routine for 32-bit Windows
937+
#ifdef SIMDJSON_IS_32BITS // _umul128 for x86, arm
938+
// this is a slow emulation routine for 32-bit
940939
//
941940
static inline uint64_t __emulu(uint32_t x, uint32_t y) {
942941
return x * (uint64_t)y;
@@ -955,15 +954,15 @@ static inline uint64_t _umul128(uint64_t ab, uint64_t cd, uint64_t *hi) {
955954

956955
really_inline value128 full_multiplication(uint64_t value1, uint64_t value2) {
957956
value128 answer;
958-
#ifdef SIMDJSON_REGULAR_VISUAL_STUDIO
957+
#if defined(SIMDJSON_REGULAR_VISUAL_STUDIO) || defined(SIMDJSON_IS_32BITS)
959958
#ifdef _M_ARM64
960959
// ARM64 has native support for 64-bit multiplications, no need to emultate
961960
answer.high = __umulh(value1, value2);
962961
answer.low = value1 * value2;
963962
#else
964963
answer.low = _umul128(value1, value2, &answer.high); // _umul128 not available on ARM64
965964
#endif // _M_ARM64
966-
#else // SIMDJSON_REGULAR_VISUAL_STUDIO
965+
#else // defined(SIMDJSON_REGULAR_VISUAL_STUDIO) || defined(SIMDJSON_IS_32BITS)
967966
__uint128_t r = ((__uint128_t)value1) * value2;
968967
answer.low = uint64_t(r);
969968
answer.high = uint64_t(r >> 64);
@@ -7826,7 +7825,7 @@ really_inline bool add_overflow(uint64_t value1, uint64_t value2,
78267825
#endif
78277826
}
78287827

7829-
#ifdef SIMDJSON_REGULAR_VISUAL_STUDIO
7828+
#if defined(SIMDJSON_REGULAR_VISUAL_STUDIO) || defined(SIMDJSON_IS_32BITS)
78307829
#pragma intrinsic(_umul128)
78317830
#endif
78327831
really_inline bool mul_overflow(uint64_t value1, uint64_t value2,
@@ -11114,7 +11113,7 @@ really_inline bool add_overflow(uint64_t value1, uint64_t value2,
1111411113
#endif
1111511114
}
1111611115

11117-
#ifdef SIMDJSON_REGULAR_VISUAL_STUDIO
11116+
#if defined(SIMDJSON_REGULAR_VISUAL_STUDIO) || defined(SIMDJSON_IS_32BITS)
1111811117
#pragma intrinsic(_umul128)
1111911118
#endif
1112011119
really_inline bool mul_overflow(uint64_t value1, uint64_t value2,

singleheader/simdjson.h

Lines changed: 51 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* auto-generated on Tue 23 Jun 2020 20:51:12 EDT. Do not edit! */
1+
/* auto-generated on Thu Jun 25 16:43:19 PDT 2020. Do not edit! */
22
/* begin file include/simdjson.h */
33
#ifndef SIMDJSON_H
44
#define SIMDJSON_H
@@ -91,13 +91,14 @@
9191

9292
#if defined(__x86_64__) || defined(_M_AMD64)
9393
#define SIMDJSON_IS_X86_64 1
94-
#endif
95-
#if defined(__aarch64__) || defined(_M_ARM64)
94+
#elif defined(__aarch64__) || defined(_M_ARM64)
9695
#define SIMDJSON_IS_ARM64 1
96+
#else
97+
#define SIMDJSON_IS_32BITS 1
9798
#endif
9899

99-
#if (!defined(SIMDJSON_IS_X86_64)) && (!defined(SIMDJSON_IS_ARM64))
100-
#ifdef SIMDJSON_REGULAR_VISUAL_STUDIO
100+
#ifdef SIMDJSON_IS_32BITS
101+
#if defined(SIMDJSON_REGULAR_VISUAL_STUDIO) || defined(__GNUC__)
101102
#pragma message("The simdjson library is designed\
102103
for 64-bit processors and it seems that you are not \
103104
compiling for a known 64-bit platform. All fast kernels \
@@ -108,7 +109,7 @@ use a 64-bit target such as x64 or 64-bit ARM.")
108109
for 64-bit processors. It seems that you are not \
109110
compiling for a known 64-bit platform."
110111
#endif
111-
#endif // (!defined(SIMDJSON_IS_X86_64)) && (!defined(SIMDJSON_IS_ARM64))
112+
#endif // SIMDJSON_IS_32BITS
112113
113114
// this is almost standard?
114115
#undef STRINGIFY_IMPLEMENTATION_
@@ -2632,7 +2633,6 @@ inline error_code dom_parser_implementation::allocate(size_t capacity, size_t ma
26322633
26332634
#endif // SIMDJSON_INTERNAL_DOM_PARSER_IMPLEMENTATION_H
26342635
/* end file include/simdjson/internal/dom_parser_implementation.h */
2635-
#include <optional>
26362636
#include <string>
26372637
#include <atomic>
26382638
#include <vector>
@@ -4008,21 +4008,42 @@ class element {
40084008
*/
40094009
inline simdjson_result<object> get_object() const noexcept;
40104010
/**
4011-
* Cast this element to a string.
4011+
* Cast this element to a null-terminated C string.
4012+
*
4013+
* The string is guaranteed to be valid UTF-8.
40124014
*
4013-
* Equivalent to get<const char *>().
4015+
* The get_c_str() function is equivalent to get<const char *>().
4016+
*
4017+
* The length of the string is given by get_string_length(). Because JSON strings
4018+
* may contain null characters, it may be incorrect to use strlen to determine the
4019+
* string length.
4020+
*
4021+
* It is possible to get a single string_view instance which represents both the string
4022+
* content and its length: see get_string().
40144023
*
4015-
* @returns An pointer to a null-terminated string. This string is stored in the parser and will
4024+
* @returns A pointer to a null-terminated UTF-8 string. This string is stored in the parser and will
40164025
* be invalidated the next time it parses a document or when it is destroyed.
40174026
* Returns INCORRECT_TYPE if the JSON element is not a string.
40184027
*/
40194028
inline simdjson_result<const char *> get_c_str() const noexcept;
40204029
/**
4021-
* Cast this element to a string.
4030+
* Gives the length in bytes of the string.
4031+
*
4032+
* It is possible to get a single string_view instance which represents both the string
4033+
* content and its length: see get_string().
4034+
*
4035+
* @returns A string length in bytes.
4036+
* Returns INCORRECT_TYPE if the JSON element is not a string.
4037+
*/
4038+
inline simdjson_result<size_t> get_string_length() const noexcept;
4039+
/**
4040+
* Cast this element to a string.
4041+
*
4042+
* The string is guaranteed to be valid UTF-8.
40224043
*
40234044
* Equivalent to get<std::string_view>().
40244045
*
4025-
* @returns A string. The string is stored in the parser and will be invalidated the next time it
4046+
* @returns An UTF-8 string. The string is stored in the parser and will be invalidated the next time it
40264047
* parses a document or when it is destroyed.
40274048
* Returns INCORRECT_TYPE if the JSON element is not a string.
40284049
*/
@@ -4199,7 +4220,9 @@ class element {
41994220
inline operator bool() const noexcept(false);
42004221

42014222
/**
4202-
* Read this element as a null-terminated string.
4223+
* Read this element as a null-terminated UTF-8 string.
4224+
*
4225+
* Be mindful that JSON allows strings to contain null characters.
42034226
*
42044227
* Does *not* convert other types to a string; requires that the JSON type of the element was
42054228
* an actual string.
@@ -4210,7 +4233,7 @@ class element {
42104233
inline explicit operator const char*() const noexcept(false);
42114234

42124235
/**
4213-
* Read this element as a null-terminated string.
4236+
* Read this element as a null-terminated UTF-8 string.
42144237
*
42154238
* Does *not* convert other types to a string; requires that the JSON type of the element was
42164239
* an actual string.
@@ -4410,6 +4433,7 @@ struct simdjson_result<dom::element> : public internal::simdjson_result_base<dom
44104433
really_inline simdjson_result<dom::array> get_array() const noexcept;
44114434
really_inline simdjson_result<dom::object> get_object() const noexcept;
44124435
really_inline simdjson_result<const char *> get_c_str() const noexcept;
4436+
really_inline simdjson_result<size_t> get_string_length() const noexcept;
44134437
really_inline simdjson_result<std::string_view> get_string() const noexcept;
44144438
really_inline simdjson_result<int64_t> get_int64() const noexcept;
44154439
really_inline simdjson_result<uint64_t> get_uint64() const noexcept;
@@ -5820,6 +5844,10 @@ really_inline simdjson_result<const char *> simdjson_result<dom::element>::get_c
58205844
if (error()) { return error(); }
58215845
return first.get_c_str();
58225846
}
5847+
really_inline simdjson_result<size_t> simdjson_result<dom::element>::get_string_length() const noexcept {
5848+
if (error()) { return error(); }
5849+
return first.get_string_length();
5850+
}
58235851
really_inline simdjson_result<std::string_view> simdjson_result<dom::element>::get_string() const noexcept {
58245852
if (error()) { return error(); }
58255853
return first.get_string();
@@ -5960,6 +5988,15 @@ inline simdjson_result<const char *> element::get_c_str() const noexcept {
59605988
return INCORRECT_TYPE;
59615989
}
59625990
}
5991+
inline simdjson_result<size_t> element::get_string_length() const noexcept {
5992+
switch (tape.tape_ref_type()) {
5993+
case internal::tape_type::STRING: {
5994+
return tape.get_string_length();
5995+
}
5996+
default:
5997+
return INCORRECT_TYPE;
5998+
}
5999+
}
59636000
inline simdjson_result<std::string_view> element::get_string() const noexcept {
59646001
switch (tape.tape_ref_type()) {
59656002
case internal::tape_type::STRING:

src/haswell/bitmanipulation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ really_inline bool add_overflow(uint64_t value1, uint64_t value2,
5858
#endif
5959
}
6060

61-
#ifdef SIMDJSON_REGULAR_VISUAL_STUDIO
61+
#if defined(SIMDJSON_REGULAR_VISUAL_STUDIO) || defined(SIMDJSON_IS_32BITS)
6262
#pragma intrinsic(_umul128)
6363
#endif
6464
really_inline bool mul_overflow(uint64_t value1, uint64_t value2,

src/jsoncharutils.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -317,9 +317,8 @@ struct value128 {
317317
uint64_t high;
318318
};
319319

320-
#if defined(SIMDJSON_REGULAR_VISUAL_STUDIO) && \
321-
!defined(_M_X64) && !defined(_M_ARM64)// _umul128 for x86, arm
322-
// this is a slow emulation routine for 32-bit Windows
320+
#ifdef SIMDJSON_IS_32BITS // _umul128 for x86, arm
321+
// this is a slow emulation routine for 32-bit
323322
//
324323
static inline uint64_t __emulu(uint32_t x, uint32_t y) {
325324
return x * (uint64_t)y;
@@ -338,15 +337,15 @@ static inline uint64_t _umul128(uint64_t ab, uint64_t cd, uint64_t *hi) {
338337

339338
really_inline value128 full_multiplication(uint64_t value1, uint64_t value2) {
340339
value128 answer;
341-
#ifdef SIMDJSON_REGULAR_VISUAL_STUDIO
340+
#if defined(SIMDJSON_REGULAR_VISUAL_STUDIO) || defined(SIMDJSON_IS_32BITS)
342341
#ifdef _M_ARM64
343342
// ARM64 has native support for 64-bit multiplications, no need to emultate
344343
answer.high = __umulh(value1, value2);
345344
answer.low = value1 * value2;
346345
#else
347346
answer.low = _umul128(value1, value2, &answer.high); // _umul128 not available on ARM64
348347
#endif // _M_ARM64
349-
#else // SIMDJSON_REGULAR_VISUAL_STUDIO
348+
#else // defined(SIMDJSON_REGULAR_VISUAL_STUDIO) || defined(SIMDJSON_IS_32BITS)
350349
__uint128_t r = ((__uint128_t)value1) * value2;
351350
answer.low = uint64_t(r);
352351
answer.high = uint64_t(r >> 64);

src/westmere/bitmanipulation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ really_inline bool add_overflow(uint64_t value1, uint64_t value2,
6666
#endif
6767
}
6868

69-
#ifdef SIMDJSON_REGULAR_VISUAL_STUDIO
69+
#if defined(SIMDJSON_REGULAR_VISUAL_STUDIO) || defined(SIMDJSON_IS_32BITS)
7070
#pragma intrinsic(_umul128)
7171
#endif
7272
really_inline bool mul_overflow(uint64_t value1, uint64_t value2,

0 commit comments

Comments
 (0)