diff options
| author | steven-na <noreply.github@stvnc.dev> | 2026-08-21 23:16:44 -0700 |
|---|---|---|
| committer | steven-na <noreply.github@stvnc.dev> | 2026-08-21 23:16:44 -0700 |
| commit | fee3f00c6d8a855b4372a0367e0b3e9dcea76699 (patch) | |
| tree | ab423c6b1f43e3eb53c88a6a55a95d932fbbd19b /src | |
| parent | b844718a1687424b2748608cbb52fb4012417fe5 (diff) | |
Added printf attr to log funcs
Diffstat (limited to 'src')
| -rw-r--r-- | src/deque.c | 2 | ||||
| -rw-r--r-- | src/log.h | 1 | ||||
| -rw-r--r-- | src/map.c | 13 | ||||
| -rw-r--r-- | src/string.c | 17 | ||||
| -rw-r--r-- | src/threadpool.c | 3 |
5 files changed, 25 insertions, 11 deletions
diff --git a/src/deque.c b/src/deque.c index 1046575..c66b25e 100644 --- a/src/deque.c +++ b/src/deque.c @@ -65,7 +65,7 @@ ts_deque_t ts_deque_create(smrt_arena_t *arena, ez_deque_t *q) { sem_init(s, 0, 0); #ifndef NLOG_TRACE - log_trace("Created thread-safe Deque; queue %p", q); + log_trace("Created thread-safe Deque; queue %p", (void*)q); #endif /* ifndef NLOG_TRACE */ return (ts_deque_t){ @@ -35,4 +35,5 @@ void log_set_fp(FILE *log_file); const char *log_get_level(); +__attribute__((format(printf, 4, 5))) void log_log(LogLevelE lvl, const char *src_file, u64 src_line, const char *fmt, ...); @@ -1,10 +1,10 @@ #include "map.h" #include "common.h" #include "smrt_arena.h" +#include "log.h" #include "../include/a5hash.h" -#include <immintrin.h> #include <stdint.h> #include <string.h> @@ -34,6 +34,11 @@ map_t map_create(smrt_arena_t *arena, u64 capacity) { map->values = SMRTA_ALLOC_ARRAY(arena, void*, capacity); map->table_size = capacity; + #ifndef NLOG_TRACE + log_trace("Created hashmap; Total capacity %lu", + capacity); + #endif /* ifndef NLOG_TRACE */ + return map; } @@ -73,6 +78,8 @@ i32 map_insert(map_t const map, u8 const *key, u64 keylen, void *value) { } } + log_warn("Attempted to insert value with key \"%.*s...\" into hashmap that is full", + (i32)MIN(5, keylen), key); return -1; } @@ -107,7 +114,7 @@ void *map_lookup(map_t const map, u8 const *key, u64 keylen) { u64 tsize = map->table_size; for (u64 i = start; i != start - 1; i = (i+1)%tsize) { u8 h_lookupcmp = map->hashlookup[i]; - if (h_lookupcmp == ENTRY_EMPTY) return NULL; + if (h_lookupcmp == ENTRY_EMPTY) break; if (h_lookupcmp == ENTRY_TOMBSTONE) continue; map_key_entry_t k = map->keys[i]; @@ -115,7 +122,7 @@ void *map_lookup(map_t const map, u8 const *key, u64 keylen) { h == map->hashes[i] && k.keylen == keylen && (memcmp(key, k.key, keylen) == 0)) - { return map->values[i]; } + { return map->values[i]; } } return NULL; diff --git a/src/string.c b/src/string.c index 795eb95..63c886a 100644 --- a/src/string.c +++ b/src/string.c @@ -224,11 +224,13 @@ i32 sv_find_substr(strng_view_t const *sv, char const *_needle) { char const *restrict haystack = sv->string+sv->start; char const *restrict needle = _needle; - __m256i first_vec = _mm256_set1_epi8(*needle); - u64 end_idx = hlen - nlen + 1; u64 i = 0; + if (hlen < 32) goto lt_32; + + __m256i first_vec = _mm256_set1_epi8(*needle); + for (; i + 32 <= end_idx; i += 32) { __m256i hay_vec = _mm256_loadu_si256((const __m256i*)(haystack+i)); __m256i cmp = _mm256_cmpeq_epi8(hay_vec, first_vec); @@ -236,12 +238,13 @@ i32 sv_find_substr(strng_view_t const *sv, char const *_needle) { while (mask != 0) { i32 offset = __builtin_ctz(mask); - if (strncmp(haystack+i+offset, needle, nlen) == 0) return i+offset; + if (memcmp(haystack+i+offset, needle, nlen) == 0) return i+offset; mask &= (mask - 1); } } - for (; i < end_idx; i++) { if (strncmp(haystack + i, needle, nlen) == 0) return i; } +lt_32: + for (; i < end_idx; i++) { if (memcmp(haystack + i, needle, nlen) == 0) return i; } return -1; } @@ -254,9 +257,10 @@ i32 sv_find_char(strng_view_t const *sv, char n) { if (hlen == 0) return -1; if (hlen == 1 && *haystack == n) return 0; + u64 i = 0; + if (hlen < 32) goto lt_32; __m256i needle_vec = _mm256_set1_epi8(n); - u64 i = 0; for (; i + 32 <= hlen; i += 32) { __m256i hay_vec = _mm256_loadu_si256((const __m256i*)(haystack+i)); @@ -269,6 +273,7 @@ i32 sv_find_char(strng_view_t const *sv, char n) { } } +lt_32: for (; i < hlen; i++) { if (haystack[i] == n) return i; } return -1; @@ -320,7 +325,7 @@ b32 sv_eq_case_insensitive(strng_view_t const *sv1, strng_view_t const *sv2) { v1 = _mm256_or_si256(v1, U1); v2 = _mm256_or_si256(v2, U2); - __m256i cmp = _mm256_cmpeq_epi64(v1, v2); + __m256i cmp = _mm256_cmpeq_epi8(v1, v2); u32 mask = _mm256_movemask_epi8(cmp); if (mask != 0xFFFFFFFF) return false; diff --git a/src/threadpool.c b/src/threadpool.c index 152ca66..162fcf2 100644 --- a/src/threadpool.c +++ b/src/threadpool.c @@ -1,3 +1,4 @@ +#include <stdint.h> #if defined(__linux__) #ifndef _DEFAULT_SOURCE #define _DEFAULT_SOURCE @@ -196,7 +197,7 @@ i32 tp_push_job(thread_pool_t *tp, tp_job_proc job, void *args) { }; #ifndef NLOG_TRACE - log_trace("Pushing job %p with arg %p onto threadpool.", job, args); + log_trace("Pushing job 0x%lx with arg %p onto threadpool.", (uintptr_t)job, args); #endif /* ifndef NLOG_TRACE */ return ts_deque_enqueue(tp->jobs, &j); |