From 28135b7a20c4fd31e7a17fe171e11c260473b836 Mon Sep 17 00:00:00 2001 From: Justine Tunney Date: Wed, 3 Feb 2021 15:53:33 -0800 Subject: [PATCH] Add `q` keyboard shortcut to printvideo.com (#37) --- ape/ape.S | 2 +- libc/bits/likely.h | 4 ++-- libc/crt/crt.S | 5 ++--- libc/intrin/asan.c | 9 +++++---- libc/stubs/xnu.S | 5 ++--- libc/unicode/wcwidth.c | 20 ++++++++++++-------- tool/viz/printvideo.c | 12 +++++++++--- 7 files changed, 33 insertions(+), 24 deletions(-) diff --git a/ape/ape.S b/ape/ape.S index 0463e0499..3c0cf479e 100644 --- a/ape/ape.S +++ b/ape/ape.S @@ -663,7 +663,7 @@ ape.macho: .quad 0 # r13 .quad 0 # r14 .quad 0 # r15 - .quad _start_xnu # rip + .quad _xnu # rip .quad 0 # rflags .quad 0 # cs .quad 0 # fs diff --git a/libc/bits/likely.h b/libc/bits/likely.h index 78e3dfc77..0464e9cd5 100644 --- a/libc/bits/likely.h +++ b/libc/bits/likely.h @@ -2,8 +2,8 @@ #define COSMOPOLITAN_LIBC_BITS_LIKELY_H_ #if !(__ASSEMBLER__ + __LINKER__ + 0) -#define likely(expr) __builtin_expect(!!(expr), 1) -#define unlikely(expr) __builtin_expect(!!(expr), 0) +#define LIKELY(expr) __builtin_expect(!!(expr), 1) +#define UNLIKELY(expr) __builtin_expect(!!(expr), 0) #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_BITS_LIKELY_H_ */ diff --git a/libc/crt/crt.S b/libc/crt/crt.S index ad70ccc6e..519b11de7 100644 --- a/libc/crt/crt.S +++ b/libc/crt/crt.S @@ -62,7 +62,6 @@ _start: test %rdi,%rdi / @param rsp is [n,argv₀..argvₙ₋₁,0,envp₀..,0,auxv₀..,0,..] / @note FreeBSD is special (see freebsd/lib/csu/amd64/...) / @noreturn -_start_xnu: - movb $XNU,__hostos(%rip) +_xnu: movb $XNU,__hostos(%rip) jmp 0b - .endfn _start_xnu,weak,hidden + .endfn _xnu,weak,hidden diff --git a/libc/intrin/asan.c b/libc/intrin/asan.c index e9c604c58..f2a61c503 100644 --- a/libc/intrin/asan.c +++ b/libc/intrin/asan.c @@ -18,6 +18,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/alg/reverse.h" #include "libc/bits/bits.h" +#include "libc/bits/likely.h" #include "libc/bits/weaken.h" #include "libc/calls/calls.h" #include "libc/dce.h" @@ -321,11 +322,11 @@ static size_t __asan_int2str(int64_t i, char *a) { return 1 + __asan_uint2str(-i, a); } -void __asan_poison(uintptr_t p, size_t n, int kind) { +flattenout void __asan_poison(uintptr_t p, size_t n, int kind) { int k; char *s; if (!n) return; - if (p & 7) { + if (UNLIKELY(p & 7)) { k = MIN(8 - (p & 7), n); s = SHADOW(p); if (*s == 0 || *s > (p & 7)) { @@ -343,11 +344,11 @@ void __asan_poison(uintptr_t p, size_t n, int kind) { } } -void __asan_unpoison(uintptr_t p, size_t n) { +flattenout void __asan_unpoison(uintptr_t p, size_t n) { int k; char *s; if (!n) return; - if (p & 7) { + if (UNLIKELY(p & 7)) { k = MIN(8 - (p & 7), n); s = SHADOW(p); *s = 0; diff --git a/libc/stubs/xnu.S b/libc/stubs/xnu.S index 23ad0dd76..68ed799af 100644 --- a/libc/stubs/xnu.S +++ b/libc/stubs/xnu.S @@ -19,6 +19,5 @@ #include "libc/macros.h" .source __FILE__ -_start_xnu: - ud2 - .endfn _start_xnu,weak +_xnu: ud2 + .endfn _xnu,weak diff --git a/libc/unicode/wcwidth.c b/libc/unicode/wcwidth.c index 3d8c9282f..fbb95490f 100644 --- a/libc/unicode/wcwidth.c +++ b/libc/unicode/wcwidth.c @@ -16,6 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/bits/likely.h" #include "libc/unicode/unicode.h" extern const uint8_t kEastAsianWidth[]; @@ -26,15 +27,18 @@ extern const uint32_t kCombiningCharsBits; /** * Returns cell width of monospace character. */ -int wcwidth(wchar_t ucs) { - if (ucs == 0) return 0; - if ((0 <= ucs && ucs < 32) || (0x7f <= ucs && ucs < 0xA0)) { - return -1; - } else if ((0 <= ucs && ucs < kCombiningCharsBits) && - !!(kCombiningChars[ucs >> 3] & (1 << (ucs & 7)))) { +int wcwidth(wchar_t c) { + if (LIKELY(32 <= c && c < 127)) { + return 1; + } else if (!c) { return 0; - } else if (0 <= ucs && ucs < kEastAsianWidthBits) { - return 1 + !!(kEastAsianWidth[ucs >> 3] & (1 << (ucs & 7))); + } else if ((0 < c && c < 32) || (0x7f <= c && c < 0xA0)) { + return -1; + } else if ((0 <= c && c < kCombiningCharsBits) && + !!(kCombiningChars[c >> 3] & (1 << (c & 7)))) { + return 0; + } else if (0 <= c && c < kEastAsianWidthBits) { + return 1 + !!(kEastAsianWidth[c >> 3] & (1 << (c & 7))); } else { return 1; } diff --git a/tool/viz/printvideo.c b/tool/viz/printvideo.c index a6f39aa47..25aef47b0 100644 --- a/tool/viz/printvideo.c +++ b/tool/viz/printvideo.c @@ -127,12 +127,17 @@ Flags & Keyboard Shortcuts:\n\ CTRL+L redraw [keyboard]\n\ CTRL+Z suspend [keyboard]\n\ CTRL+C exit [keyboard]\n\ + q quit [keyboard]\n\ \n\ Effects Shortcuts:\n\ \n\ - H +Hue ALT+H -Hue\n\ - S +Saturation ALT+S -Saturation\n\ - L +Lightness ALT+L -Lightness\n\ + S Toggle Swing (TV, PC)\n\ + Y Toggle Black/White Mode\n\ + p Toggle Primaries (BT.601, BT.709)\n\ + g +Gamma G -Gamma\n\ + l +Illumination L -Illumination\n\ + k +LumaKernel K -LumaKernel\n\ + j +ChromaKernel J -ChromaKernel\n\ CTRL-G {Unsharp,Sharp}\n\ \n\ Environment Variables:\n\ @@ -1018,6 +1023,7 @@ static optimizesize void ReadKeyboard(void) { chromakernel_ = MOD(sgn + chromakernel_, ARRAYLEN(kMagkern)); memcpy(g_magkern, kMagkern[chromakernel_], sizeof(kMagkern[0])); break; + case 'q': case CTRL('C'): longjmp(jb_, 1); break;