Skip to content

Commit c5d4aa1

Browse files
committed
wip(fsst): support big-endian systems
1 parent 1f33a0d commit c5d4aa1

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

fsst/libfsst.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -529,11 +529,11 @@ extern "C" u32 fsst_export(fsst_encoder_t *encoder, u8 *buf) {
529529
// The version field is now there just for future-proofness, but not used yet
530530

531531
// version allows keeping track of fsst versions, track endianness, and encoder reconstruction
532-
u64 version = (FSST_VERSION << 32) | // version is 24 bits, most significant byte is 0
532+
dwarfs::uint64le_t version((FSST_VERSION << 32) | // version is 24 bits, most significant byte is 0
533533
(((u64) e->symbolTable->suffixLim) << 24) |
534534
(((u64) e->symbolTable->terminator) << 16) |
535535
(((u64) e->symbolTable->nSymbols) << 8) |
536-
FSST_ENDIAN_MARKER; // least significant byte is nonzero
536+
FSST_ENDIAN_MARKER); // least significant byte is nonzero
537537

538538
/* do not assume unaligned reads here */
539539
memcpy(buf, &version, 8);
@@ -553,7 +553,7 @@ extern "C" u32 fsst_export(fsst_encoder_t *encoder, u8 *buf) {
553553
#define FSST_CORRUPT 32774747032022883 /* 7-byte number in little endian containing "corrupt" */
554554

555555
extern "C" u32 fsst_import(fsst_decoder_t *decoder, u8 const *buf) {
556-
u64 version = 0;
556+
dwarfs::uint64le_t version;
557557
u32 code, pos = 17;
558558
u8 lenHisto[8];
559559

fsst/libfsst.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
#include <fcntl.h>
3333
#include <stddef.h>
3434

35+
#include <dwarfs/endian.h>
36+
3537
using namespace std;
3638

3739
#include "fsst.h" // the official FSST API -- also usable by C mortals
@@ -61,7 +63,7 @@ typedef uint64_t u64;
6163

6264
namespace libfsst {
6365
inline uint64_t fsst_unaligned_load(u8 const* V) {
64-
uint64_t Ret;
66+
dwarfs::uint64le_t Ret;
6567
memcpy(&Ret, V, sizeof(uint64_t)); // compiler will generate efficient code (unaligned load, where possible)
6668
return Ret;
6769
}
@@ -70,7 +72,7 @@ struct Symbol {
7072
static const unsigned maxLength = 8;
7173

7274
// the byte sequence that this symbol stands for
73-
union { char str[maxLength]; u64 num; } val; // usually we process it as a num(ber), as this is fast
75+
union { char str[maxLength]; dwarfs::uint64le_t num{}; } val; // usually we process it as a num(ber), as this is fast
7476

7577
// icl = u64 ignoredBits:16,code:12,length:4,unused:32 -- but we avoid exposing this bit-field notation
7678
u64 icl; // use a single u64 to be sure "code" is accessed with one load and can be compared with one comparison

0 commit comments

Comments
 (0)