golang/go

cmd/asm: ARM64 NEON floating point instructions (VFABD VFMAX, VFMAXNM, VFMINNM VFMIN VFADD, VFSUB VFMUL, VFDIV VFMLA, VFMLS VCVT*)

Aperta

#41.092 aperta il 28 ago 2020

 (9 commenti) (0 reazioni) (0 assegnatari)Go (19.008 fork)batch import
NeedsInvestigationcompiler/runtimehelp wanted

Metriche repository

Star
 (133.883 stelle)
Metriche merge PR
 (Nessuna PR mergiata in 30 g)

Descrizione

What version of Go are you using (go version)?

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

What did you do?

Whilst writing some NEON code, I found myself in need of floating point operations in NEON. I was able to load my data to the V* registers (and write it out!), but when I attempted to use VF* instructions, such as VFADD or VFMUL, those opcodes have not been implemented by any intrepid engineer on arm64.

What did you expect to see?

Vectorized floating point addition or multiplication.

What did you see instead?

unrecognized instruction "VFADD"

Test code

neon.go

package fptest
func AddFloat([]float32, []float32, []float32)

neon_test.go

package fptest_test

import (
        "testing"
        fptest "."

        "github.com/stretchr/testify/assert"
)

func TestAddFloat(t *testing.T) {
        dst := make([]float32, 4)
        fptest.AddFloat([]float32{1, 2, 3, 4}, []float32{10, 20, 30, 40}, dst)
        assert.Equal(t, []float32{11, 22, 33, 44}, dst)
}

neon_arm64.s

// func AddFloat(a []int32, b []int32, dst []int32)
TEXT ·AddFloat(SB), $0-72
    // For the sake of simplicity, this only does the first 4.

    // Load a, b and dst's addresses to R8, 9, 10.
    MOVD a+0(FP),    R8
    MOVD b+24(FP),   R9
    MOVD dst+48(FP), R10

    // Load [4]int32 from a, b to v1, v2.
    VLD1 (R8), [V1.S4]
    VLD1 (R9), [V2.S4]

    VFADD V1.S4, V2.S4, V1.S4
    // WORD $0x4e21d441;

    // Write [4]int32 to dst.
    VST1 [V1.S4], (R10)

    RET

Guida contributor