yeptris 0.6.64.0-riscv64-linux-gnu

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (164) hide show
  1. checksums.yaml +7 -0
  2. data/README.adoc +150 -0
  3. data/ext/build_windows_native.rb +60 -0
  4. data/ext/libyeptris/extconf.rb +57 -0
  5. data/ext/yeptris_native/cbor_ruby.c +198 -0
  6. data/ext/yeptris_native/extconf.rb +99 -0
  7. data/ext/yeptris_native/json_ruby.c +414 -0
  8. data/ext/yeptris_native/version.h +29 -0
  9. data/ext/yeptris_native/yeptris_native.c +507 -0
  10. data/lib/yeptris/3.3/native.so +0 -0
  11. data/lib/yeptris/cbor.rb +169 -0
  12. data/lib/yeptris/document.rb +319 -0
  13. data/lib/yeptris/ffi.rb +572 -0
  14. data/lib/yeptris/json/descriptor.rb +266 -0
  15. data/lib/yeptris/json.rb +502 -0
  16. data/lib/yeptris/materializer.rb +389 -0
  17. data/lib/yeptris/node.rb +482 -0
  18. data/lib/yeptris/psych/class_loader.rb +24 -0
  19. data/lib/yeptris/psych/coder_shim.rb +55 -0
  20. data/lib/yeptris/psych/drop_in.rb +63 -0
  21. data/lib/yeptris/psych/encodable.rb +14 -0
  22. data/lib/yeptris/psych/handler.rb +95 -0
  23. data/lib/yeptris/psych/parser.rb +114 -0
  24. data/lib/yeptris/psych/scalar_scanner.rb +149 -0
  25. data/lib/yeptris/psych/tree_builder.rb +119 -0
  26. data/lib/yeptris/psych/visitors.rb +670 -0
  27. data/lib/yeptris/psych.rb +796 -0
  28. data/lib/yeptris/schema.rb +253 -0
  29. data/lib/yeptris/validation.rb +320 -0
  30. data/lib/yeptris/valueml.rb +477 -0
  31. data/lib/yeptris/yaml/descriptor.rb +56 -0
  32. data/lib/yeptris/yaml.rb +668 -0
  33. data/lib/yeptris.rb +130 -0
  34. data/libyeptris.so +0 -0
  35. data/vendor/libyeptris/CMakeLists.txt +280 -0
  36. data/vendor/libyeptris/cmake/yeptris-config.cmake.in +5 -0
  37. data/vendor/libyeptris/cmake/yeptris.pc.in +11 -0
  38. data/vendor/libyeptris/src/CMakeLists.txt +183 -0
  39. data/vendor/libyeptris/src/include/yeptris/api.h +32 -0
  40. data/vendor/libyeptris/src/include/yeptris/cbor.h +174 -0
  41. data/vendor/libyeptris/src/include/yeptris/dom.h +196 -0
  42. data/vendor/libyeptris/src/include/yeptris/emit.h +128 -0
  43. data/vendor/libyeptris/src/include/yeptris/error.h +42 -0
  44. data/vendor/libyeptris/src/include/yeptris/events.h +171 -0
  45. data/vendor/libyeptris/src/include/yeptris/json.h +57 -0
  46. data/vendor/libyeptris/src/include/yeptris/json.hpp +258 -0
  47. data/vendor/libyeptris/src/include/yeptris/jsonc_compat.h +115 -0
  48. data/vendor/libyeptris/src/include/yeptris/marshal.h +75 -0
  49. data/vendor/libyeptris/src/include/yeptris/parse.h +121 -0
  50. data/vendor/libyeptris/src/include/yeptris/plan.h +100 -0
  51. data/vendor/libyeptris/src/include/yeptris/resolve.h +81 -0
  52. data/vendor/libyeptris/src/include/yeptris/schema.h +121 -0
  53. data/vendor/libyeptris/src/include/yeptris/tape.h +128 -0
  54. data/vendor/libyeptris/src/include/yeptris/types.h +38 -0
  55. data/vendor/libyeptris/src/include/yeptris/validate.h +401 -0
  56. data/vendor/libyeptris/src/include/yeptris/values.h +108 -0
  57. data/vendor/libyeptris/src/include/yeptris/version.h.in +29 -0
  58. data/vendor/libyeptris/src/include/yeptris/visit.h +77 -0
  59. data/vendor/libyeptris/src/include/yeptris/yajl_compat.h +135 -0
  60. data/vendor/libyeptris/src/include/yeptris.h +24 -0
  61. data/vendor/libyeptris/src/yeptris/build.c +393 -0
  62. data/vendor/libyeptris/src/yeptris/cbor/cbor.h +35 -0
  63. data/vendor/libyeptris/src/yeptris/cbor/decode.c +1054 -0
  64. data/vendor/libyeptris/src/yeptris/cbor/encode.c +836 -0
  65. data/vendor/libyeptris/src/yeptris/cbor/encode_priv.h +32 -0
  66. data/vendor/libyeptris/src/yeptris/cbor/from_marshal.c +982 -0
  67. data/vendor/libyeptris/src/yeptris/cbor/sink.h +36 -0
  68. data/vendor/libyeptris/src/yeptris/common/chartype.c +41 -0
  69. data/vendor/libyeptris/src/yeptris/common/chartype.h +77 -0
  70. data/vendor/libyeptris/src/yeptris/common/cpu.c +81 -0
  71. data/vendor/libyeptris/src/yeptris/common/cpu.h +40 -0
  72. data/vendor/libyeptris/src/yeptris/common/error.c +65 -0
  73. data/vendor/libyeptris/src/yeptris/common/error.h +81 -0
  74. data/vendor/libyeptris/src/yeptris/common/mutex.h +45 -0
  75. data/vendor/libyeptris/src/yeptris/common/nametab.c +275 -0
  76. data/vendor/libyeptris/src/yeptris/common/nametab.h +68 -0
  77. data/vendor/libyeptris/src/yeptris/common/port.h +74 -0
  78. data/vendor/libyeptris/src/yeptris/common/simd_text.c +49 -0
  79. data/vendor/libyeptris/src/yeptris/common/simd_text.h +342 -0
  80. data/vendor/libyeptris/src/yeptris/common/simd_text_avx2.c +672 -0
  81. data/vendor/libyeptris/src/yeptris/common/simd_text_neon.c +793 -0
  82. data/vendor/libyeptris/src/yeptris/common/simd_text_scalar.c +324 -0
  83. data/vendor/libyeptris/src/yeptris/common/string_view.c +34 -0
  84. data/vendor/libyeptris/src/yeptris/common/string_view.h +93 -0
  85. data/vendor/libyeptris/src/yeptris/doc.h +86 -0
  86. data/vendor/libyeptris/src/yeptris/dom/dom.c +1312 -0
  87. data/vendor/libyeptris/src/yeptris/dom/dom.h +332 -0
  88. data/vendor/libyeptris/src/yeptris/dom/hpool.c +107 -0
  89. data/vendor/libyeptris/src/yeptris/dom/mapindex.c +173 -0
  90. data/vendor/libyeptris/src/yeptris/dom/mapindex.h +61 -0
  91. data/vendor/libyeptris/src/yeptris/dom/mutate.c +431 -0
  92. data/vendor/libyeptris/src/yeptris/dom/ytape.c +2323 -0
  93. data/vendor/libyeptris/src/yeptris/dom/ytape.h +96 -0
  94. data/vendor/libyeptris/src/yeptris/emit/emit.c +670 -0
  95. data/vendor/libyeptris/src/yeptris/emit/float/api.h +43 -0
  96. data/vendor/libyeptris/src/yeptris/emit/float/dragon.c +405 -0
  97. data/vendor/libyeptris/src/yeptris/emit/float/floatint.h +231 -0
  98. data/vendor/libyeptris/src/yeptris/emit/float/fpconv.c +428 -0
  99. data/vendor/libyeptris/src/yeptris/emit/float/print.c +396 -0
  100. data/vendor/libyeptris/src/yeptris/emit/style.c +21 -0
  101. data/vendor/libyeptris/src/yeptris/emit/style.h +32 -0
  102. data/vendor/libyeptris/src/yeptris/emit/writer.c +1951 -0
  103. data/vendor/libyeptris/src/yeptris/emit/writer.h +111 -0
  104. data/vendor/libyeptris/src/yeptris/encoding/bom.c +31 -0
  105. data/vendor/libyeptris/src/yeptris/encoding/encoding.h +63 -0
  106. data/vendor/libyeptris/src/yeptris/encoding/transcode.c +157 -0
  107. data/vendor/libyeptris/src/yeptris/encoding/utf8_validate.c +178 -0
  108. data/vendor/libyeptris/src/yeptris/events/capture.c +166 -0
  109. data/vendor/libyeptris/src/yeptris/events/capture.h +39 -0
  110. data/vendor/libyeptris/src/yeptris/events/iterparse.c +298 -0
  111. data/vendor/libyeptris/src/yeptris/events/pull.c +117 -0
  112. data/vendor/libyeptris/src/yeptris/events/push.c +151 -0
  113. data/vendor/libyeptris/src/yeptris/events/recorder.c +144 -0
  114. data/vendor/libyeptris/src/yeptris/events/values.c +630 -0
  115. data/vendor/libyeptris/src/yeptris/events/values_priv.h +53 -0
  116. data/vendor/libyeptris/src/yeptris/events/yaml_compat.c +86 -0
  117. data/vendor/libyeptris/src/yeptris/events/yaml_compat.h +90 -0
  118. data/vendor/libyeptris/src/yeptris/jsonapi/jsonc_compat.c +687 -0
  119. data/vendor/libyeptris/src/yeptris/jsonapi/yajl_compat.c +728 -0
  120. data/vendor/libyeptris/src/yeptris/marshal/to_json.c +650 -0
  121. data/vendor/libyeptris/src/yeptris/marshal.c +988 -0
  122. data/vendor/libyeptris/src/yeptris/memory/allocator.c +20 -0
  123. data/vendor/libyeptris/src/yeptris/memory/allocator.h +43 -0
  124. data/vendor/libyeptris/src/yeptris/memory/arena.c +150 -0
  125. data/vendor/libyeptris/src/yeptris/memory/arena.h +52 -0
  126. data/vendor/libyeptris/src/yeptris/memory/pool.c +133 -0
  127. data/vendor/libyeptris/src/yeptris/memory/pool.h +36 -0
  128. data/vendor/libyeptris/src/yeptris/parse/engine.c +6528 -0
  129. data/vendor/libyeptris/src/yeptris/parse/engine.h +96 -0
  130. data/vendor/libyeptris/src/yeptris/parse/events.h +137 -0
  131. data/vendor/libyeptris/src/yeptris/parse/numbers.c +374 -0
  132. data/vendor/libyeptris/src/yeptris/parse/numbers.h +33 -0
  133. data/vendor/libyeptris/src/yeptris/parse/scalars.c +435 -0
  134. data/vendor/libyeptris/src/yeptris/parse/scalars.h +87 -0
  135. data/vendor/libyeptris/src/yeptris/parse/stream_iter.c +358 -0
  136. data/vendor/libyeptris/src/yeptris/parse.c +1074 -0
  137. data/vendor/libyeptris/src/yeptris/plan.c +824 -0
  138. data/vendor/libyeptris/src/yeptris/resolve/compat11.c +339 -0
  139. data/vendor/libyeptris/src/yeptris/resolve/core12.c +153 -0
  140. data/vendor/libyeptris/src/yeptris/resolve/full12.c +201 -0
  141. data/vendor/libyeptris/src/yeptris/resolve/json12.c +109 -0
  142. data/vendor/libyeptris/src/yeptris/resolve/resolver.h +103 -0
  143. data/vendor/libyeptris/src/yeptris/resolve/tags.c +250 -0
  144. data/vendor/libyeptris/src/yeptris/scan/json.c +839 -0
  145. data/vendor/libyeptris/src/yeptris/scan/json.h +116 -0
  146. data/vendor/libyeptris/src/yeptris/scan/scan.c +862 -0
  147. data/vendor/libyeptris/src/yeptris/scan/scan.h +177 -0
  148. data/vendor/libyeptris/src/yeptris/schema.c +309 -0
  149. data/vendor/libyeptris/src/yeptris/tape.c +2375 -0
  150. data/vendor/libyeptris/src/yeptris/tape_in.h +39 -0
  151. data/vendor/libyeptris/src/yeptris/validate/compile.c +306 -0
  152. data/vendor/libyeptris/src/yeptris/validate/internal.h +347 -0
  153. data/vendor/libyeptris/src/yeptris/validate/jsonschema.c +1922 -0
  154. data/vendor/libyeptris/src/yeptris/validate/output.c +246 -0
  155. data/vendor/libyeptris/src/yeptris/validate/regexp.c +1600 -0
  156. data/vendor/libyeptris/src/yeptris/validate/registry.c +118 -0
  157. data/vendor/libyeptris/src/yeptris/validate/resources.c +601 -0
  158. data/vendor/libyeptris/src/yeptris/validate/stream.c +1155 -0
  159. data/vendor/libyeptris/src/yeptris/validate/validate.c +1043 -0
  160. data/vendor/libyeptris/src/yeptris/version.c +7 -0
  161. data/vendor/libyeptris/src/yeptris/visit/dom_visit.c +115 -0
  162. data/vendor/libyeptris/src/yeptris/visit/json_visit.c +293 -0
  163. data/vendor/libyeptris/src/yeptris/visit/yaml_visit.c +127 -0
  164. metadata +221 -0
@@ -0,0 +1,342 @@
1
+ /* simd_text.h — SIMD-accelerated text scan primitives (TODO.impl/04).
2
+ *
3
+ * AOT framework (the libleptris pattern): a scalar reference TU is always
4
+ * compiled; AVX2 / NEON TUs are compiled separately with the right -m
5
+ * flags; dispatch picks the best table once via cpu detection. Callers go
6
+ * through yep_text_active() — never call an ISA table directly.
7
+ *
8
+ * Contract (every implementation, every ISA):
9
+ * - functions read AT MOST len bytes; no faults past the end
10
+ * (length-guarded chunking, never full-width loads beyond len);
11
+ * - len == 0 is valid: contains/count/find_not-style predicates return
12
+ * their empty answer, finds return -1;
13
+ * - results are bit-identical to the scalar reference — enforced by the
14
+ * differential suite (test_simd_text.cpp), which compares against naive
15
+ * test-local references, not against our own scalar TU.
16
+ */
17
+ #ifndef YEP_SIMD_TEXT_H
18
+ #define YEP_SIMD_TEXT_H
19
+
20
+ #include <stddef.h>
21
+ #include <stdint.h>
22
+
23
+ #include "port.h" /* yep_ctz64: the SWAR walks' first-set-lane extraction */
24
+
25
+ #ifdef __cplusplus
26
+ extern "C" {
27
+ #endif
28
+
29
+ /* One-pass pre-scan statistics: the ten occurrence counts every
30
+ * content-derived sizing rule needs (arena/node pre-reserve, engine
31
+ * anchor pre-reserve) plus the ASCII/printable flags that gate the
32
+ * UTF-8 validator. Fills the role of four separate full-buffer
33
+ * passes (printable_validate's SWAR loop + three count3 calls). */
34
+ typedef struct yep_text_stats {
35
+ size_t nl, comma, dash, colon, bracket, brace, dq, sq, pipe, amp;
36
+ int nonascii; /* any byte >= 0x80 present */
37
+ int bad_printable; /* an ASCII byte violating c-printable (not 9/10/13/0x20..0x7E) */
38
+ } yep_text_stats;
39
+
40
+ /* A byte-class stop set. The 256-bit bitmap is the truth (the scalar
41
+ * fallback reads it); lo/hi are derived nibble-class tables the vector
42
+ * kernels classify lanes with — member #k of group g sets bit k in
43
+ * lo[g][b&15] and hi[g][b>>4], so a lane matches iff some member has
44
+ * both nibbles of the lane byte: exact, no false positives (the
45
+ * SIMD/scalar differential suite pins it). Constant sets embed
46
+ * prebuilt literals (pinned against this init by StopsetLiterals). */
47
+ #define YEP_STOPSET_GROUPS 4 /* 32 members — every YAML stop class fits */
48
+
49
+ typedef struct yep_stopset {
50
+ unsigned char bitmap[32];
51
+ uint8_t groups; /* nibble-class groups in use; >GROUPS = vector kernels
52
+ decline (scalar bitmap walk stays correct) */
53
+ unsigned char lo[YEP_STOPSET_GROUPS][16];
54
+ unsigned char hi[YEP_STOPSET_GROUPS][16];
55
+ } yep_stopset;
56
+
57
+ static inline void yep_stopset_init(yep_stopset* ss, const unsigned char bitmap[32]) {
58
+ for (size_t i = 0; i < sizeof(*ss); i++) {
59
+ ((unsigned char*)ss)[i] = 0;
60
+ }
61
+ unsigned n = 0;
62
+ for (unsigned b = 0; b < 256; b++) {
63
+ if ((bitmap[b >> 3] >> (b & 7)) & 1) {
64
+ ss->bitmap[b >> 3] |= (unsigned char)(1u << (b & 7));
65
+ if (n < YEP_STOPSET_GROUPS * 8) {
66
+ ss->lo[n >> 3][b & 15] |= (unsigned char)(1u << (n & 7));
67
+ ss->hi[n >> 3][b >> 4] |= (unsigned char)(1u << (n & 7));
68
+ }
69
+ n++;
70
+ }
71
+ }
72
+ ss->groups = (uint8_t)((n + 7) >> 3);
73
+ }
74
+
75
+ /* The line-facts sweep's output (one `key: value` line's positions).
76
+ * end is the first \n/\r at/after pos (or len); indent the first
77
+ * byte != ' ' (spaces only — tabs are the caller's rule, as in
78
+ * yep_scan_line); stop the first block-plain stop byte at/after the
79
+ * indent and strictly before end, stop_set=0 when none exists.
80
+ * stop2 is the SECOND block-plain stop byte at/after indent (same
81
+ * class as stop: \n \r # :), stop2_set=0 when none exists — the
82
+ * value-side side output (TODO.max-perf/03): the pair arm's plain
83
+ * value starts past stop, so its first stop byte is stop2, computed
84
+ * over the same sweep instead of a second pass. flags bit0 mirrors
85
+ * stop2_set (uint32-packed so the struct stays sweep-width); bit1
86
+ * has_high marks any byte >= 0x80 in [pos, end) — the multibyte
87
+ * break-lead law needs the lead probe, so a facts consumer may take
88
+ * a zero-probe fast path only when the span is pure ASCII. */
89
+ #define YEP_FACTS_STOP2 0x1u
90
+ #define YEP_FACTS_HIGH 0x2u
91
+ typedef struct yep_line_facts {
92
+ uint32_t end;
93
+ uint32_t indent;
94
+ uint32_t stop;
95
+ uint32_t stop_set;
96
+ uint32_t stop2;
97
+ uint32_t flags;
98
+ } yep_line_facts;
99
+
100
+ /* The flow-kernel chunk classifier's output (one <=32-byte chunk):
101
+ * bit i of each mask = byte i of the chunk. The five classes — quote,
102
+ * backslash, structural ({,},[,],,:), value-start (0-9,-,t,f,n), and
103
+ * raw C0 — give the token walk every class it dispatches on; valid
104
+ * marks the bytes that exist (partial tail chunk). Bit-identical
105
+ * across ISAs. */
106
+ typedef struct yep_chunk_masks {
107
+ uint32_t quote;
108
+ uint32_t bs;
109
+ uint32_t structurals;
110
+ uint32_t valstart; /* 0-9, '-', 't', 'f', 'n' — scalar-token starts */
111
+ uint32_t c0; /* bytes < 0x20 (raw controls) */
112
+ uint32_t valid; /* 1-bits for the bytes that exist (tails) */
113
+ } yep_chunk_masks;
114
+
115
+ /* one 64-byte block's classification (json_stage1_masks) */
116
+ struct yep_s1_block {
117
+ uint64_t q; /* raw quote bytes */
118
+ uint64_t bs; /* backslash bytes */
119
+ uint64_t op; /* []{}:, */
120
+ uint64_t c0; /* bytes < 0x20 (ws included) */
121
+ uint64_t tokens; /* the resolver's verdict: ops + string-open quotes */
122
+ };
123
+
124
+ /* The kernel table. One struct = one dispatch point (OCP: a new ISA is a
125
+ * new TU exporting a new table; nothing else changes). */
126
+ typedef struct yep_text_kernels {
127
+ /* nonzero iff c occurs in [s, s+len) */
128
+ int (*contains)(const char* s, size_t len, char c);
129
+
130
+ /* offset of the first c, or -1 */
131
+ ptrdiff_t (*find)(const char* s, size_t len, char c);
132
+
133
+ /* offset of the first c0c1c2 run, or -1; len < 3 -> -1 */
134
+ ptrdiff_t (*find3)(const char* s, size_t len, char c0, char c1, char c2);
135
+
136
+ /* occurrences of c */
137
+ size_t (*count_char)(const char* s, size_t len, char c);
138
+
139
+ /* three counts in one memory pass (arena sizing pre-scan, 06) */
140
+ void (*count3)(const char* s, size_t len, char c0, char c1, char c2, size_t* n0, size_t* n1,
141
+ size_t* n2);
142
+
143
+ /* memcpy + count3 fused: one traversal (TODO 188 pattern) */
144
+ void (*copy_count3)(char* dst, const char* src, size_t len, char c0, char c1, char c2,
145
+ size_t* n0, size_t* n1, size_t* n2);
146
+
147
+ /* offset of the first byte != c, or -1 (indentation column scan) */
148
+ ptrdiff_t (*find_not)(const char* s, size_t len, char c);
149
+
150
+ /* offset of the first byte in the stop set, or -1 (plain-scalar
151
+ * end detection: ": " / " #" / line-break / flow stops) */
152
+ ptrdiff_t (*stopset_find)(const yep_stopset* ss, const char* s, size_t len);
153
+
154
+ /* Given the content AFTER an opening quote: offset of the closing
155
+ * quote q honoring backslash escapes, or -1 if unterminated.
156
+ * *has_escape is set to 1 iff a backslash occurred (0 otherwise). */
157
+ ptrdiff_t (*quote_scan)(const char* s, size_t len, char q, int* has_escape);
158
+
159
+ /* the fused pre-scan above (results bit-identical across ISAs) */
160
+ void (*scan_stats)(const char* s, size_t len, yep_text_stats* out);
161
+
162
+ /* offset of the first byte that is a double quote, a backslash,
163
+ * or a C0 control — the JSON string-stop set (scan/json.c owns
164
+ * the grammar; simd_text owns the finding). One SIMD pass,
165
+ * three compares OR'd; bit-identical across ISAs. */
166
+ ptrdiff_t (*qbc_find)(const char* s, size_t len);
167
+
168
+ /* 0 iff EVERY byte is gate-safe (0x20-0x7E, 09, 0A, 0D) — the
169
+ * encoding gate's fast answer; 1 means the authoritative validator
170
+ * must rule (non-ASCII may still be valid UTF-8). Replaces the
171
+ * multi-class stats sweep at parse entry (TODO.restructure/66).
172
+ * Bit-identical across ISAs. */
173
+ int (*gate_scan)(const char* s, size_t len);
174
+
175
+ /* The fused line-facts sweep (TODO.restructure/76): one pass
176
+ * yields the four positions a block line needs — first break,
177
+ * first non-space (indent), and the first block-plain stop byte
178
+ * ({\n \r # :}) at or after the indent. scan.c derives every
179
+ * line/shape fact from these; the old paths re-walked the same
180
+ * bytes per fact. Bit-identical across ISAs. */
181
+ void (*line_facts)(const char* s, size_t len, size_t pos, yep_line_facts* out);
182
+
183
+ /* The flow-kernel chunk classifier (the JSON tape's stage 1
184
+ * foundation): five byte-class masks for one <=32-byte chunk
185
+ * (quote, backslash, structurals, value-starts, C0). n must be
186
+ * <= 32; reads exactly n bytes. Bit-identical across ISAs. */
187
+ yep_chunk_masks (*json_chunk)(const char* p, size_t n);
188
+
189
+ /* The JSON structural indexer (the simdjson stage-1 shape, the
190
+ * token-contract front): walks the whole buffer in 64-byte blocks
191
+ * and writes, in position order, the u32 offsets of every token
192
+ * stage 2 dispatches on — operators ([]{}:,), string OPEN quotes
193
+ * (escape-aware, the borrow-trick scanner), and scalar-run starts
194
+ * (a non-operator non-whitespace byte whose predecessor was not
195
+ * one). String interiors and close quotes never appear; ws bytes
196
+ * are never touched by stage 2. No grammar validation: the only
197
+ * hard error is an unterminated string (odd final parity) ->
198
+ * return 0. idx must hold len+2 entries. Bit-identical across
199
+ * ISAs (the differential suite pins it); scan/json.c owns the
200
+ * grammar contract. flags (never NULL) accumulates YEP_S1_* bits:
201
+ * the doc-level facts stage 2 needs to skip content scanning. */
202
+ int (*json_stage1)(const char* p, size_t len, uint32_t* idx, size_t* nidx, unsigned* flags);
203
+
204
+ /* The structural indexer's classification half, without the
205
+ * emission: per 64-byte block, the four u64 masks the resolver
206
+ * consumes (QUOTE/BS/OP/C0; ws is dead since the token contract
207
+ * dropped scalar-run starts). blocks receives len/64+1 records;
208
+ * *nblocks returns how many were written. Same reject/flag
209
+ * contract as json_stage1. The single-pass tape walk consumes
210
+ * this — no idx array, no emission loop. */
211
+ int (*json_stage1_masks)(const char* p, size_t len, struct yep_s1_block* blocks,
212
+ size_t* nblocks, unsigned* flags);
213
+ } yep_text_kernels;
214
+
215
+ /* json_stage1 flag bits (accumulated across blocks; cleared by caller) */
216
+ #define YEP_S1_C0_IN_STRING 1u /* raw non-ws C0 inside a string: reject */
217
+ #define YEP_S1_HAS_ESCAPE 2u /* a backslash byte exists: validate spans */
218
+
219
+ /* The structural indexer's mask resolver — the SSOT identity set for
220
+ * every json_stage1 implementation (scalar in scan/json.c, the ISA
221
+ * twins in the SIMD TUs). Given one 64-byte block's QUOTE/BS/OP/WS
222
+ * masks (bit k = byte k, valid masking tail bytes) plus the three
223
+ * carried bits (string parity, escape parity, scalar-follows), it
224
+ * derives the token mask and appends positions to idx:
225
+ *
226
+ * escaped = the simdjson escape scanner's ODD_BITS borrow trick
227
+ * (real escapes + odd-run terminals ^ bs|carry)
228
+ * in_string = prefix_xor(live quotes) ^ prev parity
229
+ * string_tail= in_string ^ live quotes (interiors + closes)
230
+ * starts = ~(op|ws) & ~follows (scalar-run heads; quotes
231
+ * are scalars, a non-quote scalar extends a run)
232
+ * tokens = (op | starts) & ~string_tail
233
+ *
234
+ * Returns the block's contribution; carries update in place. */
235
+ static inline uint64_t yep_json_stage1_tokens(uint64_t q, uint64_t bs, uint64_t op, uint64_t c0,
236
+ uint64_t valid, uint64_t* prev_in_string,
237
+ uint64_t* esc_carry, unsigned* flags) {
238
+ uint64_t potential = bs & ~*esc_carry;
239
+ uint64_t s = (((potential << 1) | 0xAAAAAAAAAAAAAAAAull) - potential) ^ 0xAAAAAAAAAAAAAAAAull;
240
+ uint64_t escaped = s ^ (bs | *esc_carry);
241
+ *esc_carry = (s & bs) >> 63;
242
+ uint64_t quote_live = q & ~escaped;
243
+ uint64_t ps = quote_live; /* sequential prefix-xor — a flat
244
+ * one-expression xor of shifts misses
245
+ * the cross terms (the naive caught it) */
246
+ ps ^= ps << 1;
247
+ ps ^= ps << 2;
248
+ ps ^= ps << 4;
249
+ ps ^= ps << 8;
250
+ ps ^= ps << 16;
251
+ ps ^= ps << 32;
252
+ uint64_t in_string = ps ^ *prev_in_string;
253
+ *prev_in_string = (uint64_t)((int64_t)in_string >> 63);
254
+ uint64_t string_tail = (in_string ^ quote_live) & valid;
255
+ if (bs != 0) {
256
+ *flags |= YEP_S1_HAS_ESCAPE;
257
+ }
258
+ if ((c0 & in_string & valid) != 0) {
259
+ *flags |= YEP_S1_C0_IN_STRING;
260
+ }
261
+ return (op | (quote_live & ~string_tail)) & ~string_tail & valid;
262
+ }
263
+
264
+ /* The full resolver: token mask derivation + the idx emission loop
265
+ * (the json_stage1 implementations). */
266
+ static inline size_t yep_json_stage1_resolve(uint64_t q, uint64_t bs, uint64_t op, uint64_t ws,
267
+ uint64_t c0, uint64_t valid, uint64_t* prev_in_string,
268
+ uint64_t* esc_carry, size_t off, uint32_t* idx,
269
+ size_t n, unsigned* flags) {
270
+ uint64_t tokens =
271
+ yep_json_stage1_tokens(q, bs, op, c0, valid, prev_in_string, esc_carry, flags);
272
+ while (tokens != 0) {
273
+ idx[n++] = (uint32_t)(off + (size_t)yep_ctz64(tokens));
274
+ tokens &= tokens - 1;
275
+ }
276
+ return n;
277
+ }
278
+
279
+ /* The best table for this CPU (atomic-lazy, like yep_cpu_detect). */
280
+ const yep_text_kernels* yep_text_active(void);
281
+
282
+ /* Scalar reference implementations — callable directly for differential
283
+ * testing and as fallbacks. The active() table never points here on CPUs
284
+ * with a vector ISA we compiled. */
285
+ int yep_text_contains_scalar(const char* s, size_t len, char c);
286
+ ptrdiff_t yep_text_find_scalar(const char* s, size_t len, char c);
287
+ ptrdiff_t yep_text_find3_scalar(const char* s, size_t len, char c0, char c1, char c2);
288
+ size_t yep_text_count_char_scalar(const char* s, size_t len, char c);
289
+ void yep_text_count3_scalar(const char* s, size_t len, char c0, char c1, char c2, size_t* n0,
290
+ size_t* n1, size_t* n2);
291
+ void yep_text_copy_count3_scalar(char* dst, const char* src, size_t len, char c0, char c1, char c2,
292
+ size_t* n0, size_t* n1, size_t* n2);
293
+ ptrdiff_t yep_text_qbc_find_scalar(const char* s, size_t len);
294
+ ptrdiff_t yep_text_find_not_scalar(const char* s, size_t len, char c);
295
+ ptrdiff_t yep_text_stopset_find_scalar(const yep_stopset* ss, const char* s, size_t len);
296
+ ptrdiff_t yep_text_quote_scan_scalar(const char* s, size_t len, char q, int* has_escape);
297
+ void yep_text_scan_stats_scalar(const char* s, size_t len, yep_text_stats* out);
298
+ int yep_text_gate_scan_scalar(const char* s, size_t len);
299
+ void yep_text_line_facts_scalar(const char* s, size_t len, size_t pos, yep_line_facts* out);
300
+ yep_chunk_masks yep_text_json_chunk_scalar(const char* p, size_t n);
301
+ /* The SWAR walk bounded: settles the facts when the line's break sits
302
+ * within cap bytes (or the buffer ends) — 0 means a longer line, the
303
+ * caller sweeps. The ISA kernels use it as BOTH the short-line test
304
+ * and the short-line answer (no probe-then-rescan). */
305
+ int yep_text_line_facts_capped(const char* s, size_t len, size_t pos, size_t cap,
306
+ yep_line_facts* out);
307
+
308
+ /* SWAR byte flags: 0x80 at every byte equal to k (little-endian
309
+ * lanes — every supported target is LE). The subtract-based zero
310
+ * test is NOT exact: a 0x01 byte under a borrow chain from zero
311
+ * bytes below false-flags ('!' = 0x21 ^ ' ' = 0x01 read as a space —
312
+ * the corpus caught it); this form is carry-free per byte. */
313
+ #define YEP_SWAR_FLAGS 0x8080808080808080ull
314
+
315
+ static inline uint64_t yep_swar_eq8(uint64_t x, uint64_t k) {
316
+ uint64_t v = x ^ k;
317
+ uint64_t low = (v & 0x7F7F7F7F7F7F7F7Full) + 0x7F7F7F7F7F7F7F7Full;
318
+ uint64_t nz = (low | v) & YEP_SWAR_FLAGS;
319
+ return ~nz & YEP_SWAR_FLAGS;
320
+ }
321
+
322
+ /* Stopset bitmap helpers: a 256-bit bitmap is the wire form of a byte
323
+ * class; build with yep_stopset_clear + yep_stopset_add. */
324
+ static inline void yep_stopset_clear(unsigned char set[32]) {
325
+ for (int i = 0; i < 32; i++) {
326
+ set[i] = 0;
327
+ }
328
+ }
329
+
330
+ static inline void yep_stopset_add(unsigned char set[32], unsigned char c) {
331
+ set[c >> 3] |= (unsigned char)(1u << (c & 7));
332
+ }
333
+
334
+ static inline int yep_stopset_test(const unsigned char set[32], unsigned char c) {
335
+ return (set[c >> 3] >> (c & 7)) & 1;
336
+ }
337
+
338
+ #ifdef __cplusplus
339
+ }
340
+ #endif
341
+
342
+ #endif /* YEP_SIMD_TEXT_H */