Source file src/simd/sizeof_test.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  //go:build goexperiment.simd
     6  
     7  package simd_test
     8  
     9  import (
    10  	"simd"
    11  	"simd/testdata"
    12  	"testing"
    13  	"unsafe"
    14  )
    15  
    16  var v simd.Float32s
    17  
    18  func TestSizeof(t *testing.T) {
    19  	var f float32
    20  	sv0 := int(unsafe.Sizeof(v))
    21  	sv1 := v.Len() * int(unsafe.Sizeof(f))
    22  	sV := int(unsafe.Sizeof(testdata.V))
    23  	sF := int(unsafe.Sizeof(testdata.F()))
    24  	if sv0 != sv1 {
    25  		t.Errorf("sv0=%d and sv1=%d should be equal but are not", sv0, sv1)
    26  	}
    27  	if sF != sv1 {
    28  		t.Errorf("sF=%d and sv1=%d should be equal but are not", sF, sv1)
    29  	}
    30  	if sV != sv1 {
    31  		t.Errorf("sV=%d and sv1=%d should be equal but are not", sV, sv1)
    32  	}
    33  }
    34  

View as plain text