Skip to content

Commit

Permalink
Provide optimized assembly for PPOLL blocking syscall on ARM
Browse files Browse the repository at this point in the history
  • Loading branch information
fako1024 committed Sep 7, 2023
1 parent e02f6c9 commit 8e23f5f
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 6 deletions.
4 changes: 3 additions & 1 deletion event/poll_amd64.s
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
#include "textflag.h"

#define SYS__PPOLL 0x10f

// func pollBlock(fds *unix.PollFd, nfds int) (err syscall.Errno)
TEXT ·pollBlock(SB),NOSPLIT,$0-24
CALL runtime·entersyscallblock(SB) // Call blocking SYSCALL directive from runtime package
MOVQ fds+0(FP), DI // PollFDs parameter
MOVQ nfds+8(FP), SI // Put nFDs parameter
MOVQ $0x0, DX // Put timeout parameter (set to NULL)
MOVQ $0x0, R10 // Put sigmask parameter (skip)
MOVQ $0x10f, AX // Prepare / perform ppoll() SYSCALL
MOVQ $SYS__PPOLL, AX // Prepare / perform ppoll() SYSCALL
SYSCALL
CMPQ AX, $0xfffffffffffff002 // No error / EINTR
JLS success // Jump to success
Expand Down
24 changes: 24 additions & 0 deletions event/poll_arm.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include "textflag.h"

#define SYS__PPOLL 0x150

// func pollBlock(fds *unix.PollFd, nfds int) (err syscall.Errno)
TEXT ·pollBlock(SB),NOSPLIT,$0-12
BL runtime·entersyscallblock(SB) // Call blocking SYSCALL directive from runtime package
MOVW $SYS__PPOLL, R7 // Prepare / perform ppoll() SYSCALL
MOVW fds+0(FP), R0 // PollFDs parameter
MOVW nfds+4(FP), R1 // Put nFDs parameter
MOVW $0x0, R2 // Put timeout parameter (set to NULL)
MOVW $0x0, R3 // Put sigmask parameter (skip)
SWI $0
CMP $0xfffff002, R0 // No error / EINTR
BLS success // Jump to success
RSB $0, R0, R0 // Negate SYSCALL errno
MOVW R0, err+8(FP) // Store error code in err return value
BL runtime·exitsyscall(SB) // Finalize SYSCALL using the directive from runtime package
RET // Return
success:
MOVW $0, R0
MOVW R0, err+8(FP) // Store NULL error code in err return value
BL runtime·exitsyscall(SB) // Finalize SYSCALL using the directive from runtime package
RET // Return
4 changes: 3 additions & 1 deletion event/poll_arm64.s
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
#include "textflag.h"

#define SYS__PPOLL 0x49

// func pollBlock(fds *unix.PollFd, nfds int) (err syscall.Errno)
TEXT ·pollBlock(SB),NOSPLIT,$0-24
BL runtime·entersyscallblock(SB) // Call blocking SYSCALL directive from runtime package
MOVD fds+0(FP), R0 // PollFDs parameter
MOVD nfds+8(FP), R1 // Put nFDs parameter
MOVD $0x0, R2 // Put timeout parameter (set to NULL)
MOVD $0x0, R3 // Put sigmask parameter (skip)
MOVD $0x49, R8 // Prepare / perform ppoll() SYSCALL
MOVD $SYS__PPOLL, R8 // Prepare / perform ppoll() SYSCALL
SVC
CMP $0xfffffffffffff002, R0 // No error / EINTR
BLS success // Jump to success
Expand Down
4 changes: 2 additions & 2 deletions event/poll_asm.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:build (linux && amd64) || (linux && arm64)
// +build linux,amd64 linux,arm64
//go:build (linux && amd64) || (linux && arm64) || (linux && arm)
// +build linux,amd64 linux,arm64 linux,arm

package event

Expand Down
4 changes: 2 additions & 2 deletions event/poll_default.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:build linux && !amd64 && !arm64
// +build linux,!amd64,!arm64
//go:build linux && !amd64 && !arm64 && !arm
// +build linux,!amd64,!arm64,!arm

package event

Expand Down

0 comments on commit 8e23f5f

Please sign in to comment.