Use SIMD to replace C0 control codes in Go code

This commit is contained in:
Kovid Goyal
2025-07-21 08:54:22 +05:30
parent 12c1b0cbdf
commit fd5876b94e
10 changed files with 74 additions and 47 deletions

View File

@@ -5,7 +5,6 @@ package simdstring
import (
"bytes"
"fmt"
"github.com/kovidgoyal/kitty/tools/utils"
"runtime"
"strings"
"testing"
@@ -120,13 +119,19 @@ func addressof_data(b []byte) uintptr {
return uintptr(unsafe.Pointer(&b[0]))
}
func memset(ans []byte, val byte) {
for i := range ans {
ans[i] = val
}
}
func aligned_slice(sz, alignment int) ([]byte, []byte) {
ans := make([]byte, sz+alignment+512)
a := addressof_data(ans)
a &= uintptr(alignment - 1)
extra := uintptr(alignment) - a
utils.Memset(ans, '<')
utils.Memset(ans[extra+uintptr(sz):], '>')
memset(ans, '<')
memset(ans[extra+uintptr(sz):], '>')
return ans[extra : extra+uintptr(sz)], ans
}