Skip to content

Instantly share code, notes, and snippets.

@aclements

aclements/reg.s Secret

Created July 25, 2020 20:56
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save aclements/ded22bb8451eead8249d22d3cd873566 to your computer and use it in GitHub Desktop.
Save aclements/ded22bb8451eead8249d22d3cd873566 to your computer and use it in GitHub Desktop.
Microbenchmark of stack- and register-based calling convention
// Copyright 2020 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
#include "textflag.h"
TEXT ·stack(SB),NOSPLIT,$16-4
MOVD n+0(FP), CX
loop:
MOVQ CX, 0(SP)
CALL stackSub1<>(SB)
MOVQ 8(SP), CX
TESTQ CX, CX
JHI loop
RET
TEXT stackSub1<>(SB),NOSPLIT,$0-16
MOVQ x+0(FP), AX
DECQ AX
MOVQ AX, ret+8(FP)
RET
TEXT ·reg(SB),NOSPLIT,$0-4
MOVD n+0(FP), AX
loop:
CALL regSub1<>(SB)
TESTQ AX, AX
JHI loop
RET
TEXT regSub1<>(SB),NOSPLIT,$0-0
DECQ AX
RET
// Copyright 2020 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package stackreg
import "testing"
func BenchmarkStack(b *testing.B) {
stack(uint32(b.N))
}
func stack(n uint32)
func BenchmarkReg(b *testing.B) {
reg(uint32(b.N))
}
func reg(n uint32)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment