Source file src/cmd/compile/internal/ssagen/simdequal.go

     1  // Copyright 2026 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package ssagen
     6  
     7  import (
     8  	"cmd/compile/internal/base"
     9  	"cmd/compile/internal/ssa/ssaop"
    10  	"cmd/compile/internal/types"
    11  )
    12  
    13  // simdEqualOp returns the generic op that implements == on values of SIMD
    14  // vector or mask type t. == compares SIMD values as if they were structs with
    15  // one field per element, or one bool per element for masks.
    16  func simdEqualOp(t *types.Type) ssaop.Op {
    17  	shape, ok := t.SIMDShape()
    18  	if !ok {
    19  		base.Fatalf("== on non-SIMD type %v", t)
    20  	}
    21  	if shape.Scalable {
    22  		// SVE types aren't comparable yet.
    23  		base.Fatalf("== on SVE type %v", t)
    24  	}
    25  
    26  	// Integer vectors compare bitwise. Fixed-width masks are simply vectors
    27  	// whose elements are 0 or -1, so they also compare bitwise. Float vectors
    28  	// need to compare the individual elements. Hence, the op depends only on
    29  	// whether the elements are floats, and on the vector width.
    30  	elem := shape.Elem.Kind()
    31  	switch t.Size() {
    32  	case 16:
    33  		switch elem {
    34  		case types.TFLOAT32:
    35  			return ssaop.OpEqualVecFloat32x4
    36  		case types.TFLOAT64:
    37  			return ssaop.OpEqualVecFloat64x2
    38  		}
    39  		return ssaop.OpEqualVec128
    40  	case 32:
    41  		switch elem {
    42  		case types.TFLOAT32:
    43  			return ssaop.OpEqualVecFloat32x8
    44  		case types.TFLOAT64:
    45  			return ssaop.OpEqualVecFloat64x4
    46  		}
    47  		return ssaop.OpEqualVec256
    48  	case 64:
    49  		switch elem {
    50  		case types.TFLOAT32:
    51  			return ssaop.OpEqualVecFloat32x16
    52  		case types.TFLOAT64:
    53  			return ssaop.OpEqualVecFloat64x8
    54  		}
    55  		return ssaop.OpEqualVec512
    56  	}
    57  	base.Fatalf("== on SIMD type %v of unexpected size %d", t, t.Size())
    58  	panic("unreachable")
    59  }
    60  

View as plain text