Skip to content

Commit 798517a

Browse files
committed
gguf-hash: portable xxhash result print method
1 parent 72863d5 commit 798517a

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

examples/gguf-hash/gguf-hash.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,14 @@ static bool gguf_hash(const hash_params & hash_params) {
131131

132132
// Per Layer Hash
133133
XXH64_hash_t hash = XXH64(raw_data, n_bytes, 0);
134-
printf("xxhash %016lx %s:%s\n", hash, fname.c_str(), name);
134+
135+
char hex_result[17];
136+
for (int offset = 0; offset < 8; offset++) {
137+
unsigned int shift_bits_by = (8 * (8 - offset - 1));
138+
sprintf( ( hex_result + (2*offset)), "%02x", (unsigned char) (hash >> shift_bits_by)&0xff);
139+
}
140+
141+
printf("xxhash %s %s:%s\n", hex_result, fname.c_str(), name);
135142

136143
// Overall Model Hash
137144
if (XXH64_update(xxhash_model_hash_state, raw_data, n_bytes) == XXH_ERROR) abort();
@@ -157,7 +164,14 @@ static bool gguf_hash(const hash_params & hash_params) {
157164

158165
if (hash_params.xxhash) {
159166
XXH64_hash_t const hash = XXH64_digest(xxhash_model_hash_state);
160-
printf("xxhash %016lx %s\n", hash, fname.c_str());
167+
168+
char hex_result[17];
169+
for (int offset = 0; offset < 8; offset++) {
170+
unsigned int shift_bits_by = (8 * (8 - offset - 1));
171+
sprintf( ( hex_result + (2*offset)), "%02x", (unsigned char) (hash >> shift_bits_by)&0xff);
172+
}
173+
174+
printf("xxhash %s %s\n", hex_result, fname.c_str());
161175
}
162176

163177
if (hash_params.sha1) {

0 commit comments

Comments
 (0)