Use a shorter system call invocation template for system calls in the range
authormiod <miod@openbsd.org>
Fri, 2 Sep 2022 06:19:04 +0000 (06:19 +0000)
committermiod <miod@openbsd.org>
Fri, 2 Sep 2022 06:19:04 +0000 (06:19 +0000)
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
lib/libc/arch/sh/sys/brk.S
lib/libc/arch/sh/sys/sbrk.S
lib/libc/arch/sh/sys/sigprocmask.S
lib/libc/arch/sh/sys/sigsuspend.S
lib/libc/arch/sh/sys/tfork_thread.S
libexec/ld.so/sh/SYS.h

index 46bc22a..bed791b 100644 (file)
@@ -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.
 #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);                            \
index 9600546..4b854a3 100644 (file)
@@ -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
index 4aaf07f..3e56931 100644 (file)
@@ -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
index 32ff287..74bacc8 100644 (file)
@@ -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)
index 1d79274..4e2dffb 100644 (file)
@@ -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)
index c37efc9..6a322fe 100644 (file)
@@ -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.
  *                     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)
index 12aecd6..f9062bf 100644 (file)
@@ -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
 #include <machine/asm.h>
 #include <sys/syscall.h>
 
-#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)                ;\