_mm_add_epi32的Golang汇编工具 [英] Golang assembly implement of _mm_add_epi32

查看:95
本文介绍了_mm_add_epi32的Golang汇编工具的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在golang汇编中实现_mm_add_epi32,可以选择在 avo 的帮助下进行.但是我对汇编知之甚少,甚至不知道如何启动它.您能给我一些代码提示吗?谢谢大家.

I'm trying to implement _mm_add_epi32 in golang assembly, optionally with help of avo. But I know little about assembly and do not even know how to start it. Can you give me some hint of code? Thank you all.

以下是等效的较慢golang版本:

Here's the equivalent slower golang version:

func add(x, y []uint32) []uint32 {
    if len(x) != len(y) {
        return nil
    }

    result := make([]uint32, len(x))
    for i := 0; i < len(x); i++ {
        result[i] = x[i] + y[i]
    }
    return result
}

我知道指令paddq xmm, xmm是我们所需要的,但是不知道如何将[]byte的切片转换为256位寄存器YMM.

I know that the struction paddq xmm, xmm is what we need, but do not kown how to convert a slice of []byte to the 256 bit register YMM.

推荐答案

以下是此类附加功能的示例:

Here's an example for such an addition function:

    // func add(x, y [8]int32) [8]int32
    // q = x + y
TEXT ·add(SB),0,$0
    VMOVDQU x+0(FP), Y0
    VPADDD  Y+32(FP), Y0, Y0
    VMOVDQU Y0, q+64(FP)
    VZEROUPPER
    RET

在阅读此代码之前,请熟悉本文档.不幸的是,Go风格的程序集(又称Plan 9风格的程序集)的文档很少.

Before reading this code, familiarise yourself with this document. Unfortunately, Go-style assembly (aka Plan 9-style assembly) is poorly documented.

数组按值传递到堆栈上.返回值作为调用方回读的最右边的参数传递.使用我链接到访问函数参数的文档中记录的(FP).

Arrays are passed on the stack by value. A return value is passed as an extra rightmost argument read back by the caller. Use (FP) as documented in the document I linked to access function arguments.

除此之外,它非常简单.该语法类似于(但不等于)AT& T语法.请注意,寄存器名称不同,并且必须提供大小后缀.

Apart from that, it's pretty straightforward. The syntax is similar (but not equal) to AT&T syntax. Note that the register names are different and giving a size suffix is mandatory.

如您所见,为单个操作编写汇编函数是毫无意义的.采用所需的算法并将其完全组装成汇编,可能会做得更好.

As you can see, writing an assembly function for a single operation is pretty pointless. It's probably going to work a lot better to take the algorithm you need and write it completely in assembly.

这篇关于_mm_add_epi32的Golang汇编工具的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆