Source file test/codegen/wasmextensions.go

     1  // asmcheck -gcflags=-d=ssa/check/on
     2  
     3  // Copyright 2026 The Go Authors. All rights reserved.
     4  // Use of this source code is governed by a BSD-style
     5  // license that can be found in the LICENSE file.
     6  
     7  package codegen
     8  
     9  // Shuffle SSA values to cover extensions lowered before their loads.
    10  
    11  func wasmSignExtendArgs(x int8, y int16, z int32) (int64, int64, int64) {
    12  	// wasm:`I64Load8S` `I64Load16S` `I64Load32S` -`I64Extend(8|16|32)S`
    13  	return int64(x), int64(y), int64(z)
    14  }
    15  
    16  func wasmSignExtendLoads(x *int8, y *int16, z *int32) (int64, int64, int64) {
    17  	// wasm:`I64Load8S` `I64Load16S` `I64Load32S` -`I64Extend(8|16|32)S`
    18  	return int64(*x), int64(*y), int64(*z)
    19  }
    20  
    21  func wasmZeroExtendLoads(x *uint8, y *uint16, z *uint32) (uint64, uint64, uint64) {
    22  	// wasm:`I64Load8U` `I64Load16U` `I64Load32U` -`I64And`
    23  	return uint64(*x), uint64(*y), uint64(*z)
    24  }
    25  
    26  // Unsigned arguments still need sign extension after conversion to a signed type.
    27  func wasmSignExtendUnsignedArgs(x uint8, y uint16, z uint32) (int64, int64, int64) {
    28  	// wasm:`I64Load8U` `I64Load16U` `I64Load32U` `I64Extend8S` `I64Extend16S` `I64Extend32S`
    29  	return int64(int8(x)), int64(int16(y)), int64(int32(z))
    30  }
    31  
    32  // Narrowing a signed value changes which bit must be extended.
    33  func wasmSignExtendNarrowedArg(x int32) (int64, int64) {
    34  	// wasm:`I64Load32S` `I64Extend8S` `I64Extend16S`
    35  	return int64(int8(x)), int64(int16(x))
    36  }
    37  
    38  func wasmSignExtendNarrowedLoad(x *int32) (int64, int64) {
    39  	// wasm:`I64Load32S` `I64Extend8S` `I64Extend16S`
    40  	return int64(int8(*x)), int64(int16(*x))
    41  }
    42  

View as plain text