Source file test/abi/leaf2.go

     1  // run
     2  
     3  //go:build !wasm
     4  // +build !wasm
     5  
     6  // Copyright 2021 The Go Authors. All rights reserved.
     7  // Use of this source code is governed by a BSD-style
     8  // license that can be found in the LICENSE file.
     9  
    10  // wasm is excluded because the compiler chatter about register abi pragma ends up
    11  // on stdout, and causes the expected output to not match.
    12  
    13  package main
    14  
    15  import "fmt"
    16  
    17  type i4 struct {
    18  	a, b, c, d int
    19  }
    20  
    21  //go:registerparams
    22  //go:noinline
    23  func F(x i4) i4 {
    24  	ab := x.a + x.b
    25  	bc := x.b + x.c
    26  	cd := x.c + x.d
    27  	ad := x.a + x.d
    28  	ba := x.a - x.b
    29  	cb := x.b - x.c
    30  	dc := x.c - x.d
    31  	da := x.a - x.d
    32  
    33  	return i4{ab*bc + da, cd*ad + cb, ba*cb + ad, dc*da + bc}
    34  }
    35  
    36  func main() {
    37  	x := i4{1, 2, 3, 4}
    38  	y := x
    39  	z := F(x)
    40  	if (i4{12, 34, 6, 8}) != z {
    41  		fmt.Printf("y=%v, z=%v\n", y, z)
    42  	}
    43  }
    44  

View as plain text