How to define a function on a struct pointer in assembly?
For example:
// dummy.go
type dummy struct {
p uintptr
}
func (d dummy) Get(i int) uint64
//func (d *dummy) Get(i int) uint64 //no way to define *dummy in assembly
func (d dummy) Get
can be defined as:
// dummy_amd64.s
#include "textflag.h"
TEXT ·dummy·Get(SB),NOSPLIT,$0
MOVQ $42, 24(SP)
RET
I tried
TEXT "".(*dummy).Get+0(SB),4,$0-24 //output from 6g -S
TEXT ""·(*dummy)·Get+0(SB),4,$0
TEXT ·*dummy·Get(SB),NOSPLIT,$0
//and
TEXT ·(*dummy)·Get(SB),NOSPLIT,$0
All of them gives me the same error:
syntax error, last name: "".
I'm sure I'm missing something obvious but I can't seem to figure it out.
This is actually not possible with the current toolchain. The context is explained in issue 4978
Note that there is a simple patch to enable this feature - but only a few people are using it.
You could write a normal assembly function (ie not method), and implement a call in the Go method, to this assembly function. But the extra call will not be optimized away by the compiler.
A possible workaround to this problem would be to implement some support to allow assembly functions to be inlined in Go code - which would bring more benefits. My understanding is it has been discussed in the past, but it is not planned yet.
链接地址: http://www.djcxy.com/p/22948.html上一篇: HttpURLConnection:创建多个连接时发生BindException
下一篇: 如何在程序集中的结构指针上定义一个函数?