Skip to content

Commit 0cd3c02

Browse files
committed
release: 1.1.25
1 parent c43684d commit 0cd3c02

4 files changed

Lines changed: 11 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Change Log
22

3+
## 2025-12-21 - 1.1.25
4+
5+
- feat: Implement SWAR-based string serialization
6+
37
## 2025-11-28 - 1.1.24
48

59
- feat: Implement a moving average window to determine buffer size (essentially, allow the buffer size to shrink) [#163](https://github.com/JairusSW/json-as/pull/163)

assembly/serialize/swar/string.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export function serializeString_SWAR(src: string): void {
4141

4242
while (mask != 0) {
4343
const lane_index = usize(ctz(mask) >> 3);
44-
// console.log("lane index " + lane_index.toString());
44+
console.log("lane index " + lane_index.toString());
4545
const src_offset = srcStart + lane_index;
4646
const code = load<u16>(src_offset) << 2;
4747
const escaped = load<u32>(SERIALIZE_ESCAPE_TABLE + code);
@@ -51,13 +51,15 @@ export function serializeString_SWAR(src: string): void {
5151
const dst_offset = bs.offset + lane_index;
5252
store<u64>(dst_offset, U00_MARKER);
5353
store<u32>(dst_offset, escaped, 8);
54-
store<u64>(dst_offset, load<u64>(src_offset, 2), 12); // unsafe. can overflow here
54+
// store<u64>(dst_offset, load<u64>(src_offset, 2), 12); // unsafe. can overflow here
55+
memory.copy(dst_offset + 12, src_offset + 2, (4 - lane_index) << 1);
5556
bs.offset += 10;
5657
} else {
5758
bs.growSize(2);
5859
const dst_offset = bs.offset + lane_index;
5960
store<u32>(dst_offset, escaped);
60-
store<u64>(dst_offset, load<u64>(src_offset, 2), 4);
61+
// store<u64>(dst_offset, load<u64>(src_offset, 2), 4);
62+
memory.copy(dst_offset + 4, src_offset + 2, (4 - lane_index) << 1);
6163
bs.offset += 2;
6264
}
6365

assembly/test.tmp.ts

-41 Bytes
Binary file not shown.

assembly/test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ import { bs } from "../lib/as-bs";
22
import { serializeString_SIMD } from "./serialize/simd/string";
33
import { serializeString_SWAR } from "./serialize/swar/string";
44

5-
serializeString_SWAR("a\0b\"\nd");
6-
serializeString_SIMD("a\0b\"\nd");
5+
serializeString_SWAR("a\"cd");
6+
// serializeString_SIMD("a\0b\"\nd");
77
console.log(bs.out<string>());

0 commit comments

Comments
 (0)