From ba18c5a669c4497f9edf976ba22ed328316ee7ad Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 17 Nov 2023 13:05:43 +0530 Subject: [PATCH] Move ByteLoader back to simd-string.c in preparation for getting rid of it --- kitty/simd-string.c | 11 +++++++++++ kitty/simd-string.h | 10 ---------- kitty/vt-parser.c | 14 ++++++-------- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/kitty/simd-string.c b/kitty/simd-string.c index 0198ff004..1707de0ef 100644 --- a/kitty/simd-string.c +++ b/kitty/simd-string.c @@ -20,6 +20,17 @@ _Pragma("clang diagnostic pop") static bool has_sse4_2 = false, has_avx2 = false; // ByteLoader {{{ +#define BYTE_LOADER_T unsigned long long +typedef struct ByteLoader { + BYTE_LOADER_T m; + unsigned sz_of_next_load, digits_left, num_left; + const uint8_t *next_load_at; +} ByteLoader; +uint8_t byte_loader_peek(const ByteLoader *self); +void byte_loader_init(ByteLoader *self, const uint8_t *buf, unsigned int sz); +uint8_t byte_loader_next(ByteLoader *self); + + uint8_t byte_loader_peek(const ByteLoader *self) { #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ diff --git a/kitty/simd-string.h b/kitty/simd-string.h index 732e9d01b..274e9d01c 100644 --- a/kitty/simd-string.h +++ b/kitty/simd-string.h @@ -12,16 +12,6 @@ #include #include "data-types.h" -#define BYTE_LOADER_T unsigned long long -typedef struct ByteLoader { - BYTE_LOADER_T m; - unsigned sz_of_next_load, digits_left, num_left; - const uint8_t *next_load_at; -} ByteLoader; -uint8_t byte_loader_peek(const ByteLoader *self); -void byte_loader_init(ByteLoader *self, const uint8_t *buf, unsigned int sz); -uint8_t byte_loader_next(ByteLoader *self); - typedef void (*control_byte_callback)(void *data, uint8_t ch); typedef void (*output_chars_callback)(void *data, const uint32_t *chars, unsigned count); diff --git a/kitty/vt-parser.c b/kitty/vt-parser.c index f9cae0732..518d1730b 100644 --- a/kitty/vt-parser.c +++ b/kitty/vt-parser.c @@ -207,7 +207,6 @@ typedef struct PS { struct { size_t offset, sz, pending; } write; alignas(BUF_EXTRA) uint8_t buf[BUF_SZ + BUF_EXTRA]; } PS; -static_assert(offsetof(PS, buf) > sizeof(BYTE_LOADER_T), "There must be enough space before the buf[] array for aligned loads"); static void reset_csi(ParsedCSI *csi) { @@ -987,17 +986,16 @@ bool parse_sgr(Screen *screen, const uint8_t *buf, unsigned int num, const char *report_name UNUSED, bool is_deccara) { ParsedCSI csi = {.mult=1}; size_t pos = 0; - RAII_ALLOC(uint8_t, _buf, malloc(num + 2 + 2*sizeof(BYTE_LOADER_T))); + RAII_ALLOC(uint8_t, _buf, malloc(num + 3)); if (!_buf) return false; - uint8_t *safe_buf = _buf + sizeof(BYTE_LOADER_T); - memcpy(safe_buf, buf, num); + memcpy(_buf, buf, num); if (is_deccara) { - safe_buf[num++] = '$'; safe_buf[num++] = 'r'; + _buf[num++] = '$'; _buf[num++] = 'r'; } else { - safe_buf[num++] = 'm'; + _buf[num++] = 'm'; } - safe_buf[num] = 0; - if (!csi_parse_loop((PS*)screen->vt_parser->state, &csi, safe_buf, &pos, num, 0)) return false; + _buf[num] = 0; + if (!csi_parse_loop((PS*)screen->vt_parser->state, &csi, _buf, &pos, num, 0)) return false; return _parse_sgr((PS*)screen->vt_parser->state, &csi); } #endif