summaryrefslogtreecommitdiff
path: root/src/hist.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/hist.c')
-rw-r--r--src/hist.c352
1 files changed, 176 insertions, 176 deletions
diff --git a/src/hist.c b/src/hist.c
index fff0bfe..daf0f9c 100644
--- a/src/hist.c
+++ b/src/hist.c
@@ -42,7 +42,7 @@
#define ROWS_UNKNOWN 255
/* Bytes one cell can need, except a cluster. */
#define CELL_BYTES 5
-#define CLUSTER_BYTES (2 + TERM_GRAPHEME_MAX_LEN * 4)
+#define CLUSTER_BYTES (2 + WSAP_VTCORE_GRAPHEME_MAX_LEN * 4)
/* ---- Parts and pages ---- */
@@ -62,24 +62,24 @@ static inline struct hline *open_part(const struct hist *h)
}
/* Grow the ring so n more parts fit. The caller checks the fast path first. */
-static TERM_NOINLINE bool ring_grow(struct hist *h, uint64_t n)
+static WSAP_VTCORE_NOINLINE bool ring_grow(struct hist *h, uint64_t n)
{
uint64_t cap = h->ring ? (uint64_t)h->ring_mask + 1 : 65536;
if (cap < 65536)
cap = 65536;
- cap = term_grow_cap64(cap, h->head - h->tail + n);
- struct hline *ring = term_aligned_alloc(64, (size_t)cap * sizeof(*ring));
+ cap = wsap_vtcore_grow_cap64(cap, h->head - h->tail + n);
+ struct hline *ring = wsap_vtcore_aligned_alloc(64, (size_t)cap * sizeof(*ring));
if (!ring)
return false;
struct hist_block *blocks = calloc((size_t)cap / 16, sizeof(*blocks));
if (!blocks) {
- term_aligned_free(ring);
+ wsap_vtcore_aligned_free(ring);
return false;
}
uint32_t *exact = h->exact_rows ? calloc((size_t)cap, sizeof(*exact)) : NULL;
if (h->exact_rows && !exact) {
free(blocks);
- term_aligned_free(ring);
+ wsap_vtcore_aligned_free(ring);
return false;
}
for (uint64_t s = h->tail; s < h->head; s++) {
@@ -89,7 +89,7 @@ static TERM_NOINLINE bool ring_grow(struct hist *h, uint64_t n)
}
free(h->exact_rows);
h->exact_rows = exact;
- term_aligned_free(h->ring);
+ wsap_vtcore_aligned_free(h->ring);
free(h->blocks);
h->blocks = blocks;
h->ring = ring;
@@ -101,7 +101,7 @@ static TERM_NOINLINE bool ring_grow(struct hist *h, uint64_t n)
* keep it inline and leave only the rehash to a call. */
static inline bool ring_fit(struct hist *h, uint64_t n)
{
- if (TERM_EXPECT(h->ring && h->head - h->tail + n <= (uint64_t)h->ring_mask + 1, 1))
+ if (WSAP_VTCORE_EXPECT(h->ring && h->head - h->tail + n <= (uint64_t)h->ring_mask + 1, 1))
return true;
return ring_grow(h, n);
}
@@ -182,7 +182,7 @@ static inline bool line_valid(const struct hist *h, uint64_t id)
return id >= h->base_id && id < h->base_id + h->lines;
}
-static TERM_ALWAYS_INLINE inline void page_drop_ref(struct hist *h, uint32_t pg)
+static WSAP_VTCORE_ALWAYS_INLINE inline void page_drop_ref(struct hist *h, uint32_t pg)
{
if (--h->page_parts[pg] == 0) {
if (pg == h->cur_page)
@@ -196,7 +196,7 @@ static TERM_ALWAYS_INLINE inline void page_drop_ref(struct hist *h, uint32_t pg)
static void rows_uncount(struct hist *h, uint64_t id)
{
if (id < h->rows_id)
- h->counted_rows -= term_hist_line_estimate(h, id, h->wrap_cols);
+ h->counted_rows -= wsap_vtcore_hist_line_estimate(h, id, h->wrap_cols);
}
static void line_gone(struct hist *h)
@@ -244,7 +244,7 @@ static bool evict_part(struct hist *h)
return true;
}
-static TERM_NOINLINE void evict_line_parts(struct hist *h)
+static WSAP_VTCORE_NOINLINE void evict_line_parts(struct hist *h)
{
uint64_t end = line_end(h, h->tail);
if (part(h, end - 1)->flags & HLINE_OPEN)
@@ -272,8 +272,8 @@ static inline void page_drop_n(struct hist *h, uint32_t pg, uint32_t n)
}
}
-#if defined(TERM_KERNEL_AVX512)
-TERM_TARGET_AVX512
+#if defined(WSAP_VTCORE_KERNEL_AVX512)
+WSAP_VTCORE_TARGET_AVX512
static inline bool same_page_narrow_rows_avx512(const struct hline *p, uint32_t page)
{
const __m512i pg = _mm512_set1_epi32((int)(page << 16));
@@ -289,8 +289,8 @@ static inline bool same_page_narrow_rows_avx512(const struct hline *p, uint32_t
}
#endif
-#if defined(TERM_KERNEL_AVX2)
-TERM_TARGET_AVX2
+#if defined(WSAP_VTCORE_KERNEL_AVX2)
+WSAP_VTCORE_TARGET_AVX2
static inline bool same_page_narrow_rows_avx2(const struct hline *p, uint32_t page)
{
const __m256i pg = _mm256_set1_epi32((int)(page << 16));
@@ -309,12 +309,12 @@ static inline bool same_page_narrow_rows_avx2(const struct hline *p, uint32_t pa
/* Check 16 narrow rows. Each descriptor has four words. */
static inline bool same_page_narrow_rows(const struct hline *p, uint32_t page)
{
-#if defined(TERM_KERNEL_AVX512)
- if (term_use_avx512())
+#if defined(WSAP_VTCORE_KERNEL_AVX512)
+ if (wsap_vtcore_use_avx512())
return same_page_narrow_rows_avx512(p, page);
#endif
-#if defined(TERM_KERNEL_AVX2)
- if (term_use_avx2())
+#if defined(WSAP_VTCORE_KERNEL_AVX2)
+ if (wsap_vtcore_use_avx2())
return same_page_narrow_rows_avx2(p, page);
#endif
#if defined(__aarch64__)
@@ -336,8 +336,8 @@ static inline bool same_page_narrow_rows(const struct hline *p, uint32_t page)
#endif
}
-#if defined(TERM_KERNEL_AVX512)
-TERM_TARGET_AVX512
+#if defined(WSAP_VTCORE_KERNEL_AVX512)
+WSAP_VTCORE_TARGET_AVX512
static inline bool same_page_rows_64(const struct hline *p, uint32_t page,
uint32_t *text_count, uint32_t *row_count)
{
@@ -352,7 +352,7 @@ static inline bool same_page_rows_64(const struct hline *p, uint32_t page,
for (int i = 0; i < 64; i += 4) {
__m512i v = _mm512_loadu_si512((const void *)(p + i));
__mmask16 empty = _mm512_cmpeq_epi32_mask(v, no_text) & 0x1111;
- blanks += term_popcount32(empty);
+ blanks += wsap_vtcore_popcount32(empty);
tag_fail |= (_mm512_test_epi32_mask(v, open) |
_mm512_cmpeq_epi32_mask(_mm512_and_si512(v, unknown), unknown)) & 0x8888;
pg_fail |= (uint16_t)(~(_mm512_cmpeq_epi32_mask(_mm512_and_si512(v, mask), pg) | empty) & 0x1111);
@@ -400,8 +400,8 @@ static uint64_t evict_simple_run(struct hist *h, uint64_t k)
continue;
}
}
-#if defined(TERM_KERNEL_AVX512)
- if (term_use_avx512() && (tail & 63) == 0 && n + 64 <= k && tail + 64 <= head &&
+#if defined(WSAP_VTCORE_KERNEL_AVX512)
+ if (wsap_vtcore_use_avx512() && (tail & 63) == 0 && n + 64 <= k && tail + 64 <= head &&
((tail & rmask) + 64 <= rmask + 1)) {
const struct hline *f = &ring[tail & rmask];
@@ -463,7 +463,7 @@ static uint64_t evict_simple_run(struct hist *h, uint64_t k)
uint32_t or_all = t0 | t1 | t2 | t3 | t4 | t5 | t6 | t7 |
t8 | t9 | t10 | t11 | t12 | t13 | t14 | t15;
- if (TERM_EXPECT((or_all & 0x0030ffff) == 0 &&
+ if (WSAP_VTCORE_EXPECT((or_all & 0x0030ffff) == 0 &&
(t0 >> 24) != 255 && (t1 >> 24) != 255 && (t2 >> 24) != 255 && (t3 >> 24) != 255 &&
(t4 >> 24) != 255 && (t5 >> 24) != 255 && (t6 >> 24) != 255 && (t7 >> 24) != 255 &&
(t8 >> 24) != 255 && (t9 >> 24) != 255 && (t10 >> 24) != 255 && (t11 >> 24) != 255 &&
@@ -568,16 +568,16 @@ static inline void evict_for(struct hist *h, uint64_t n)
}
/* Drop the oldest line with all its parts. It is never the open line. */
-static inline TERM_ALWAYS_INLINE void evict_line(struct hist *h)
+static inline WSAP_VTCORE_ALWAYS_INLINE void evict_line(struct hist *h)
{
if (h->tail == h->head)
return;
const struct hline *f = part(h, h->tail);
- if (TERM_EXPECT(!(f->flags & HLINE_OPEN) &&
+ if (WSAP_VTCORE_EXPECT(!(f->flags & HLINE_OPEN) &&
(h->tail + 1 == h->head || !(part(h, h->tail + 1)->flags & HLINE_CONT)), 1)) {
if (h->base_id < h->rows_id)
h->counted_rows -= f->wrap_rows != ROWS_UNKNOWN
- ? f->wrap_rows : term_hist_line_estimate(h, h->base_id, h->wrap_cols);
+ ? f->wrap_rows : wsap_vtcore_hist_line_estimate(h, h->base_id, h->wrap_cols);
if (f->off != NO_TEXT)
page_drop_ref(h, f->off >> 16);
h->tail++;
@@ -587,7 +587,7 @@ static inline TERM_ALWAYS_INLINE void evict_line(struct hist *h)
evict_line_parts(h);
}
-static TERM_NOINLINE int page_next(struct hist *h)
+static WSAP_VTCORE_NOINLINE int page_next(struct hist *h)
{
for (;;) {
if (h->nfree) {
@@ -597,7 +597,7 @@ static TERM_NOINLINE int page_next(struct hist *h)
return (int)pg;
}
if (h->npages < h->max_pages) {
- uint8_t *page = term_aligned_alloc(64, HIST_PAGE_SIZE);
+ uint8_t *page = wsap_vtcore_aligned_alloc(64, HIST_PAGE_SIZE);
if (!page)
return -1;
uint32_t pg = h->npages++;
@@ -620,7 +620,7 @@ static inline int page_for(struct hist *h, size_t need)
if (need > HIST_PAGE_USABLE)
return -1;
uint32_t pg = h->cur_page;
- if (TERM_EXPECT(pg < h->npages && h->page_used[pg] + need <= HIST_PAGE_USABLE, 1))
+ if (WSAP_VTCORE_EXPECT(pg < h->npages && h->page_used[pg] + need <= HIST_PAGE_USABLE, 1))
return (int)pg;
return page_next(h);
}
@@ -629,12 +629,12 @@ static inline int page_for(struct hist *h, size_t need)
static inline int put_varint(uint8_t *p, uint32_t v)
{
- if (TERM_EXPECT(v < 0x80, 1)) {
+ if (WSAP_VTCORE_EXPECT(v < 0x80, 1)) {
p[0] = (uint8_t)v;
return 1;
}
p[0] = (uint8_t)(v | 0x80);
- if (TERM_EXPECT(v < 0x4000, 1)) {
+ if (WSAP_VTCORE_EXPECT(v < 0x4000, 1)) {
p[1] = (uint8_t)(v >> 7);
return 2;
}
@@ -656,12 +656,12 @@ static inline int put_varint(uint8_t *p, uint32_t v)
static inline int get_varint(const uint8_t *p, uint32_t *v)
{
uint8_t b0 = p[0];
- if (TERM_EXPECT((b0 & 0x80) == 0, 1)) {
+ if (WSAP_VTCORE_EXPECT((b0 & 0x80) == 0, 1)) {
*v = b0;
return 1;
}
uint8_t b1 = p[1];
- if (TERM_EXPECT((b1 & 0x80) == 0, 1)) {
+ if (WSAP_VTCORE_EXPECT((b1 & 0x80) == 0, 1)) {
*v = (uint32_t)(b0 & 0x7f) | ((uint32_t)b1 << 7);
return 2;
}
@@ -691,7 +691,7 @@ static inline uint8_t *emit_run(uint8_t *p, const struct pen_attr *base, const s
uint32_t count)
{
/* Most runs change only colors and cover fewer than 128 cells. */
- if (TERM_EXPECT(count < 0x80 && pen_sl(pen) == pen_sl(base), 1)) {
+ if (WSAP_VTCORE_EXPECT(count < 0x80 && pen_sl(pen) == pen_sl(base), 1)) {
uint32_t dfg = pen->fg != base->fg, dbg = pen->bg != base->bg;
p[0] = (uint8_t)(dfg | (dbg << 1));
p[1] = (uint8_t)count;
@@ -727,9 +727,9 @@ static inline const uint8_t *read_run(const uint8_t *p, struct pen_attr *pen, ui
static bool runs_reserve(struct hist_runs *r, size_t extra)
{
- if (TERM_EXPECT(r->len + extra <= r->cap, 1))
+ if (WSAP_VTCORE_EXPECT(r->len + extra <= r->cap, 1))
return true;
- size_t cap = term_grow_cap(r->cap ? r->cap : 256, (size_t)r->len + extra);
+ size_t cap = wsap_vtcore_grow_cap(r->cap ? r->cap : 256, (size_t)r->len + extra);
uint8_t *data = realloc(r->data, cap);
if (!data)
return false;
@@ -746,7 +746,7 @@ static inline void runs_reset(struct hist_runs *r)
r->count = 0;
}
-void term_hist_runs_emit_slow(struct hist_runs *r)
+void wsap_vtcore_hist_runs_emit_slow(struct hist_runs *r)
{
r->len = (uint32_t)(emit_run(r->data + r->len, &r->base, &r->pen, r->count) - r->data);
}
@@ -812,11 +812,11 @@ struct enc {
uint16_t wide;
};
-#if defined(TERM_KERNEL_AVX512)
+#if defined(WSAP_VTCORE_KERNEL_AVX512)
/* The prefix of cells where (lane & keep) - target <= span holds in every
* lane. Their code points go to dst as bytes. Eight cells per step; the
* last step uses masked loads. */
-TERM_TARGET_AVX512
+WSAP_VTCORE_TARGET_AVX512
static inline int narrow_prefix_avx512(const struct cell *cells, int len, uint8_t *dst,
__m512i keep, __m512i target, __m512i span)
{
@@ -834,7 +834,7 @@ static inline int narrow_prefix_avx512(const struct cell *cells, int len, uint8_
if (ok0 != m0 || ok1 != m1) {
/* Keep the cells before the first failing one. */
uint32_t bad = (uint32_t)(~ok0 & m0) | ((uint32_t)(~ok1 & m1) << 16);
- int good = term_ctz32(bad) / 4;
+ int good = wsap_vtcore_ctz32(bad) / 4;
_mm_mask_storeu_epi8(dst + k, (__mmask16)((1u << good) - 1), _mm512_cvtepi32_epi8(cp));
return k + good;
}
@@ -846,7 +846,7 @@ static inline int narrow_prefix_avx512(const struct cell *cells, int len, uint8_
return len;
}
-TERM_TARGET_AVX512
+WSAP_VTCORE_TARGET_AVX512
static inline int narrow_any_pen_prefix_avx512(const struct cell *cells, int len, uint8_t *dst)
{
const __m512i keep = _mm512_setr_epi32(-1, 0, 0, SHAPE_FLAGS, -1, 0, 0, SHAPE_FLAGS,
@@ -856,7 +856,7 @@ static inline int narrow_any_pen_prefix_avx512(const struct cell *cells, int len
return narrow_prefix_avx512(cells, len, dst, keep, target, span);
}
-TERM_TARGET_AVX512
+WSAP_VTCORE_TARGET_AVX512
static inline int narrow_uniform_prefix_avx512(const struct cell *cells, int len, uint8_t *dst)
{
uint32_t sl = (uint32_t)(cells[0].flags & STYLE_FLAGS) | ((uint32_t)cells[0].pad << 16);
@@ -875,8 +875,8 @@ static inline int narrow_uniform_prefix_avx512(const struct cell *cells, int len
* to dst. */
static inline int narrow_any_pen_prefix(const struct cell *cells, int len, uint8_t *dst)
{
-#if defined(TERM_KERNEL_AVX512)
- if (term_use_avx512())
+#if defined(WSAP_VTCORE_KERNEL_AVX512)
+ if (wsap_vtcore_use_avx512())
return narrow_any_pen_prefix_avx512(cells, len, dst);
#endif
int k = 0;
@@ -890,7 +890,7 @@ static inline int narrow_any_pen_prefix(const struct cell *cells, int len, uint8
/* Add the pens of n cells to r, one run per change. Cells carry no
* underline color, so no pen here has one. */
-static TERM_NOINLINE uint32_t runs_scan(struct hist_runs *r, const struct cell *cells, int n)
+static WSAP_VTCORE_NOINLINE uint32_t runs_scan(struct hist_runs *r, const struct cell *cells, int n)
{
uint32_t links = 0;
uint32_t pfg = r->pen.fg, pbg = r->pen.bg;
@@ -903,13 +903,13 @@ static TERM_NOINLINE uint32_t runs_scan(struct hist_runs *r, const struct cell *
const struct cell *c = &cells[i];
uint32_t sl = (uint32_t)(c->flags & STYLE_FLAGS) | ((uint32_t)c->pad << 16);
links |= c->pad;
- if (TERM_EXPECT(((c->fg ^ pfg) | (c->bg ^ pbg) | (sl ^ psl)) != 0, 0)) {
+ if (WSAP_VTCORE_EXPECT(((c->fg ^ pfg) | (c->bg ^ pbg) | (sl ^ psl)) != 0, 0)) {
if (count) {
uint32_t header = (pfg != bfg ? RUN_FG : 0) | (pbg != bbg ? RUN_BG : 0) |
((uint16_t)psl != (uint16_t)bsl ? RUN_ATTR : 0) |
((psl >> 16) != (bsl >> 16) ? RUN_LINK : 0);
rp[0] = (uint8_t)header;
- if (TERM_EXPECT(count < 0x80, 1)) {
+ if (WSAP_VTCORE_EXPECT(count < 0x80, 1)) {
rp[1] = (uint8_t)count;
rp += 2;
} else {
@@ -919,7 +919,7 @@ static TERM_NOINLINE uint32_t runs_scan(struct hist_runs *r, const struct cell *
rp += (header & RUN_FG) ? 4 : 0;
put_u32(rp, pbg);
rp += (header & RUN_BG) ? 4 : 0;
- if (TERM_EXPECT(header & (RUN_ATTR | RUN_LINK), 0)) {
+ if (WSAP_VTCORE_EXPECT(header & (RUN_ATTR | RUN_LINK), 0)) {
if (header & RUN_ATTR) { put_u16(rp, (uint16_t)psl); rp += 2; }
if (header & RUN_LINK) { put_u16(rp, (uint16_t)(psl >> 16)); rp += 2; }
}
@@ -945,8 +945,8 @@ static TERM_NOINLINE uint32_t runs_scan(struct hist_runs *r, const struct cell *
* Their bytes go to dst. */
static inline int narrow_uniform_prefix(const struct cell *cells, int len, uint8_t *dst)
{
-#if defined(TERM_KERNEL_AVX512)
- if (term_use_avx512())
+#if defined(WSAP_VTCORE_KERNEL_AVX512)
+ if (wsap_vtcore_use_avx512())
return narrow_uniform_prefix_avx512(cells, len, dst);
#endif
uint32_t sl = (uint32_t)(cells[0].flags & STYLE_FLAGS) | ((uint32_t)cells[0].pad << 16);
@@ -961,11 +961,11 @@ static inline int narrow_uniform_prefix(const struct cell *cells, int len, uint8
return k;
}
-#if defined(TERM_KERNEL_AVX512)
+#if defined(WSAP_VTCORE_KERNEL_AVX512)
/* Encode a prefix of cells with the pen of cells[0] and no clusters, eight
* cells at a time. Return the cells used; runcells counts the cells that
* are not trail cells. */
-TERM_TARGET_AVX512
+WSAP_VTCORE_TARGET_AVX512
static int uniform_utf8_prefix(const struct cell *cells, int len, uint8_t *dst, struct enc *o,
uint32_t *runcells)
{
@@ -1019,11 +1019,11 @@ static int uniform_utf8_prefix(const struct cell *cells, int len, uint8_t *dst,
bm = _mm256_maskz_mov_epi32((__mmask8)~m_trail, bm);
__mmask32 keep_bytes = _mm256_movepi8_mask(bm);
_mm256_storeu_si256((__m256i *)(void *)(dst + bytes), _mm256_maskz_compress_epi8(keep_bytes, w));
- bytes += (uint32_t)term_popcount32(keep_bytes);
- uint32_t trails = (uint32_t)term_popcount32(m_trail);
- ncells += 8u - trails + (uint32_t)term_popcount32(m_wide);
+ bytes += (uint32_t)wsap_vtcore_popcount32(keep_bytes);
+ uint32_t trails = (uint32_t)wsap_vtcore_popcount32(m_trail);
+ ncells += 8u - trails + (uint32_t)wsap_vtcore_popcount32(m_wide);
*runcells += 8u - trails;
- nwide += (uint32_t)term_popcount32(m_wide);
+ nwide += (uint32_t)wsap_vtcore_popcount32(m_wide);
wide |= m_wide;
ascii &= (uint32_t)(uint8_t)~(ge80 & ~m_trail);
}
@@ -1036,11 +1036,11 @@ static int uniform_utf8_prefix(const struct cell *cells, int len, uint8_t *dst,
}
#endif
-static TERM_NOINLINE size_t encode_cluster(uint8_t *dst, const struct gstore *g,
+static WSAP_VTCORE_NOINLINE size_t encode_cluster(uint8_t *dst, const struct gstore *g,
uint32_t handle, uint16_t f)
{
- uint32_t cps[TERM_GRAPHEME_MAX_LEN];
- int n = term_gstore_expand(g, handle, cps, TERM_GRAPHEME_MAX_LEN);
+ uint32_t cps[WSAP_VTCORE_GRAPHEME_MAX_LEN];
+ int n = wsap_vtcore_gstore_expand(g, handle, cps, WSAP_VTCORE_GRAPHEME_MAX_LEN);
size_t b = 0;
dst[b++] = PREFIX_CLUSTER;
dst[b++] = (uint8_t)((n & 0x1f) | ((f & CELL_WIDE) ? 0x80 : 0) |
@@ -1053,7 +1053,7 @@ static TERM_NOINLINE size_t encode_cluster(uint8_t *dst, const struct gstore *g,
static size_t encode_shaped(uint8_t *dst, uint32_t cp, uint16_t f, const struct gstore *g,
uint8_t *flags)
{
- if (term_grapheme_is_handle(cp)) {
+ if (wsap_vtcore_grapheme_is_handle(cp)) {
*flags |= HLINE_HAS_CLUSTER | ((f & CELL_WIDE) ? HLINE_HAS_WIDE : 0);
return encode_cluster(dst, g, cp, f);
}
@@ -1118,8 +1118,8 @@ static int encode_cells(struct hist_runs *r, const struct cell *cells, int n, ui
*o = (struct enc){ .bytes = (uint32_t)i, .cells = (uint32_t)i,
.flags = (uint8_t)(HLINE_NARROW | (c0->pad ? HLINE_HAS_LINK : 0)) };
}
-#if defined(TERM_KERNEL_AVX512)
- if (term_use_avx512() && n - i >= 8 && ((cells[i].flags & SHAPE_FLAGS) || cells[i].c >= 0x80)) {
+#if defined(WSAP_VTCORE_KERNEL_AVX512)
+ if (wsap_vtcore_use_avx512() && n - i >= 8 && ((cells[i].flags & SHAPE_FLAGS) || cells[i].c >= 0x80)) {
/* Text with one pen, eight cells per step. */
struct enc u;
uint32_t runcells = 0;
@@ -1155,18 +1155,18 @@ static int encode_cells(struct hist_runs *r, const struct cell *cells, int n, ui
continue;
uint32_t cp = c->c;
bool simple = !(f & (CELL_WIDE | CELL_EMOJI | CELL_TEXT)) && cp - 0x20u < 0x60u;
- if (!simple && term_grapheme_is_handle(cp) &&
+ if (!simple && wsap_vtcore_grapheme_is_handle(cp) &&
bytes + CLUSTER_BYTES + (size_t)(n - i) * CELL_BYTES > cap)
break;
uint32_t sl = (uint32_t)(f & STYLE_FLAGS) | ((uint32_t)c->pad << 16);
links |= c->pad;
- if (TERM_EXPECT(((c->fg ^ pfg) | (c->bg ^ pbg) | (sl ^ psl)) != 0, 0)) {
+ if (WSAP_VTCORE_EXPECT(((c->fg ^ pfg) | (c->bg ^ pbg) | (sl ^ psl)) != 0, 0)) {
if (count) {
uint32_t header = (pfg != bfg ? RUN_FG : 0) | (pbg != bbg ? RUN_BG : 0) |
((uint16_t)psl != (uint16_t)bsl ? RUN_ATTR : 0) |
((psl >> 16) != (bsl >> 16) ? RUN_LINK : 0);
*rp++ = (uint8_t)header;
- if (TERM_EXPECT(count < 0x80, 1))
+ if (WSAP_VTCORE_EXPECT(count < 0x80, 1))
*rp++ = (uint8_t)count;
else
rp += put_varint(rp, count);
@@ -1174,7 +1174,7 @@ static int encode_cells(struct hist_runs *r, const struct cell *cells, int n, ui
rp += (header & RUN_FG) ? 4 : 0;
put_u32(rp, pbg);
rp += (header & RUN_BG) ? 4 : 0;
- if (TERM_EXPECT(header & (RUN_ATTR | RUN_LINK), 0)) {
+ if (WSAP_VTCORE_EXPECT(header & (RUN_ATTR | RUN_LINK), 0)) {
if (header & RUN_ATTR) { put_u16(rp, (uint16_t)psl); rp += 2; }
if (header & RUN_LINK) { put_u16(rp, (uint16_t)(psl >> 16)); rp += 2; }
}
@@ -1189,7 +1189,7 @@ static int encode_cells(struct hist_runs *r, const struct cell *cells, int n, ui
}
count++;
nwide += (f & CELL_WIDE) != 0;
- if (TERM_EXPECT(simple, 1)) {
+ if (WSAP_VTCORE_EXPECT(simple, 1)) {
dst[bytes++] = (uint8_t)cp;
ncells++;
continue;
@@ -1408,7 +1408,7 @@ static void close_part(struct hist *h, struct hline *p)
p->flags &= (uint8_t)~HLINE_OPEN;
}
-void term_hist_close_open_line(struct hist *h)
+void wsap_vtcore_hist_close_open_line(struct hist *h)
{
struct hline *p = open_part(h);
if (!p)
@@ -1424,7 +1424,7 @@ void term_hist_close_open_line(struct hist *h)
uint64_t first = line_first(h, id);
uint64_t rows = first == h->head - 1
? cheap_rows(p->cells, p->wide, cols)
- : cheap_rows(term_hist_line_cells(h, id), term_hist_line_wide(h, id), cols);
+ : cheap_rows(wsap_vtcore_hist_line_cells(h, id), wsap_vtcore_hist_line_wide(h, id), cols);
if (!rows && h->walk_on) {
walk_advance(h);
rows = h->walk_rows;
@@ -1440,7 +1440,7 @@ static struct hline *open_room(struct hist *h, struct hline *p, size_t text_need
{
uint32_t start = p->off & 0xffff;
size_t runs = h->runs.len + runs_need + RUN_MAX;
- if (TERM_EXPECT(start + p->text_len + text_need + runs <= HIST_PAGE_USABLE &&
+ if (WSAP_VTCORE_EXPECT(start + p->text_len + text_need + runs <= HIST_PAGE_USABLE &&
p->cells + add_cells <= HIST_MAX_PART_CELLS &&
runs <= UINT16_MAX, 1))
return p;
@@ -1547,7 +1547,7 @@ static inline void part_add(struct hist *h, struct hline *p, const struct enc *e
h->page_used[p->off >> 16] = (p->off & 0xffff) + p->text_len;
}
-void term_hist_push_row(struct hist *h, const struct cell *cells, int len, bool wrapped,
+void wsap_vtcore_hist_push_row(struct hist *h, const struct cell *cells, int len, bool wrapped,
const struct gstore *g)
{
if (!h->line_limit)
@@ -1555,7 +1555,7 @@ void term_hist_push_row(struct hist *h, const struct cell *cells, int len, bool
struct hline *p = open_part(h);
if (!p) {
if (len <= 0 && !wrapped) {
- term_hist_push_blank(h, 1);
+ wsap_vtcore_hist_push_blank(h, 1);
return;
}
if (!wrapped && push_uniform_line(h, cells, len))
@@ -1582,12 +1582,12 @@ void term_hist_push_row(struct hist *h, const struct cell *cells, int len, bool
return;
}
if (!wrapped)
- term_hist_close_open_line(h);
+ wsap_vtcore_hist_close_open_line(h);
else if (h->wrap_cols && (h->walk_on || (p->flags & (HLINE_HAS_WIDE | HLINE_HAS_CLUSTER))))
walk_advance(h);
}
-void term_hist_push_ascii(struct hist *h, const char *bytes, int n, const struct pen_attr *pen,
+void wsap_vtcore_hist_push_ascii(struct hist *h, const char *bytes, int n, const struct pen_attr *pen,
bool wrapped)
{
if (!h->line_limit)
@@ -1598,7 +1598,7 @@ void term_hist_push_ascii(struct hist *h, const char *bytes, int n, const struct
struct hline *p = open_part(h);
if (!p) {
if (n <= 0 && !wrapped) {
- term_hist_push_blank(h, 1);
+ wsap_vtcore_hist_push_blank(h, 1);
return;
}
/* A default-pen line: one copy and one descriptor. */
@@ -1643,7 +1643,7 @@ void term_hist_push_ascii(struct hist *h, const char *bytes, int n, const struct
n -= chunk;
}
if (!wrapped)
- term_hist_close_open_line(h);
+ wsap_vtcore_hist_close_open_line(h);
else if (h->wrap_cols && h->walk_on)
walk_advance(h);
}
@@ -1663,7 +1663,7 @@ static void text_row_readd(struct hist *h, const struct text_row *row)
hist_runs_add(&h->runs, &rr->pen, rr->count);
}
-void term_hist_push_text(struct hist *h, const struct text_row *row, bool wrapped)
+void wsap_vtcore_hist_push_text(struct hist *h, const struct text_row *row, bool wrapped)
{
if (!h->line_limit)
return;
@@ -1672,7 +1672,7 @@ void term_hist_push_text(struct hist *h, const struct text_row *row, bool wrappe
size_t runs_need = (size_t)rr->len * RUN_MAX / 2 + 2 * RUN_MAX;
if (!p) {
if (row->cells == 0 && !wrapped) {
- term_hist_push_blank(h, 1);
+ wsap_vtcore_hist_push_blank(h, 1);
return;
}
if (!wrapped && pen_attr_is_default(&row->start)) {
@@ -1738,7 +1738,7 @@ void term_hist_push_text(struct hist *h, const struct text_row *row, bool wrappe
}
part_add(h, p, &(struct enc){ row->text_len, row->cells, row->flags, row->wide });
if (!wrapped)
- term_hist_close_open_line(h);
+ wsap_vtcore_hist_close_open_line(h);
else if (h->wrap_cols && (h->walk_on || (p->flags & (HLINE_HAS_WIDE | HLINE_HAS_CLUSTER))))
walk_advance(h);
}
@@ -1754,8 +1754,8 @@ struct hist_stream_state {
/* Write the narrow descriptors of ends[i..stop) in blocks, while a block
* fits before the ring wraps. Return the first line left for the caller. */
-#if defined(TERM_KERNEL_AVX512)
-TERM_TARGET_AVX512
+#if defined(WSAP_VTCORE_KERNEL_AVX512)
+WSAP_VTCORE_TARGET_AVX512
static int lf_rows_avx512(struct hist *restrict h, const uint16_t *restrict ends, int i, int stop,
uint32_t cols, struct hist_stream_state *state)
{
@@ -1771,7 +1771,7 @@ static int lf_rows_avx512(struct hist *restrict h, const uint16_t *restrict ends
__m512i end = _mm512_cvtepu16_epi32(_mm256_loadu_si256((const __m256i *)(ends + i + 1)));
__m512i lens = _mm512_sub_epi32(_mm512_sub_epi32(end, start), _mm512_set1_epi32(1));
__mmask16 empty = _mm512_cmpeq_epi32_mask(lens, _mm512_setzero_si512());
- uint32_t refs = 16 - term_popcount32(empty);
+ uint32_t refs = 16 - wsap_vtcore_popcount32(empty);
text_count += refs;
__m512i offsets = _mm512_mask_mov_epi32(_mm512_add_epi32(start, _mm512_set1_epi32((int)base)),
empty, _mm512_set1_epi32(-1));
@@ -1821,8 +1821,8 @@ static int lf_rows_avx512(struct hist *restrict h, const uint16_t *restrict ends
}
#endif
-#if defined(TERM_KERNEL_AVX2)
-TERM_TARGET_AVX2
+#if defined(WSAP_VTCORE_KERNEL_AVX2)
+WSAP_VTCORE_TARGET_AVX2
static int lf_rows_avx2(struct hist *restrict h, const uint16_t *restrict ends, int i, int stop,
uint32_t cols, struct hist_stream_state *state)
{
@@ -1841,7 +1841,7 @@ static int lf_rows_avx2(struct hist *restrict h, const uint16_t *restrict ends,
__m128i end = _mm_cvtepu16_epi32(_mm_loadl_epi64((const __m128i *)(ends + i + 1)));
__m128i lens = _mm_sub_epi32(_mm_sub_epi32(end, start), _mm_set1_epi32(1));
__m128i empty = _mm_cmpeq_epi32(lens, _mm_setzero_si128());
- refs = 4 - term_popcount32((unsigned)_mm_movemask_ps(_mm_castsi128_ps(empty)));
+ refs = 4 - wsap_vtcore_popcount32((unsigned)_mm_movemask_ps(_mm_castsi128_ps(empty)));
__m128i offsets = _mm_or_si128(_mm_add_epi32(start, _mm_set1_epi32((int)base)), empty);
__m128i rs = _mm_set1_epi32(1);
if (cols == 1) rs = _mm_max_epu32(lens, rs);
@@ -1883,12 +1883,12 @@ static int lf_rows_avx2(struct hist *restrict h, const uint16_t *restrict ends,
static inline int lf_rows(struct hist *restrict h, const uint16_t *restrict ends, int i, int stop,
uint32_t cols, struct hist_stream_state *state)
{
-#if defined(TERM_KERNEL_AVX512)
- if (term_use_avx512())
+#if defined(WSAP_VTCORE_KERNEL_AVX512)
+ if (wsap_vtcore_use_avx512())
return lf_rows_avx512(h, ends, i, stop, cols, state);
#endif
-#if defined(TERM_KERNEL_AVX2)
- if (term_use_avx2())
+#if defined(WSAP_VTCORE_KERNEL_AVX2)
+ if (wsap_vtcore_use_avx2())
return lf_rows_avx2(h, ends, i, stop, cols, state);
#endif
#if defined(__aarch64__)
@@ -1949,14 +1949,14 @@ static inline int lf_rows(struct hist *restrict h, const uint16_t *restrict ends
return i;
}
-TERM_NOINLINE
-void term_hist_push_ascii_lf(struct hist *restrict h, const char *restrict bytes,
+WSAP_VTCORE_NOINLINE
+void wsap_vtcore_hist_push_ascii_lf(struct hist *restrict h, const char *restrict bytes,
const uint16_t *restrict ends, int count)
{
if (!h->line_limit) return;
int i = 0;
if (count && hist_is_open(h)) {
- term_hist_push_ascii(h, bytes + ends[0], ends[1] - ends[0] - 1, NULL, false);
+ wsap_vtcore_hist_push_ascii(h, bytes + ends[0], ends[1] - ends[0] - 1, NULL, false);
i++;
}
uint32_t cols = h->wrap_cols ? h->wrap_cols : 1;
@@ -2034,8 +2034,8 @@ static_assert(offsetof(struct hist_ascii_line, len) == 8, "len is in the second
/* Write the narrow one-row descriptors of lines[i..stream_end) in blocks,
* while a block fits before the ring wraps. first is the first byte of
* the page copy at base. Return the first line left for the caller. */
-#if defined(TERM_KERNEL_AVX512)
-TERM_TARGET_AVX512
+#if defined(WSAP_VTCORE_KERNEL_AVX512)
+WSAP_VTCORE_TARGET_AVX512
static int stream_lines_avx512(struct hist *restrict h, const struct hist_ascii_line *lines,
int i, int stream_end, struct hist_stream_state *state)
{
@@ -2065,7 +2065,7 @@ static int stream_lines_avx512(struct hist *restrict h, const struct hist_ascii_
_mm512_inserti64x4(_mm512_castsi256_si512(lo), hi, 1),
_mm512_set1_epi32(UINT16_MAX));
__mmask16 empty = _mm512_cmpeq_epi32_mask(lens, _mm512_setzero_si512());
- uint32_t refs = 16 - term_popcount32(empty);
+ uint32_t refs = 16 - wsap_vtcore_popcount32(empty);
text_count += refs;
offsets = _mm512_mask_mov_epi32(offsets, empty, _mm512_set1_epi32(-1));
__m512i tags = _mm512_set1_epi32((1u << 24) | (HLINE_NARROW << 16));
@@ -2099,8 +2099,8 @@ static int stream_lines_avx512(struct hist *restrict h, const struct hist_ascii_
}
#endif
-#if defined(TERM_KERNEL_AVX2)
-TERM_TARGET_AVX2
+#if defined(WSAP_VTCORE_KERNEL_AVX2)
+WSAP_VTCORE_TARGET_AVX2
static int stream_lines_avx2(struct hist *restrict h, const struct hist_ascii_line *lines,
int i, int stream_end, struct hist_stream_state *state)
{
@@ -2118,7 +2118,7 @@ static int stream_lines_avx2(struct hist *restrict h, const struct hist_ascii_li
_mm_i32gather_epi32((const int *)((const char *)(lines + i) + 8), index, 1),
_mm_set1_epi32(UINT16_MAX));
__m128i empty = _mm_cmpeq_epi32(lens, _mm_setzero_si128());
- refs = 4 - term_popcount32((unsigned)_mm_movemask_ps(_mm_castsi128_ps(empty)));
+ refs = 4 - wsap_vtcore_popcount32((unsigned)_mm_movemask_ps(_mm_castsi128_ps(empty)));
__m128i offsets = _mm_add_epi32(ptrs,
_mm_set1_epi32((int)(base - (uint32_t)(uintptr_t)first)));
offsets = _mm_or_si128(offsets, empty);
@@ -2142,12 +2142,12 @@ static int stream_lines_avx2(struct hist *restrict h, const struct hist_ascii_li
static inline int stream_lines(struct hist *restrict h, const struct hist_ascii_line *lines,
int i, int stream_end, struct hist_stream_state *state)
{
-#if defined(TERM_KERNEL_AVX512)
- if (term_use_avx512())
+#if defined(WSAP_VTCORE_KERNEL_AVX512)
+ if (wsap_vtcore_use_avx512())
return stream_lines_avx512(h, lines, i, stream_end, state);
#endif
-#if defined(TERM_KERNEL_AVX2)
- if (term_use_avx2())
+#if defined(WSAP_VTCORE_KERNEL_AVX2)
+ if (wsap_vtcore_use_avx2())
return stream_lines_avx2(h, lines, i, stream_end, state);
#endif
#if defined(__aarch64__)
@@ -2179,7 +2179,7 @@ static inline int stream_lines(struct hist *restrict h, const struct hist_ascii_
return i;
}
-void term_hist_push_ascii_lines(struct hist *h, const struct hist_ascii_line *lines, int count,
+void wsap_vtcore_hist_push_ascii_lines(struct hist *h, const struct hist_ascii_line *lines, int count,
const struct pen_attr *pen)
{
if (!h->line_limit)
@@ -2196,15 +2196,15 @@ void term_hist_push_ascii_lines(struct hist *h, const struct hist_ascii_line *li
lines[end].len <= INT32_MAX - bytes) {
bytes += lines[end++].len;
}
- term_hist_push_ascii(h, l->ptr, bytes, pen, true);
+ wsap_vtcore_hist_push_ascii(h, l->ptr, bytes, pen, true);
i = end;
continue;
}
if (!def || hist_is_open(h)) {
if (l->len == 0 && !l->wrapped)
- term_hist_push_blank(h, 1);
+ wsap_vtcore_hist_push_blank(h, 1);
else
- term_hist_push_ascii(h, l->ptr, l->len, pen, l->wrapped);
+ wsap_vtcore_hist_push_ascii(h, l->ptr, l->len, pen, l->wrapped);
i++;
continue;
}
@@ -2230,7 +2230,7 @@ void term_hist_push_ascii_lines(struct hist *h, const struct hist_ascii_line *li
size_t span = (size_t)(next->ptr - l->ptr) + next->len;
if (span > room)
break;
- if (TERM_EXPECT(next->len > (uint32_t)cols, 0))
+ if (WSAP_VTCORE_EXPECT(next->len > (uint32_t)cols, 0))
extra_rows += rows_narrow(next->len, cols) - 1;
stream_end++;
}
@@ -2259,7 +2259,7 @@ void term_hist_push_ascii_lines(struct hist *h, const struct hist_ascii_line *li
struct hline *dst = &h->ring[state.head++ & h->ring_mask];
if (len) {
uint32_t line_off = base + (uint32_t)(lines[i].ptr - l->ptr);
- if (TERM_EXPECT(len <= cols, 1)) {
+ if (WSAP_VTCORE_EXPECT(len <= cols, 1)) {
part_put_narrow(dst, line_off, len);
} else {
part_put_narrow_rows(dst, line_off, len, rows_narrow(len, cols));
@@ -2309,7 +2309,7 @@ void term_hist_push_ascii_lines(struct hist *h, const struct hist_ascii_line *li
uint32_t len = lines[i].len;
/* A blank line: no text, no page slot, one row. The scan does
* not stop on it, so the batch keeps its room and its setup. */
- if (TERM_EXPECT(len == 0, 0)) {
+ if (WSAP_VTCORE_EXPECT(len == 0, 0)) {
ring[head++ & rmask] = HLINE_BLANK;
rows_add++;
continue;
@@ -2317,7 +2317,7 @@ void term_hist_push_ascii_lines(struct hist *h, const struct hist_ascii_line *li
bytes_copy_small(page + off, lines[i].ptr, (int)len);
n_text++;
any_text = true;
- if (TERM_EXPECT(len <= cols, 1)) {
+ if (WSAP_VTCORE_EXPECT(len <= cols, 1)) {
part_put_narrow(&ring[head++ & rmask], page_off | off, len);
rows_add++;
} else {
@@ -2340,12 +2340,12 @@ void term_hist_push_ascii_lines(struct hist *h, const struct hist_ascii_line *li
}
}
-void term_hist_push_blank(struct hist *h, size_t n)
+void wsap_vtcore_hist_push_blank(struct hist *h, size_t n)
{
if (!h->line_limit || n == 0)
return;
if (hist_is_open(h)) {
- term_hist_close_open_line(h);
+ wsap_vtcore_hist_close_open_line(h);
n--;
}
if (n == 0)
@@ -2361,7 +2361,7 @@ void term_hist_push_blank(struct hist *h, size_t n)
}
if (n >= h->line_limit) {
uint64_t end = hist_end_id(h) + n;
- term_hist_clear(h);
+ wsap_vtcore_hist_clear(h);
h->base_id = h->rows_id = end - h->line_limit;
n = h->line_limit;
h->all_blank = true;
@@ -2429,7 +2429,7 @@ static void runs_iter_init(struct runs_iter *it, const struct hist *h, const str
/* Take up to n cells of the current run. it->pen is their pen. */
static inline uint32_t runs_take(struct runs_iter *it, uint32_t n)
{
- while (TERM_EXPECT(it->left == 0, 0)) {
+ while (WSAP_VTCORE_EXPECT(it->left == 0, 0)) {
if (it->p < it->end) {
it->p = read_run(it->p, &it->pen, &it->left);
} else if (it->pending) {
@@ -2516,21 +2516,21 @@ static const uint8_t *text_cell(const uint8_t *s, const uint8_t *end, struct gst
}
uint8_t k = s[1];
s += 2;
- uint32_t cps[TERM_GRAPHEME_MAX_LEN];
+ uint32_t cps[WSAP_VTCORE_GRAPHEME_MAX_LEN];
int n = 0;
for (int i = 0; i < (k & 0x1f) && s < end; i++) {
uint32_t c;
s += get_utf8(s, end, &c);
- if (n < TERM_GRAPHEME_MAX_LEN)
+ if (n < WSAP_VTCORE_GRAPHEME_MAX_LEN)
cps[n++] = c;
}
- *cp = n == 0 ? ' ' : (g && n > 1) ? term_gstore_intern(g, cps, n) : cps[0];
+ *cp = n == 0 ? ' ' : (g && n > 1) ? wsap_vtcore_gstore_intern(g, cps, n) : cps[0];
*shape = (uint16_t)(((k & 0x80) ? CELL_WIDE : 0) | ((k & 0x40) ? CELL_EMOJI : 0) |
((k & 0x20) ? CELL_TEXT : 0));
return s;
}
-uint64_t term_hist_line_cells(const struct hist *h, uint64_t id)
+uint64_t wsap_vtcore_hist_line_cells(const struct hist *h, uint64_t id)
{
if (!line_valid(h, id))
return 0;
@@ -2545,7 +2545,7 @@ uint64_t term_hist_line_cells(const struct hist *h, uint64_t id)
return cells;
}
-uint64_t term_hist_line_wide(const struct hist *h, uint64_t id)
+uint64_t wsap_vtcore_hist_line_wide(const struct hist *h, uint64_t id)
{
if (!line_valid(h, id))
return 0;
@@ -2560,7 +2560,7 @@ uint64_t term_hist_line_wide(const struct hist *h, uint64_t id)
return wide;
}
-uint8_t term_hist_line_flags(const struct hist *h, uint64_t id)
+uint8_t wsap_vtcore_hist_line_flags(const struct hist *h, uint64_t id)
{
if (!line_valid(h, id))
return 0;
@@ -2596,7 +2596,7 @@ static int line_rows_walk(const struct hist *h, uint64_t first, uint64_t end, in
return rows;
}
-int term_hist_line_rows(const struct hist *h, uint64_t id, int cols)
+int wsap_vtcore_hist_line_rows(const struct hist *h, uint64_t id, int cols)
{
if (cols <= 0 || !line_valid(h, id))
return 0;
@@ -2604,7 +2604,7 @@ int term_hist_line_rows(const struct hist *h, uint64_t id, int cols)
const struct hline *f = part(h, first);
if (cols == h->wrap_cols) {
if (id < h->rows_id &&
- ((f->flags & HLINE_ROWS_EXACT) || !(term_hist_line_flags(h, id) & HLINE_HAS_WIDE))) {
+ ((f->flags & HLINE_ROWS_EXACT) || !(wsap_vtcore_hist_line_flags(h, id) & HLINE_HAS_WIDE))) {
if (f->wrap_rows != ROWS_UNKNOWN)
return f->wrap_rows;
if ((f->flags & HLINE_ROWS_EXACT) && h->exact_rows)
@@ -2614,9 +2614,9 @@ int term_hist_line_rows(const struct hist *h, uint64_t id, int cols)
h->walk_off == part(h, h->walk_seq)->text_len)
return (int)h->walk_rows;
}
- uint64_t cells = term_hist_line_cells(h, id);
+ uint64_t cells = wsap_vtcore_hist_line_cells(h, id);
if (cells <= (uint64_t)cols ||
- !(term_hist_line_flags(h, id) & (HLINE_HAS_WIDE | HLINE_HAS_CLUSTER)))
+ !(wsap_vtcore_hist_line_flags(h, id) & (HLINE_HAS_WIDE | HLINE_HAS_CLUSTER)))
return (int)rows_narrow(cells, cols);
return line_rows_walk(h, first, line_end(h, first), cols);
}
@@ -2672,7 +2672,7 @@ static bool line_narrow(const struct hist *h, uint64_t first, uint64_t end)
return true;
}
-int term_hist_decode_segments(const struct hist *h, uint64_t id, int start_seg, int count, int cols,
+int wsap_vtcore_hist_decode_segments(const struct hist *h, uint64_t id, int start_seg, int count, int cols,
struct cell *out, int *lens, struct gstore *g)
{
if (count <= 0 || start_seg < 0 || cols <= 0 || !line_valid(h, id))
@@ -2730,7 +2730,7 @@ int term_hist_decode_segments(const struct hist *h, uint64_t id, int start_seg,
}
if (g)
- term_gstore_pin(g);
+ wsap_vtcore_gstore_pin(g);
int row = 0, col = 0;
int end_seg = start_seg + count;
uint64_t s = first;
@@ -2787,14 +2787,14 @@ int term_hist_decode_segments(const struct hist *h, uint64_t id, int start_seg,
int seg_idx = row - start_seg;
struct cell *row_out = out + (size_t)seg_idx * (size_t)cols;
if (col < cols)
- row_out[col] = (struct cell){ ' ', TERM_COLOR_FG, TERM_COLOR_BG, CELL_WRAP_PAD, 0 };
+ row_out[col] = (struct cell){ ' ', WSAP_VTCORE_COLOR_FG, WSAP_VTCORE_COLOR_BG, CELL_WRAP_PAD, 0 };
if (lens)
lens[seg_idx] = col < cols ? cols : col;
row++;
col = 0;
if (row == end_seg) {
if (g)
- term_gstore_unpin(g);
+ wsap_vtcore_gstore_unpin(g);
dec->epoch = h->index_epoch;
dec->id = id;
dec->cols = (uint16_t)cols;
@@ -2820,7 +2820,7 @@ int term_hist_decode_segments(const struct hist *h, uint64_t id, int start_seg,
}
if (row == end_seg) {
if (g)
- term_gstore_unpin(g);
+ wsap_vtcore_gstore_unpin(g);
dec->epoch = h->index_epoch;
dec->id = id;
dec->cols = (uint16_t)cols;
@@ -2841,15 +2841,15 @@ int term_hist_decode_segments(const struct hist *h, uint64_t id, int start_seg,
}
dec->valid = false;
if (g)
- term_gstore_unpin(g);
+ wsap_vtcore_gstore_unpin(g);
return decoded;
}
-int term_hist_decode_segment(const struct hist *h, uint64_t id, int seg, int cols,
+int wsap_vtcore_hist_decode_segment(const struct hist *h, uint64_t id, int seg, int cols,
struct cell *out, struct gstore *g)
{
int len = 0;
- int got = term_hist_decode_segments(h, id, seg, 1, cols, out, &len, g);
+ int got = wsap_vtcore_hist_decode_segments(h, id, seg, 1, cols, out, &len, g);
return got > 0 ? len : 0;
}
@@ -2859,7 +2859,7 @@ static int decode_line(const struct hist *h, uint64_t first, uint64_t end,
{
int n = 0;
if (g)
- term_gstore_pin(g);
+ wsap_vtcore_gstore_pin(g);
for (uint64_t s = first; s < end; s++) {
const struct hline *p = part(h, s);
if (!p->text_len)
@@ -2882,11 +2882,11 @@ static int decode_line(const struct hist *h, uint64_t first, uint64_t end,
}
}
if (g)
- term_gstore_unpin(g);
+ wsap_vtcore_gstore_unpin(g);
return n;
}
-int term_hist_text_decode(const struct text_row *row, struct cell *out, int cap, struct gstore *g)
+int wsap_vtcore_hist_text_decode(const struct text_row *row, struct cell *out, int cap, struct gstore *g)
{
struct runs_iter it;
runs_iter_runs(&it, &row->runs, &row->start);
@@ -2921,7 +2921,7 @@ int term_hist_text_decode(const struct text_row *row, struct cell *out, int cap,
return n < cap ? n : cap;
}
-void term_hist_text_mark_links(const struct text_row *row, void (*mark)(void *ud, uint16_t link), void *ud)
+void wsap_vtcore_hist_text_mark_links(const struct text_row *row, void (*mark)(void *ud, uint16_t link), void *ud)
{
if (!(row->flags & HLINE_HAS_LINK) && !row->start.link)
return;
@@ -2940,7 +2940,7 @@ void term_hist_text_mark_links(const struct text_row *row, void (*mark)(void *ud
mark(ud, it.pending_pen.link);
}
-void term_hist_mark_links(const struct hist *h, void (*mark)(void *ud, uint16_t link), void *ud)
+void wsap_vtcore_hist_mark_links(const struct hist *h, void (*mark)(void *ud, uint16_t link), void *ud)
{
for (uint64_t s = h->tail; s < h->head; s++) {
const struct hline *p = part(h, s);
@@ -2976,7 +2976,7 @@ static void drop_head_part(struct hist *h)
cont_trim(h);
}
-int term_hist_peek_last_line(const struct hist *h, struct cell *out, int cap, struct gstore *g)
+int wsap_vtcore_hist_peek_last_line(const struct hist *h, struct cell *out, int cap, struct gstore *g)
{
if (h->lines == 0)
return 0;
@@ -2984,13 +2984,13 @@ int term_hist_peek_last_line(const struct hist *h, struct cell *out, int cap, st
return decode_line(h, line_first(h, id), h->head, out, cap, g);
}
-int term_hist_pop_line(struct hist *h, struct cell *out, int cap, struct gstore *g)
+int wsap_vtcore_hist_pop_line(struct hist *h, struct cell *out, int cap, struct gstore *g)
{
if (h->lines == 0)
return 0;
uint64_t id = hist_end_id(h) - 1;
uint64_t first = line_first(h, id);
- int n = out ? decode_line(h, first, h->head, out, cap, g) : (int)term_hist_line_cells(h, id);
+ int n = out ? decode_line(h, first, h->head, out, cap, g) : (int)wsap_vtcore_hist_line_cells(h, id);
if (id < h->rows_id) {
rows_uncount(h, id);
h->rows_id = id;
@@ -3001,8 +3001,8 @@ int term_hist_pop_line(struct hist *h, struct cell *out, int cap, struct gstore
h->index_epoch++;
if (h->lines) {
uint64_t last = hist_end_id(h) - 1;
- h->last_cells = term_hist_line_cells(h, last);
- h->last_wide = term_hist_line_wide(h, last);
+ h->last_cells = wsap_vtcore_hist_line_cells(h, last);
+ h->last_wide = wsap_vtcore_hist_line_wide(h, last);
h->last_id = last;
}
runs_reset(&h->runs);
@@ -3015,21 +3015,21 @@ int term_hist_pop_line(struct hist *h, struct cell *out, int cap, struct gstore
return n;
}
-int term_hist_pop_tail_cells(struct hist *h, int n, struct cell *out, struct gstore *g)
+int wsap_vtcore_hist_pop_tail_cells(struct hist *h, int n, struct cell *out, struct gstore *g)
{
if (h->lines == 0 || n <= 0)
return 0;
- uint64_t total = term_hist_line_cells(h, hist_end_id(h) - 1);
+ uint64_t total = wsap_vtcore_hist_line_cells(h, hist_end_id(h) - 1);
if (total == 0) {
- term_hist_pop_line(h, NULL, 0, g);
+ wsap_vtcore_hist_pop_line(h, NULL, 0, g);
return 0;
}
struct cell *all = malloc((size_t)total * sizeof(*all));
if (!all)
return 0;
if (g)
- term_gstore_pin(g);
- int got = term_hist_pop_line(h, all, (int)total, g);
+ wsap_vtcore_gstore_pin(g);
+ int got = wsap_vtcore_hist_pop_line(h, all, (int)total, g);
int take = n < got ? n : got;
int keep = got - take;
if (keep > 0 && (all[keep].flags & CELL_TRAIL)) {
@@ -3041,17 +3041,17 @@ int term_hist_pop_tail_cells(struct hist *h, int n, struct cell *out, struct gst
if (keep > 0) {
uint16_t cols = h->wrap_cols ? h->wrap_cols : 1;
for (int i = 0; i < keep; i += cols)
- term_hist_push_row(h, all + i, keep - i < cols ? keep - i : cols, true, g);
+ wsap_vtcore_hist_push_row(h, all + i, keep - i < cols ? keep - i : cols, true, g);
}
if (g)
- term_gstore_unpin(g);
+ wsap_vtcore_gstore_unpin(g);
free(all);
return take;
}
/* ---- Rows ---- */
-void term_hist_set_width(struct hist *h, int cols)
+void wsap_vtcore_hist_set_width(struct hist *h, int cols)
{
if (h->wrap_cols == cols)
return;
@@ -3061,7 +3061,7 @@ void term_hist_set_width(struct hist *h, int cols)
h->walk_on = false;
}
-uint64_t term_hist_line_estimate(const struct hist *h, uint64_t id, int cols)
+uint64_t wsap_vtcore_hist_line_estimate(const struct hist *h, uint64_t id, int cols)
{
if (!line_valid(h, id))
return 0;
@@ -3071,18 +3071,18 @@ uint64_t term_hist_line_estimate(const struct hist *h, uint64_t id, int cols)
return first->wrap_rows != ROWS_UNKNOWN ? first->wrap_rows :
h->exact_rows[line_first(h, id) & h->ring_mask];
}
- uint64_t cells = term_hist_line_cells(h, id);
+ uint64_t cells = wsap_vtcore_hist_line_cells(h, id);
if (cols == 1)
- cells -= term_hist_line_wide(h, id);
+ cells -= wsap_vtcore_hist_line_wide(h, id);
return rows_narrow(cells, cols);
}
-void term_hist_refine_rows(struct hist *h, uint64_t id, int cols, int rows)
+void wsap_vtcore_hist_refine_rows(struct hist *h, uint64_t id, int cols, int rows)
{
if (cols != h->wrap_cols || id >= h->rows_id || id < h->base_id)
return;
uint64_t seq = line_first(h, id);
- uint64_t old = term_hist_line_estimate(h, id, cols);
+ uint64_t old = wsap_vtcore_hist_line_estimate(h, id, cols);
if (rows >= ROWS_UNKNOWN) {
if (!h->exact_rows) {
h->exact_rows = calloc((size_t)h->ring_mask + 1, sizeof(*h->exact_rows));
@@ -3098,53 +3098,53 @@ void term_hist_refine_rows(struct hist *h, uint64_t id, int cols, int rows)
}
/* Fill descriptor counts only. This never reads the encoded text. */
-void term_hist_prepare_rows(struct hist *h, int cols)
+void wsap_vtcore_hist_prepare_rows(struct hist *h, int cols)
{
if (cols != h->wrap_cols)
- term_hist_set_width(h, cols);
+ wsap_vtcore_hist_set_width(h, cols);
uint64_t stop = hist_end_id(h) - (hist_is_open(h) ? 1 : 0);
for (; h->rows_id < stop; h->rows_id++) {
- uint64_t rows = term_hist_line_estimate(h, h->rows_id, cols);
+ uint64_t rows = wsap_vtcore_hist_line_estimate(h, h->rows_id, cols);
struct hline *first = part(h, line_first(h, h->rows_id));
first->wrap_rows = row_count_byte(rows);
first->flags &= (uint8_t)~HLINE_ROWS_EXACT;
if (rows < ROWS_UNKNOWN &&
- (!(term_hist_line_flags(h, h->rows_id) & HLINE_HAS_WIDE) || cols == 1))
+ (!(wsap_vtcore_hist_line_flags(h, h->rows_id) & HLINE_HAS_WIDE) || cols == 1))
first->flags |= HLINE_ROWS_EXACT;
h->counted_rows += rows;
}
}
-uint64_t term_hist_estimated_rows(const struct hist *h, int cols)
+uint64_t wsap_vtcore_hist_estimated_rows(const struct hist *h, int cols)
{
if (!h || cols <= 0 || !h->lines)
return 0;
uint64_t total = cols == h->wrap_cols ? h->counted_rows : 0;
uint64_t first = cols == h->wrap_cols ? h->rows_id : h->base_id;
for (uint64_t id = first; id < hist_end_id(h); id++)
- total += term_hist_line_estimate(h, id, cols);
+ total += wsap_vtcore_hist_line_estimate(h, id, cols);
return total;
}
-uint64_t term_hist_rows(const struct hist *h, int cols)
+uint64_t wsap_vtcore_hist_rows(const struct hist *h, int cols)
{
if (!h || cols <= 0)
return 0;
uint64_t total = 0;
for (uint64_t id = hist_first_id(h); id < hist_end_id(h); id++)
- total += (uint64_t)term_hist_line_rows(h, id, cols);
+ total += (uint64_t)wsap_vtcore_hist_line_rows(h, id, cols);
return total;
}
/* Locate a row boundary by its cell offset. Wide wrap pads do not count. */
-uint64_t term_hist_segment_cell(const struct hist *h, uint64_t id, int seg, int cols)
+uint64_t wsap_vtcore_hist_segment_cell(const struct hist *h, uint64_t id, int seg, int cols)
{
if (!line_valid(h, id))
return 0;
uint64_t base = id == h->base_cell_id ? h->base_cell : 0;
if (seg <= 0)
return base;
- if (!(term_hist_line_flags(h, id) & (HLINE_HAS_WIDE | HLINE_HAS_CLUSTER)))
+ if (!(wsap_vtcore_hist_line_flags(h, id) & (HLINE_HAS_WIDE | HLINE_HAS_CLUSTER)))
return base + (uint64_t)seg * cols;
uint64_t first = line_first(h, id), end = line_end(h, first), cells = 0;
int row = 0, col = 0;
@@ -3168,14 +3168,14 @@ uint64_t term_hist_segment_cell(const struct hist *h, uint64_t id, int seg, int
return base + cells;
}
-int term_hist_cell_segment(const struct hist *h, uint64_t id, uint64_t cell, int cols)
+int wsap_vtcore_hist_cell_segment(const struct hist *h, uint64_t id, uint64_t cell, int cols)
{
if (!line_valid(h, id) || cols <= 0)
return 0;
uint64_t base = id == h->base_cell_id ? h->base_cell : 0;
cell = cell > base ? cell - base : 0;
- if (!(term_hist_line_flags(h, id) & (HLINE_HAS_WIDE | HLINE_HAS_CLUSTER))) {
- uint64_t cells = term_hist_line_cells(h, id);
+ if (!(wsap_vtcore_hist_line_flags(h, id) & (HLINE_HAS_WIDE | HLINE_HAS_CLUSTER))) {
+ uint64_t cells = wsap_vtcore_hist_line_cells(h, id);
if (cells && cell >= cells)
cell = cells - 1;
return (int)(cell / cols);
@@ -3205,7 +3205,7 @@ int term_hist_cell_segment(const struct hist *h, uint64_t id, uint64_t cell, int
/* ---- Life cycle ---- */
-bool term_hist_init(struct hist *h, int line_limit, size_t byte_cap)
+bool wsap_vtcore_hist_init(struct hist *h, int line_limit, size_t byte_cap)
{
memset(h, 0, sizeof(*h));
h->all_blank = true;
@@ -3227,22 +3227,22 @@ bool term_hist_init(struct hist *h, int line_limit, size_t byte_cap)
h->page_parts = calloc(h->max_pages, sizeof(*h->page_parts));
h->free_pages = malloc(h->max_pages * sizeof(*h->free_pages));
if (!h->pages || !h->page_used || !h->page_parts || !h->free_pages || !ring_fit(h, 1)) {
- term_hist_free(h);
+ wsap_vtcore_hist_free(h);
return false;
}
return true;
}
-void term_hist_free(struct hist *h)
+void wsap_vtcore_hist_free(struct hist *h)
{
if (h->pages)
for (uint32_t i = 0; i < h->npages; i++)
- term_aligned_free(h->pages[i]);
+ wsap_vtcore_aligned_free(h->pages[i]);
free(h->pages);
free(h->page_used);
free(h->page_parts);
free(h->free_pages);
- term_aligned_free(h->ring);
+ wsap_vtcore_aligned_free(h->ring);
free(h->blocks);
free(h->exact_rows);
free(h->cont);
@@ -3250,7 +3250,7 @@ void term_hist_free(struct hist *h)
memset(h, 0, sizeof(*h));
}
-void term_hist_clear(struct hist *h)
+void wsap_vtcore_hist_clear(struct hist *h)
{
h->index_epoch++;
uint64_t end = hist_end_id(h);