问题描述

_mm_add_epi32
_mm_add_epi32

以下是等效的较慢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[]byteYMM
paddq xmm, xmm[]byteYMM

推荐答案

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

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)
(FP)

除此之外,它非常简单.该语法类似于(但不等于)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屋!