This is an automated email from the git hooks/post-receive script.

git pushed a commit to branch master
in repository terminology.

View the commit online.

commit 00bb4bbe7770f9dc56a63a35ddc56ba1a9548304
Author: Cedric BAIL <[email protected]>
AuthorDate: Fri Nov 20 18:45:07 2026 -0600

    termptyops: write the attributes of an ASCII run from registers
    
    _append_ascii_run() cleared att.dblwidth in a local copy of the
    attributes, and GCC 11.4 put that byte clear inside the loop, on the
    stack, right before the 8 and 4 byte loads that copy att into the
    cell. A byte store cannot be forwarded to a wider load, so every cell
    of a run waited for the store to reach the cache. On upstream-fixes,
    termpty_text_append_known_ascii took 42% of the cycles of the scroll
    corpus and 71% of plain-ascii, and 85% and 93% of its samples sit on
    the store after that load (the sample skids past the load itself).
    The store forwarding interlock counter, ls_bad_status2.stli_other,
    reads 341 M on plain-ascii and 362 M on scroll.
    
    Copy att through two words that are loaded once before the loop: the
    counter falls to 44 M and 101 M.
    
    The stall depends on the compiler and the CPU: Clang 14 does not
    emit the byte clear in the loop and gains nothing. Numbers are GCC
    11.4 on a Ryzen 7 6800U.
    
    tybench -i 10 -w 1, release build with -falign-functions=64
    -falign-loops=64 -falign-jumps=32, 2000 lines of scrollback, median
    of 7 interleaved runs of perf stat on one pinned CPU, from a fixed
    working directory, parent vs this:
    
      corpus         Gcycles:u         Ginstructions:u
      plain-ascii    1.725 -> 0.737    2.623 ->  2.491   -57% / -5.0%
      long-lines     1.671 -> 0.673    2.206 ->  2.071   -60% / -6.1%
      scroll-region  1.432 -> 0.579    2.213 ->  2.099   -60% / -5.1%
      scroll         2.950 -> 2.175    7.002 ->  6.885   -26% / -1.7%
      rep            4.577 -> 3.067   12.701 -> 12.495   -33% / -1.6%
      insert-mode    3.234 -> 2.447    8.032 ->  7.921   -24% / -1.4%
      sgr            1.927 -> 1.664    4.943 ->  4.892   -14% / -1.0%
      insert         1.950 -> 1.730    5.614 ->  5.573   -11% / -0.7%
      fill           2.095 -> 1.980    5.915 ->  5.889    -6% / -0.4%
      unicode        2.006 -> 1.970    6.238 ->  6.236    -2% /  0.0%
      strings        0.333 -> 0.331    1.515 ->  1.515    -1% /  0.0%
      hyperlink      3.326 -> 3.354   10.014 -> 10.012    +1% /  0.0%
    
    Hyperlink takes the per-character path and is the noisiest corpus:
    its instruction count does not move. The cells written are the same.
---
 src/bin/termptyops.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/src/bin/termptyops.c b/src/bin/termptyops.c
index 9632b66d..db48c1d5 100644
--- a/src/bin/termptyops.c
+++ b/src/bin/termptyops.c
@@ -345,11 +345,23 @@ _append_ascii_run(Termpty *ty, Termcell *cells, const Eina_Unicode *cp, int n,
                   int max_right)
 {
    Termatt att = ty->termstate.att;
+   uint64_t att_lo;
+   uint32_t att_hi;
    int cx = ty->cursor_state.cx;
    int k;
 
+   _Static_assert(sizeof(Termatt) == sizeof(att_lo) + sizeof(att_hi),
+                  "Termatt is copied as a 64 and a 32 bit word");
+
    /* Nothing in 0x20..0x7e is ever double width. */
    att.dblwidth = 0;
+   /* Copied through two words held in registers: the compiler otherwise
+    * clears the bit in att, on the stack, once per cell, and reads att back
+    * as wider words in the same iteration. The CPU cannot forward a byte
+    * store to a wider load, which then waits for it to reach the cache. */
+   memcpy(&att_lo, &att, sizeof(att_lo));
+   memcpy(&att_hi, (const unsigned char *)&att + sizeof(att_lo),
+          sizeof(att_hi));
 
    for (k = 0; k < n; k++)
      {
@@ -359,7 +371,9 @@ _append_ascii_run(Termpty *ty, Termcell *cells, const Eina_Unicode *cp, int n,
         if (EINA_UNLIKELY(dst->att.link_id))
           term_link_refcount_dec(ty, dst->att.link_id, 1);
         dst->codepoint = cp[k];
-        dst->att = att;
+        memcpy(&dst->att, &att_lo, sizeof(att_lo));
+        memcpy((unsigned char *)&dst->att + sizeof(att_lo), &att_hi,
+               sizeof(att_hi));
      }
 
    /* Recorded before the cursor moves, as the per-character path does. */

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

Reply via email to