From 3e492f6eb5c9124bd14f3f57338f09e914ed8d63 Mon Sep 17 00:00:00 2001 From: miod Date: Fri, 2 Sep 2022 06:19:04 +0000 Subject: [PATCH] Use a shorter system call invocation template for system calls in the range 0-127, where immediate addressing can be used to load the system call number in r0, rather than performing a memory load using pc-relative addressing. No functional change, but rm(1) runs a couple cycles faster per file now. --- lib/libc/arch/sh/SYS.h | 32 +++++++++++++++++++++-------- lib/libc/arch/sh/sys/brk.S | 8 +++++++- lib/libc/arch/sh/sys/sbrk.S | 8 +++++++- lib/libc/arch/sh/sys/sigprocmask.S | 11 ++++++++-- lib/libc/arch/sh/sys/sigsuspend.S | 8 +++++++- lib/libc/arch/sh/sys/tfork_thread.S | 18 +++++++++++++--- libexec/ld.so/sh/SYS.h | 32 +++++++++++++++++++++-------- 7 files changed, 93 insertions(+), 24 deletions(-) diff --git a/lib/libc/arch/sh/SYS.h b/lib/libc/arch/sh/SYS.h index 46bc22acf0a..bed791bab88 100644 --- a/lib/libc/arch/sh/SYS.h +++ b/lib/libc/arch/sh/SYS.h @@ -1,4 +1,4 @@ -/* $OpenBSD: SYS.h,v 1.11 2016/05/18 20:21:13 guenther Exp $ */ +/* $OpenBSD: SYS.h,v 1.12 2022/09/02 06:19:04 miod Exp $ */ /*- * Copyright (c) 1990 The Regents of the University of California. * All rights reserved. @@ -85,14 +85,30 @@ #define __END(x) \ __END_HIDDEN(x); SET_ENTRY_SIZE(x) +#ifdef __ASSEMBLER__ +/* + * If the system call number fits in a 8-bit signed value (i.e. fits in 7 bits), + * then we can use the #imm8 addressing mode. + */ + +.macro systrap num +.iflt \num - 128 + mov # \num, r0 + trapa #0x80 +.else + mov.l 903f, r0 + trapa #0x80 + bra 904f + nop + .align 2 + 903: .long \num + 904: +.endif +.endm +#endif + #define SYSTRAP(x) \ - mov.l 903f, r0; \ - .word 0xc380; /* trapa #0x80; */ \ - bra 904f; \ - nop; \ - .align 2; \ - 903: .long (SYS_ ## x); \ - 904: + systrap SYS_ ## x #define _SYSCALL_NOERROR(x,y) \ SYSENTRY(x); \ diff --git a/lib/libc/arch/sh/sys/brk.S b/lib/libc/arch/sh/sys/brk.S index 9600546fa7c..4b854a31db5 100644 --- a/lib/libc/arch/sh/sys/brk.S +++ b/lib/libc/arch/sh/sys/brk.S @@ -1,4 +1,4 @@ -/* $OpenBSD: brk.S,v 1.6 2016/05/30 05:18:52 guenther Exp $ */ +/* $OpenBSD: brk.S,v 1.7 2022/09/02 06:19:04 miod Exp $ */ /* $NetBSD: brk.S,v 1.10 2006/01/06 03:58:31 uwe Exp $ */ /*- @@ -64,7 +64,11 @@ ENTRY(brk) bf 1f mov r0, r4 1: +#if SYS_break >= 128 mov.l LSYS_break, r0 +#else + mov #SYS_break, r0 +#endif trapa #0x80 bf 2f #ifdef __PIC__ @@ -81,7 +85,9 @@ ENTRY(brk) SET_ERRNO_AND_RETURN .align 2 +#if SYS_break >= 128 LSYS_break: .long SYS_break +#endif #ifdef __PIC__ L_GOT: .long _GLOBAL_OFFSET_TABLE_ Lminbrk: .long __minbrk@GOT diff --git a/lib/libc/arch/sh/sys/sbrk.S b/lib/libc/arch/sh/sys/sbrk.S index 4aaf07f2fde..3e569319700 100644 --- a/lib/libc/arch/sh/sys/sbrk.S +++ b/lib/libc/arch/sh/sys/sbrk.S @@ -1,4 +1,4 @@ -/* $OpenBSD: sbrk.S,v 1.6 2016/05/30 05:18:52 guenther Exp $ */ +/* $OpenBSD: sbrk.S,v 1.7 2022/09/02 06:19:04 miod Exp $ */ /* $NetBSD: sbrk.S,v 1.9 2006/01/06 03:58:31 uwe Exp $ */ /*- @@ -64,7 +64,11 @@ ENTRY(sbrk) #endif mov.l @r0, r0 add r0, r4 +#if SYS_break >= 128 mov.l LSYS_break, r0 +#else + mov #SYS_break, r0 +#endif trapa #0x80 bf 1f #ifdef __PIC__ @@ -81,7 +85,9 @@ ENTRY(sbrk) SET_ERRNO_AND_RETURN .align 2 +#if SYS_break >= 128 LSYS_break: .long SYS_break +#endif #ifdef __PIC__ L_GOT: .long _GLOBAL_OFFSET_TABLE_ Lcurbrk: .long __curbrk@GOT diff --git a/lib/libc/arch/sh/sys/sigprocmask.S b/lib/libc/arch/sh/sys/sigprocmask.S index 32ff2872b33..74bacc8ae85 100644 --- a/lib/libc/arch/sh/sys/sigprocmask.S +++ b/lib/libc/arch/sh/sys/sigprocmask.S @@ -1,4 +1,4 @@ -/* $OpenBSD: sigprocmask.S,v 1.5 2016/05/18 20:21:13 guenther Exp $ */ +/* $OpenBSD: sigprocmask.S,v 1.6 2022/09/02 06:19:04 miod Exp $ */ /* $NetBSD: sigprocmask.S,v 1.6 2003/08/07 16:42:21 agc Exp $ */ /*- @@ -46,7 +46,12 @@ SYSENTRY_HIDDEN(sigprocmask) nop 1: mov.l @r2, r2 /* fetch indirect ... */ mov r2, r5 /* to new mask arg */ -2: mov.l LSYS_sigprocmask, r0 +2: +#if SYS_sigprocmask >= 128 + mov.l LSYS_sigprocmask, r0 +#else + mov #SYS_sigprocmask, r0 +#endif trapa #0x80 bf 4f mov r6, r2 /* fetch old mask requested */ @@ -61,6 +66,8 @@ SYSENTRY_HIDDEN(sigprocmask) SET_ERRNO_AND_RETURN .align 2 +#if SYS_sigprocmask >= 128 LSYS_sigprocmask: .long SYS_sigprocmask +#endif SYSCALL_END_HIDDEN(sigprocmask) diff --git a/lib/libc/arch/sh/sys/sigsuspend.S b/lib/libc/arch/sh/sys/sigsuspend.S index 1d7927423fc..4e2dffbb7b0 100644 --- a/lib/libc/arch/sh/sys/sigsuspend.S +++ b/lib/libc/arch/sh/sys/sigsuspend.S @@ -1,4 +1,4 @@ -/* $OpenBSD: sigsuspend.S,v 1.4 2016/05/18 20:21:13 guenther Exp $ */ +/* $OpenBSD: sigsuspend.S,v 1.5 2022/09/02 06:19:04 miod Exp $ */ /* $NetBSD: sigsuspend.S,v 1.5 2003/08/07 16:42:21 agc Exp $ */ /*- @@ -41,11 +41,17 @@ SYSENTRY_HIDDEN(sigsuspend) mov r4, r0 /* fetch mask arg */ mov.l @r0, r0 /* indirect to mask arg */ mov r0, r4 +#if SYS_sigsuspend >= 128 mov.l LSYS_sigsuspend, r0 +#else + mov #SYS_sigsuspend, r0 +#endif trapa #0x80 SET_ERRNO_AND_RETURN .align 2 +#if SYS_sigsuspend >= 128 LSYS_sigsuspend: .long SYS_sigsuspend +#endif SYSCALL_END_HIDDEN(sigsuspend) diff --git a/lib/libc/arch/sh/sys/tfork_thread.S b/lib/libc/arch/sh/sys/tfork_thread.S index c37efc94997..6a322fe2b3b 100644 --- a/lib/libc/arch/sh/sys/tfork_thread.S +++ b/lib/libc/arch/sh/sys/tfork_thread.S @@ -1,4 +1,4 @@ -/* $OpenBSD: tfork_thread.S,v 1.3 2016/05/18 20:21:13 guenther Exp $ */ +/* $OpenBSD: tfork_thread.S,v 1.4 2022/09/02 06:19:04 miod Exp $ */ /* * Copyright (c) 2007 Miodrag Vallat. @@ -24,8 +24,12 @@ * r4 r5 r6 r7 */ ENTRY(__tfork_thread) +#if SYS___tfork >= 128 mov.l .LSYS___tfork, r0 - .word 0xc380 /* trapa #0x80 */ +#else + mov #SYS___tfork, r0 +#endif + trapa #0x80 bf 9f tst r0, r0 @@ -44,8 +48,12 @@ ENTRY(__tfork_thread) jsr @r6 mov r7, r4 +#if SYS___threxit >= 128 mov.l .LSYS___threxit, r0 - .word 0xc380 /* trapa #0x80 */ +#else + mov #SYS___threxit, r0 +#endif + trapa #0x80 9: /* @@ -54,7 +62,11 @@ ENTRY(__tfork_thread) SET_ERRNO_AND_RETURN .align 2 +#if SYS___tfork >= 128 .LSYS___tfork: .long SYS___tfork +#endif +#if SYS___threxit >= 128 .LSYS___threxit: .long SYS___threxit +#endif SET_ENTRY_SIZE(__tfork_thread) diff --git a/libexec/ld.so/sh/SYS.h b/libexec/ld.so/sh/SYS.h index 12aecd690f2..f9062bf1b07 100644 --- a/libexec/ld.so/sh/SYS.h +++ b/libexec/ld.so/sh/SYS.h @@ -1,4 +1,4 @@ -/* $OpenBSD: SYS.h,v 1.1 2017/08/27 21:59:52 deraadt Exp $ */ +/* $OpenBSD: SYS.h,v 1.2 2022/09/02 06:19:05 miod Exp $ */ /* * Copyright (c) 2006 Dale Rahn @@ -29,14 +29,30 @@ #include #include -#define SYSTRAP(x) \ - mov.l 903f, r0; \ - .word 0xc380; /* trapa #0x80; */ \ - bra 904f; \ - nop; \ - .align 2; \ - 903: .long (SYS_ ## x); \ +#ifdef __ASSEMBLER__ +/* + * If the system call number fits in a 8-bit signed value (i.e. fits in 7 bits), + * then we can use the #imm8 addressing mode. + */ + +.macro systrap num +.iflt \num - 128 + mov # \num, r0 + trapa #0x80 +.else + mov.l 903f, r0 + trapa #0x80 + bra 904f + nop + .align 2 + 903: .long \num 904: +.endif +.endm +#endif + +#define SYSTRAP(x) \ + systrap SYS_ ## x #define DL_SYSCALL(n) \ .global __CONCAT(_dl_,n) ;\ -- 2.20.1