dongzhuo8210 2014-09-22 03:40
浏览 32
已采纳

如何在汇编中的结构指针上定义函数?

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.

  • 写回答

1条回答 默认 最新

  • douwen5951 2014-09-22 08:43
    关注

    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 (i.e. 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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置