Source file src/simd/testdata/timport/main1/main.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 // main1 validates transitive SIMD rewriting across a package chain where 6 // neither main1 nor relay directly imports "simd": 7 // - main imports relay. 8 // - relay imports isimd and exports V = isimd.F() plus non-SIMD relayed vars. 9 // - isimd imports simd, exports F() returning unexported type t (embedding 10 // simd.Int8s), and initializes a non-SIMD dependency chain a -> b -> c -> d. 11 package main 12 13 import ( 14 "fmt" 15 "os" 16 "timport/relay" 17 ) 18 19 // checkTransitiveEmbeddedSimdVar validates that calling a promoted SIMD method 20 // on relay.V (whose unexported type embeds simd.Int8s from timport/isimd) 21 // triggers midway rewriting in both relay and main1 and matches isimd.G(). 22 func checkTransitiveEmbeddedSimdVar() { 23 relayDotVdotReduceSum := relay.V.ReduceSum() 24 fmt.Printf("relay.V.ReduceSum()=%d\n", relayDotVdotReduceSum) 25 if relayDotVdotReduceSum != int8(relay.VdotReduceSum) { 26 fmt.Printf("FAIL, %d != %d\n", relayDotVdotReduceSum, relay.VdotReduceSum) 27 os.Exit(1) 28 } 29 } 30 31 // checkRelayedInitChain validates that relay.PTwoP1 (derived in isimd via 32 // a -> b (SIMD) -> c -> d = 4*Int32s.Len()+1) initialized in dependency order. 33 func checkRelayedInitChain() { 34 fmt.Printf("relay.PTwoP1=%d\n", relay.PTwoP1) 35 if relay.PTwoP1&1 != 1 || relay.PTwoP1 < 17 { 36 fmt.Printf("FAIL, expected relay.PTwoP1 = 2**N+1, got %d\n", relay.PTwoP1) 37 os.Exit(1) 38 } 39 } 40 41 func main() { 42 checkTransitiveEmbeddedSimdVar() 43 checkRelayedInitChain() 44 } 45