Source file test/codegen/memcombine.go

     1  // asmcheck
     2  
     3  // Copyright 2018 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  import (
    10  	"encoding/binary"
    11  	"runtime"
    12  )
    13  
    14  // ------------- //
    15  //    Loading    //
    16  // ------------- //
    17  
    18  func load_le64(b []byte) uint64 {
    19  	// amd64:`MOVQ\s\(.*\),`,-`MOV[BWL]\t[^$]`,-`OR`
    20  	// s390x:`MOVDBR\s\(.*\),`
    21  	// arm64:`MOVD\s\(R[0-9]+\),`,-`MOV[BHW]`
    22  	// loong64:`MOVBU\s\(R[0-9]+\),`
    23  	// ppc64le:`MOVD\s`,-`MOV[BHW]Z`
    24  	// ppc64:`MOVDBR\s`,-`MOV[BHW]Z`
    25  	return binary.LittleEndian.Uint64(b)
    26  }
    27  
    28  func load_le64_idx(b []byte, idx int) uint64 {
    29  	// amd64:`MOVQ\s\(.*\)\(.*\*1\),`,-`MOV[BWL]\t[^$]`,-`OR`
    30  	// s390x:`MOVDBR\s\(.*\)\(.*\*1\),`
    31  	// arm64:`MOVD\s\(R[0-9]+\)\(R[0-9]+\),`,-`MOV[BHW]`
    32  	// loong64:`MOVBU\s\(R[0-9]+\)\(R[0-9]+\),`
    33  	// ppc64le:`MOVD\s`,-`MOV[BHW]Z\s`
    34  	// ppc64:`MOVDBR\s`,-`MOV[BHW]Z\s`
    35  	return binary.LittleEndian.Uint64(b[idx:])
    36  }
    37  
    38  func load_le32(b []byte) uint32 {
    39  	// amd64:`MOVL\s\(.*\),`,-`MOV[BW]`,-`OR`
    40  	// 386:`MOVL\s\(.*\),`,-`MOV[BW]`,-`OR`
    41  	// s390x:`MOVWBR\s\(.*\),`
    42  	// arm64:`MOVWU\s\(R[0-9]+\),`,-`MOV[BH]`
    43  	// loong64:`MOVBU\s\(R[0-9]+\),`
    44  	// ppc64le:`MOVWZ\s`,-`MOV[BH]Z\s`
    45  	// ppc64:`MOVWBR\s`,-`MOV[BH]Z\s`
    46  	return binary.LittleEndian.Uint32(b)
    47  }
    48  
    49  func load_le32_idx(b []byte, idx int) uint32 {
    50  	// amd64:`MOVL\s\(.*\)\(.*\*1\),`,-`MOV[BW]`,-`OR`
    51  	// 386:`MOVL\s\(.*\)\(.*\*1\),`,-`MOV[BW]`,-`OR`
    52  	// s390x:`MOVWBR\s\(.*\)\(.*\*1\),`
    53  	// arm64:`MOVWU\s\(R[0-9]+\)\(R[0-9]+\),`,-`MOV[BH]`
    54  	// loong64:`MOVBU\s\(R[0-9]+\)\(R[0-9]+\),`
    55  	// ppc64le:`MOVWZ\s`,-`MOV[BH]Z\s`
    56  	// ppc64:`MOVWBR\s`,-`MOV[BH]Z\s'
    57  	return binary.LittleEndian.Uint32(b[idx:])
    58  }
    59  
    60  func load_le16(b []byte) uint16 {
    61  	// amd64:`MOVWLZX\s\(.*\),`,-`MOVB`,-`OR`
    62  	// ppc64le:`MOVHZ\s`,-`MOVBZ`
    63  	// arm64:`MOVHU\s\(R[0-9]+\),`,-`MOVB`
    64  	// loong64:`MOVBU\s\(R[0-9]+\),`
    65  	// s390x:`MOVHBR\s\(.*\),`
    66  	// ppc64:`MOVHBR\s`,-`MOVBZ`
    67  	return binary.LittleEndian.Uint16(b)
    68  }
    69  
    70  func load_le16_idx(b []byte, idx int) uint16 {
    71  	// amd64:`MOVWLZX\s\(.*\),`,-`MOVB`,-`OR`
    72  	// ppc64le:`MOVHZ\s`,-`MOVBZ`
    73  	// ppc64:`MOVHBR\s`,-`MOVBZ`
    74  	// arm64:`MOVHU\s\(R[0-9]+\)\(R[0-9]+\),`,-`MOVB`
    75  	// loong64:`MOVBU\s\(R[0-9]+\)\(R[0-9]+\),`
    76  	// s390x:`MOVHBR\s\(.*\)\(.*\*1\),`
    77  	return binary.LittleEndian.Uint16(b[idx:])
    78  }
    79  
    80  func load_be64(b []byte) uint64 {
    81  	// amd64/v1,amd64/v2:`BSWAPQ`,-`MOV[BWL]\t[^$]`,-`OR`
    82  	// amd64/v3:`MOVBEQ`
    83  	// s390x:`MOVD\s\(.*\),`
    84  	// arm64:`REV`,`MOVD\s\(R[0-9]+\),`,-`MOV[BHW]`,-`REVW`,-`REV16W`
    85  	// ppc64le:`MOVDBR`,-`MOV[BHW]Z`
    86  	// ppc64:`MOVD`,-`MOV[BHW]Z`
    87  	return binary.BigEndian.Uint64(b)
    88  }
    89  
    90  func load_be64_idx(b []byte, idx int) uint64 {
    91  	// amd64/v1,amd64/v2:`BSWAPQ`,-`MOV[BWL]\t[^$]`,-`OR`
    92  	// amd64/v3: `MOVBEQ\t\([A-Z]+[0-9]*\)\([A-Z]+[0-9]*\*1\), [A-Z]+[0-9]*`
    93  	// s390x:`MOVD\s\(.*\)\(.*\*1\),`
    94  	// arm64:`REV`,`MOVD\s\(R[0-9]+\)\(R[0-9]+\),`,-`MOV[WHB]`,-`REVW`,-`REV16W`
    95  	// ppc64le:`MOVDBR`,-`MOV[BHW]Z`
    96  	// ppc64:`MOVD`,-`MOV[BHW]Z`
    97  	return binary.BigEndian.Uint64(b[idx:])
    98  }
    99  
   100  func load_be32(b []byte) uint32 {
   101  	// amd64/v1,amd64/v2:`BSWAPL`,-`MOV[BW]`,-`OR`
   102  	// amd64/v3: `MOVBEL`
   103  	// s390x:`MOVWZ\s\(.*\),`
   104  	// arm64:`REVW`,`MOVWU\s\(R[0-9]+\),`,-`MOV[BH]`,-`REV16W`
   105  	// ppc64le:`MOVWBR`,-`MOV[BH]Z`
   106  	// ppc64:`MOVWZ`,-MOV[BH]Z`
   107  	return binary.BigEndian.Uint32(b)
   108  }
   109  
   110  func load_be32_idx(b []byte, idx int) uint32 {
   111  	// amd64/v1,amd64/v2:`BSWAPL`,-`MOV[BW]`,-`OR`
   112  	// amd64/v3: `MOVBEL\t\([A-Z]+[0-9]*\)\([A-Z]+[0-9]*\*1\), [A-Z]+[0-9]*`
   113  	// s390x:`MOVWZ\s\(.*\)\(.*\*1\),`
   114  	// arm64:`REVW`,`MOVWU\s\(R[0-9]+\)\(R[0-9]+\),`,-`MOV[HB]`,-`REV16W`
   115  	// ppc64le:`MOVWBR`,-`MOV[BH]Z`
   116  	// ppc64:`MOVWZ`,-MOV[BH]Z`
   117  	return binary.BigEndian.Uint32(b[idx:])
   118  }
   119  
   120  func load_be16(b []byte) uint16 {
   121  	// amd64:`ROLW\s\$8`,-`MOVB`,-`OR`
   122  	// arm64:`REV16W`,`MOVHU\s\(R[0-9]+\),`,-`MOVB`
   123  	// ppc64le:`MOVHBR`,-`MOVBZ`
   124  	// ppc64:`MOVHZ`,-`MOVBZ`
   125  	// s390x:`MOVHZ\s\(.*\),`,-`OR`,-`ORW`,-`SLD`,-`SLW`
   126  	return binary.BigEndian.Uint16(b)
   127  }
   128  
   129  func load_be16_idx(b []byte, idx int) uint16 {
   130  	// amd64:`ROLW\s\$8`,-`MOVB`,-`OR`
   131  	// arm64:`REV16W`,`MOVHU\s\(R[0-9]+\)\(R[0-9]+\),`,-`MOVB`
   132  	// ppc64le:`MOVHBR`,-`MOVBZ`
   133  	// ppc64:`MOVHZ`,-`MOVBZ`
   134  	// s390x:`MOVHZ\s\(.*\)\(.*\*1\),`,-`OR`,-`ORW`,-`SLD`,-`SLW`
   135  	return binary.BigEndian.Uint16(b[idx:])
   136  }
   137  
   138  func load_le_byte2_uint16(s []byte) uint16 {
   139  	// arm64:`MOVHU\t\(R[0-9]+\)`,-`ORR`,-`MOVB`
   140  	// 386:`MOVWLZX\s\([A-Z]+\)`,-`MOVB`,-`OR`
   141  	// amd64:`MOVWLZX\s\([A-Z]+\)`,-`MOVB`,-`OR`
   142  	// ppc64le:`MOVHZ\t\(R[0-9]+\)`,-`MOVBZ`
   143  	// ppc64:`MOVHBR`,-`MOVBZ`
   144  	return uint16(s[0]) | uint16(s[1])<<8
   145  }
   146  
   147  func load_le_byte2_uint16_inv(s []byte) uint16 {
   148  	// arm64:`MOVHU\t\(R[0-9]+\)`,-`ORR`,-`MOVB`
   149  	// 386:`MOVWLZX\s\([A-Z]+\)`,-`MOVB`,-`OR`
   150  	// amd64:`MOVWLZX\s\([A-Z]+\)`,-`MOVB`,-`OR`
   151  	// ppc64le:`MOVHZ\t\(R[0-9]+\)`,-`MOVBZ`
   152  	// ppc64:`MOVHBR`,-`MOVBZ`
   153  	return uint16(s[1])<<8 | uint16(s[0])
   154  }
   155  
   156  func load_le_byte4_uint32(s []byte) uint32 {
   157  	// arm64:`MOVWU\t\(R[0-9]+\)`,-`ORR`,-`MOV[BH]`
   158  	// 386:`MOVL\s\([A-Z]+\)`,-`MOV[BW]`,-`OR`
   159  	// amd64:`MOVL\s\([A-Z]+\)`,-`MOV[BW]`,-`OR`
   160  	// ppc64le:`MOVWZ\t\(R[0-9]+\)`,-`MOV[BH]Z`
   161  	// ppc64:`MOVWBR`,-MOV[BH]Z`
   162  	return uint32(s[0]) | uint32(s[1])<<8 | uint32(s[2])<<16 | uint32(s[3])<<24
   163  }
   164  
   165  func load_le_byte4_uint32_inv(s []byte) uint32 {
   166  	// arm64:`MOVWU\t\(R[0-9]+\)`,-`ORR`,-`MOV[BH]`
   167  	// ppc64le:`MOVWZ`,-`MOV[BH]Z`
   168  	// ppc64:`MOVWBR`,-`MOV[BH]Z`
   169  	return uint32(s[3])<<24 | uint32(s[2])<<16 | uint32(s[1])<<8 | uint32(s[0])
   170  }
   171  
   172  func load_le_byte8_uint64(s []byte) uint64 {
   173  	// arm64:`MOVD\t\(R[0-9]+\)`,-`ORR`,-`MOV[BHW]`
   174  	// amd64:`MOVQ\s\([A-Z]+\),\s[A-Z]+`,-`MOV[BWL]\t[^$]`,-`OR`
   175  	// ppc64le:`MOVD\t\(R[0-9]+\)`,-`MOV[BHW]Z`
   176  	// ppc64:`MOVDBR`,-`MOVW[WHB]Z`
   177  	return uint64(s[0]) | uint64(s[1])<<8 | uint64(s[2])<<16 | uint64(s[3])<<24 | uint64(s[4])<<32 | uint64(s[5])<<40 | uint64(s[6])<<48 | uint64(s[7])<<56
   178  }
   179  
   180  func load_le_byte8_uint64_inv(s []byte) uint64 {
   181  	// arm64:`MOVD\t\(R[0-9]+\)`,-`ORR`,-`MOV[BHW]`
   182  	// ppc64le:`MOVD`,-`MOV[WHB]Z`
   183  	// ppc64:`MOVDBR`,-`MOV[WHB]Z`
   184  	return uint64(s[7])<<56 | uint64(s[6])<<48 | uint64(s[5])<<40 | uint64(s[4])<<32 | uint64(s[3])<<24 | uint64(s[2])<<16 | uint64(s[1])<<8 | uint64(s[0])
   185  }
   186  
   187  func load_be_byte2_uint16(s []byte) uint16 {
   188  	// arm64:`MOVHU\t\(R[0-9]+\)`,`REV16W`,-`ORR`,-`MOVB`
   189  	// amd64:`MOVWLZX\s\([A-Z]+\)`,`ROLW`,-`MOVB`,-`OR`
   190  	// ppc64le:`MOVHBR\t\(R[0-9]+\)`,-`MOVBZ`
   191  	// ppc64:`MOVHZ`,-`MOVBZ`
   192  	return uint16(s[0])<<8 | uint16(s[1])
   193  }
   194  
   195  func load_be_byte2_uint16_inv(s []byte) uint16 {
   196  	// arm64:`MOVHU\t\(R[0-9]+\)`,`REV16W`,-`ORR`,-`MOVB`
   197  	// amd64:`MOVWLZX\s\([A-Z]+\)`,`ROLW`,-`MOVB`,-`OR`
   198  	// ppc64le:`MOVHBR\t\(R[0-9]+\)`,-`MOVBZ`
   199  	// ppc64:`MOVHZ`,-`MOVBZ`
   200  	return uint16(s[1]) | uint16(s[0])<<8
   201  }
   202  
   203  func load_be_byte4_uint32(s []byte) uint32 {
   204  	// arm64:`MOVWU\t\(R[0-9]+\)`,`REVW`,-`ORR`,-`REV16W`,-`MOV[BH]`
   205  	// ppc64le:`MOVWBR`,-`MOV[HB]Z`
   206  	// ppc64:`MOVWZ`,-`MOV[HB]Z`
   207  	return uint32(s[0])<<24 | uint32(s[1])<<16 | uint32(s[2])<<8 | uint32(s[3])
   208  }
   209  
   210  func load_be_byte4_uint32_inv(s []byte) uint32 {
   211  	// arm64:`MOVWU\t\(R[0-9]+\)`,`REVW`,-`ORR`,-`REV16W`,-`MOV[BH]`
   212  	// amd64/v1,amd64/v2:`MOVL\s\([A-Z]+\)`,`BSWAPL`,-`MOV[BW]`,-`OR`
   213  	// amd64/v3: `MOVBEL`
   214  	// ppc64le:`MOVWBR`,-`MOV[HB]Z`
   215  	// ppc64:`MOVWZ`,-`MOV[HB]Z`
   216  	return uint32(s[3]) | uint32(s[2])<<8 | uint32(s[1])<<16 | uint32(s[0])<<24
   217  }
   218  
   219  func load_be_byte8_uint64(s []byte) uint64 {
   220  	// arm64:`MOVD\t\(R[0-9]+\)`,`REV`,-`ORR`,-`REVW`,-`REV16W`,-`MOV[BHW]`
   221  	// ppc64le:`MOVDBR\t\(R[0-9]+\)`,-`MOV[BHW]Z`
   222  	// ppc64:`MOVD`,-`MOV[WHB]Z`
   223  	return uint64(s[0])<<56 | uint64(s[1])<<48 | uint64(s[2])<<40 | uint64(s[3])<<32 | uint64(s[4])<<24 | uint64(s[5])<<16 | uint64(s[6])<<8 | uint64(s[7])
   224  }
   225  
   226  func load_be_byte8_uint64_inv(s []byte) uint64 {
   227  	// arm64:`MOVD\t\(R[0-9]+\)`,`REV`,-`ORR`,-`REVW`,-`REV16W`,-`MOV[BHW]`
   228  	// amd64/v1,amd64/v2:`MOVQ\s\([A-Z]+\),\s[A-Z]+`,`BSWAPQ`,-`MOV[BWL]\t[^$]`,-`OR`
   229  	// amd64/v3: `MOVBEQ`
   230  	// ppc64le:`MOVDBR\t\(R[0-9]+\)`,-`MOV[BHW]Z`
   231  	// ppc64:`MOVD`,-`MOV[BHW]Z`
   232  	return uint64(s[7]) | uint64(s[6])<<8 | uint64(s[5])<<16 | uint64(s[4])<<24 | uint64(s[3])<<32 | uint64(s[2])<<40 | uint64(s[1])<<48 | uint64(s[0])<<56
   233  }
   234  
   235  func load_le_byte2_uint16_idx(s []byte, idx int) uint16 {
   236  	// arm64:`MOVHU\s\(R[0-9]+\)\(R[0-9]+\)`,-`ORR`,-`MOVB`
   237  	// 386:`MOVWLZX\s\([A-Z]+\)\([A-Z]+`,-`ORL`,-`MOVB`
   238  	// amd64:`MOVWLZX\s\([A-Z]+\)\([A-Z]+`,-`MOVB`,-`OR`
   239  	// ppc64le:`MOVHZ`,-`MOVBZ`
   240  	// ppc64:`MOVHBR`,-`MOVBZ`
   241  	return uint16(s[idx]) | uint16(s[idx+1])<<8
   242  }
   243  
   244  func load_le_byte2_uint16_idx_inv(s []byte, idx int) uint16 {
   245  	// arm64:`MOVHU\s\(R[0-9]+\)\(R[0-9]+\)`,-`ORR`,-`MOVB`
   246  	// 386:`MOVWLZX\s\([A-Z]+\)\([A-Z]+`,-`ORL`,-`MOVB`
   247  	// amd64:`MOVWLZX\s\([A-Z]+\)\([A-Z]+`,-`MOVB`,-`OR`
   248  	// ppc64le:`MOVHZ`,-`MOVBZ`
   249  	// ppc64:`MOVHBR`,-`MOVBZ`
   250  	return uint16(s[idx+1])<<8 | uint16(s[idx])
   251  }
   252  
   253  func load_le_byte4_uint32_idx(s []byte, idx int) uint32 {
   254  	// arm64:`MOVWU\s\(R[0-9]+\)\(R[0-9]+\)`,-`ORR`,-`MOV[BH]`
   255  	// amd64:`MOVL\s\([A-Z]+\)\([A-Z]+`,-`MOV[BW]`,-`OR`
   256  	return uint32(s[idx]) | uint32(s[idx+1])<<8 | uint32(s[idx+2])<<16 | uint32(s[idx+3])<<24
   257  }
   258  
   259  func load_le_byte4_uint32_idx_inv(s []byte, idx int) uint32 {
   260  	// arm64:`MOVWU\s\(R[0-9]+\)\(R[0-9]+\)`,-`ORR`,-`MOV[BH]`
   261  	return uint32(s[idx+3])<<24 | uint32(s[idx+2])<<16 | uint32(s[idx+1])<<8 | uint32(s[idx])
   262  }
   263  
   264  func load_le_byte8_uint64_idx(s []byte, idx int) uint64 {
   265  	// arm64:`MOVD\s\(R[0-9]+\)\(R[0-9]+\)`,-`ORR`,-`MOV[BHW]`
   266  	// amd64:`MOVQ\s\([A-Z]+\)\([A-Z]+`,-`MOV[BWL]`,-`OR`
   267  	return uint64(s[idx]) | uint64(s[idx+1])<<8 | uint64(s[idx+2])<<16 | uint64(s[idx+3])<<24 | uint64(s[idx+4])<<32 | uint64(s[idx+5])<<40 | uint64(s[idx+6])<<48 | uint64(s[idx+7])<<56
   268  }
   269  
   270  func load_le_byte8_uint64_idx_inv(s []byte, idx int) uint64 {
   271  	// arm64:`MOVD\s\(R[0-9]+\)\(R[0-9]+\)`,-`ORR`,-`MOV[BHW]`
   272  	return uint64(s[idx+7])<<56 | uint64(s[idx+6])<<48 | uint64(s[idx+5])<<40 | uint64(s[idx+4])<<32 | uint64(s[idx+3])<<24 | uint64(s[idx+2])<<16 | uint64(s[idx+1])<<8 | uint64(s[idx])
   273  }
   274  
   275  func load_be_byte2_uint16_idx(s []byte, idx int) uint16 {
   276  	// arm64:`MOVHU\s\(R[0-9]+\)\(R[0-9]+\)`,`REV16W`,-`ORR`,-`MOVB`
   277  	// amd64:`MOVWLZX\s\([A-Z]+\)\([A-Z]+`,-`MOVB`,-`OR`
   278  	return uint16(s[idx])<<8 | uint16(s[idx+1])
   279  }
   280  
   281  func load_be_byte2_uint16_idx_inv(s []byte, idx int) uint16 {
   282  	// arm64:`MOVHU\s\(R[0-9]+\)\(R[0-9]+\)`,`REV16W`,-`ORR`,-`MOVB`
   283  	// amd64:`MOVWLZX\s\([A-Z]+\)\([A-Z]+`,-`MOVB`,-`OR`
   284  	return uint16(s[idx+1]) | uint16(s[idx])<<8
   285  }
   286  
   287  func load_be_byte4_uint32_idx(s []byte, idx int) uint32 {
   288  	// arm64:`MOVWU\s\(R[0-9]+\)\(R[0-9]+\)`,`REVW`,-`ORR`,-`MOV[BH]`,-`REV16W`
   289  	return uint32(s[idx])<<24 | uint32(s[idx+1])<<16 | uint32(s[idx+2])<<8 | uint32(s[idx+3])
   290  }
   291  
   292  func load_be_byte8_uint64_idx(s []byte, idx int) uint64 {
   293  	// arm64:`MOVD\s\(R[0-9]+\)\(R[0-9]+\)`,`REV`,-`ORR`,-`MOV[BHW]`,-`REVW`,-`REV16W`
   294  	return uint64(s[idx])<<56 | uint64(s[idx+1])<<48 | uint64(s[idx+2])<<40 | uint64(s[idx+3])<<32 | uint64(s[idx+4])<<24 | uint64(s[idx+5])<<16 | uint64(s[idx+6])<<8 | uint64(s[idx+7])
   295  }
   296  
   297  func load_le_byte2_uint16_idx2(s []byte, idx int) uint16 {
   298  	// arm64:`MOVHU\s\(R[0-9]+\)\(R[0-9]+<<1\)`,-`ORR`,-`MOVB`
   299  	return uint16(s[idx<<1]) | uint16(s[(idx<<1)+1])<<8
   300  }
   301  
   302  func load_le_byte2_uint16_idx2_inv(s []byte, idx int) uint16 {
   303  	// arm64:`MOVHU\s\(R[0-9]+\)\(R[0-9]+<<1\)`,-`ORR`,-`MOVB`
   304  	return uint16(s[(idx<<1)+1])<<8 | uint16(s[idx<<1])
   305  }
   306  
   307  func load_le_byte4_uint32_idx4(s []byte, idx int) uint32 {
   308  	// arm64:`MOVWU\s\(R[0-9]+\)\(R[0-9]+<<2\)`,-`ORR`,-`MOV[BH]`
   309  	return uint32(s[idx<<2]) | uint32(s[(idx<<2)+1])<<8 | uint32(s[(idx<<2)+2])<<16 | uint32(s[(idx<<2)+3])<<24
   310  }
   311  
   312  func load_le_byte4_uint32_idx4_inv(s []byte, idx int) uint32 {
   313  	// arm64:`MOVWU\s\(R[0-9]+\)\(R[0-9]+<<2\)`,-`ORR`,-`MOV[BH]`
   314  	return uint32(s[(idx<<2)+3])<<24 | uint32(s[(idx<<2)+2])<<16 | uint32(s[(idx<<2)+1])<<8 | uint32(s[idx<<2])
   315  }
   316  
   317  func load_le_byte8_uint64_idx8(s []byte, idx int) uint64 {
   318  	// arm64:`MOVD\s\(R[0-9]+\)\(R[0-9]+<<3\)`,-`ORR`,-`MOV[BHW]`
   319  	return uint64(s[idx<<3]) | uint64(s[(idx<<3)+1])<<8 | uint64(s[(idx<<3)+2])<<16 | uint64(s[(idx<<3)+3])<<24 | uint64(s[(idx<<3)+4])<<32 | uint64(s[(idx<<3)+5])<<40 | uint64(s[(idx<<3)+6])<<48 | uint64(s[(idx<<3)+7])<<56
   320  }
   321  
   322  func load_le_byte8_uint64_idx8_inv(s []byte, idx int) uint64 {
   323  	// arm64:`MOVD\s\(R[0-9]+\)\(R[0-9]+<<3\)`,-`ORR`,-`MOV[BHW]`
   324  	return uint64(s[(idx<<3)+7])<<56 | uint64(s[(idx<<3)+6])<<48 | uint64(s[(idx<<3)+5])<<40 | uint64(s[(idx<<3)+4])<<32 | uint64(s[(idx<<3)+3])<<24 | uint64(s[(idx<<3)+2])<<16 | uint64(s[(idx<<3)+1])<<8 | uint64(s[idx<<3])
   325  }
   326  
   327  func load_be_byte2_uint16_idx2(s []byte, idx int) uint16 {
   328  	// arm64:`MOVHU\s\(R[0-9]+\)\(R[0-9]+<<1\)`,`REV16W`,-`ORR`,-`MOVB`
   329  	return uint16(s[idx<<1])<<8 | uint16(s[(idx<<1)+1])
   330  }
   331  
   332  func load_be_byte2_uint16_idx2_inv(s []byte, idx int) uint16 {
   333  	// arm64:`MOVHU\s\(R[0-9]+\)\(R[0-9]+<<1\)`,`REV16W`,-`ORR`,-`MOVB`
   334  	return uint16(s[(idx<<1)+1]) | uint16(s[idx<<1])<<8
   335  }
   336  
   337  func load_be_byte4_uint32_idx4(s []byte, idx int) uint32 {
   338  	// arm64:`MOVWU\s\(R[0-9]+\)\(R[0-9]+<<2\)`,`REVW`,-`ORR`,-`MOV[BH]`,-`REV16W`
   339  	return uint32(s[idx<<2])<<24 | uint32(s[(idx<<2)+1])<<16 | uint32(s[(idx<<2)+2])<<8 | uint32(s[(idx<<2)+3])
   340  }
   341  
   342  func load_be_byte8_uint64_idx8(s []byte, idx int) uint64 {
   343  	// arm64:`MOVD\s\(R[0-9]+\)\(R[0-9]+<<3\)`,`REV`,-`ORR`,-`MOV[BHW]`,-`REVW`,-`REV16W`
   344  	return uint64(s[idx<<3])<<56 | uint64(s[(idx<<3)+1])<<48 | uint64(s[(idx<<3)+2])<<40 | uint64(s[(idx<<3)+3])<<32 | uint64(s[(idx<<3)+4])<<24 | uint64(s[(idx<<3)+5])<<16 | uint64(s[(idx<<3)+6])<<8 | uint64(s[(idx<<3)+7])
   345  }
   346  
   347  // Some tougher cases for the memcombine pass.
   348  
   349  func reassoc_load_uint32(b []byte) uint32 {
   350  	// amd64:`MOVL\s\([A-Z]+\)`,-`MOV[BW]`,-`OR`
   351  	return (uint32(b[0]) | uint32(b[1])<<8) | (uint32(b[2])<<16 | uint32(b[3])<<24)
   352  }
   353  
   354  func extrashift_load_uint32(b []byte) uint32 {
   355  	// amd64:`MOVL\s\([A-Z]+\)`,`SHLL\s[$]2`,-`MOV[BW]`,-`OR`
   356  	return uint32(b[0])<<2 | uint32(b[1])<<10 | uint32(b[2])<<18 | uint32(b[3])<<26
   357  }
   358  
   359  func outoforder_load_uint32(b []byte) uint32 {
   360  	// amd64:`MOVL\s\([A-Z]+\)`,-`MOV[BW]`,-`OR`
   361  	return uint32(b[0]) | uint32(b[2])<<16 | uint32(b[1])<<8 | uint32(b[3])<<24
   362  }
   363  
   364  func extraOr_load_uint32(b []byte, x, y uint32) uint32 {
   365  	// amd64:`ORL\s\([A-Z]+\)`,-`MOV[BW]`
   366  	return x | binary.LittleEndian.Uint32(b) | y
   367  	// TODO: Note that
   368  	//   x | uint32(b[0]) | uint32(b[1])<<8 | uint32(b[2])<<16 | uint32(b[3])<<24 | y
   369  	// doesn't work because it associates in a way that memcombine can't detect it.
   370  }
   371  
   372  // Check load combining across function calls.
   373  
   374  func fcall_byte(a [2]byte) [2]byte {
   375  	return fcall_byte(fcall_byte(a)) // amd64:`MOVW`
   376  }
   377  
   378  func fcall_uint16(a [2]uint16) [2]uint16 {
   379  	return fcall_uint16(fcall_uint16(a)) // amd64:`MOVL`
   380  }
   381  
   382  func fcall_uint32(a [2]uint32) [2]uint32 {
   383  	return fcall_uint32(fcall_uint32(a)) // amd64:`MOVQ`
   384  }
   385  
   386  // We want to merge load+op in the first function, but not in the
   387  // second. See Issue 19595.
   388  func load_op_merge(p, q *int) {
   389  	x := *p // amd64:`ADDQ\t\(`
   390  	*q += x // The combined nilcheck and load would normally have this line number, but we want that combined operation to have the line number of the nil check instead (see #33724).
   391  }
   392  func load_op_no_merge(p, q *int) {
   393  	x := *p
   394  	for i := 0; i < 10; i++ {
   395  		*q += x // amd64:`ADDQ\t[A-Z]`
   396  	}
   397  }
   398  
   399  // Make sure offsets are folded into loads and stores.
   400  func offsets_fold(_, a [20]byte) (b [20]byte) {
   401  	// arm64:`MOVD\tcommand-line-arguments\.a\+[0-9]+\(FP\), R[0-9]+`,`MOVD\tR[0-9]+, command-line-arguments\.b\+[0-9]+\(FP\)`
   402  	b = a
   403  	return
   404  }
   405  
   406  // Make sure we don't put pointers in SSE registers across safe
   407  // points.
   408  
   409  func safe_point(p, q *[2]*int) {
   410  	a, b := p[0], p[1] // amd64:-`MOVUPS`
   411  	runtime.GC()
   412  	q[0], q[1] = a, b // amd64:-`MOVUPS`
   413  }
   414  
   415  // ------------- //
   416  //    Storing    //
   417  // ------------- //
   418  
   419  func store_le64(b []byte, x uint64) {
   420  	// amd64:`MOVQ\s.*\(.*\)$`,-`SHR.`
   421  	// arm64:`MOVD`,-`MOV[WBH]`
   422  	// ppc64le:`MOVD\s`,-`MOV[BHW]\s`
   423  	// ppc64:`MOVDBR`,-MOVB\s`
   424  	// s390x:`MOVDBR\s.*\(.*\)$`
   425  	binary.LittleEndian.PutUint64(b, x)
   426  }
   427  
   428  func store_le64_idx(b []byte, x uint64, idx int) {
   429  	// amd64:`MOVQ\s.*\(.*\)\(.*\*1\)$`,-`SHR.`
   430  	// arm64:`MOVD\sR[0-9]+,\s\(R[0-9]+\)\(R[0-9]+\)`,-`MOV[BHW]`
   431  	// ppc64le:`MOVD\s`,-`MOV[BHW]\s`
   432  	// ppc64:`MOVDBR`,-`MOVBZ`
   433  	// s390x:`MOVDBR\s.*\(.*\)\(.*\*1\)$`
   434  	binary.LittleEndian.PutUint64(b[idx:], x)
   435  }
   436  
   437  func store_le64_idx2(dst []byte, d, length, offset int) []byte {
   438  	a := dst[d : d+length]
   439  	b := dst[d-offset:]
   440  	// amd64:`MOVQ\s.*\(.*\)\(.*\*1\)$`,-`SHR.`
   441  	binary.LittleEndian.PutUint64(a, binary.LittleEndian.Uint64(b))
   442  	return dst
   443  }
   444  
   445  func store_le64_idx_const(b []byte, idx int) {
   446  	// amd64:`MOVQ\s\$123, \(.*\)\(.*\*1\)$`
   447  	binary.LittleEndian.PutUint64(b[idx:], 123)
   448  }
   449  
   450  func store_le64_load(b []byte, x *[8]byte) {
   451  	_ = b[8]
   452  	// amd64:-`MOV[BWL]`
   453  	// arm64:-`MOV[BWH]`
   454  	// ppc64le:`MOVD\s`,-`MOV[BWH]Z`
   455  	// ppc64:`MOVDBR`
   456  	// s390x:-`MOVB`,-`MOV[WH]BR`
   457  	binary.LittleEndian.PutUint64(b, binary.LittleEndian.Uint64(x[:]))
   458  }
   459  
   460  func store_le32(b []byte, x uint32) {
   461  	// amd64:`MOVL\s`
   462  	// arm64:`MOVW`,-`MOV[BH]`
   463  	// ppc64le:`MOVW\s`
   464  	// ppc64:`MOVWBR`
   465  	// s390x:`MOVWBR\s.*\(.*\)$`
   466  	binary.LittleEndian.PutUint32(b, x)
   467  }
   468  
   469  func store_le32_idx(b []byte, x uint32, idx int) {
   470  	// amd64:`MOVL\s`
   471  	// arm64:`MOVW\sR[0-9]+,\s\(R[0-9]+\)\(R[0-9]+\)`,-`MOV[BH]`
   472  	// ppc64le:`MOVW\s`
   473  	// ppc64:`MOVWBR`
   474  	// s390x:`MOVWBR\s.*\(.*\)\(.*\*1\)$`
   475  	binary.LittleEndian.PutUint32(b[idx:], x)
   476  }
   477  
   478  func store_le32_idx_const(b []byte, idx int) {
   479  	// amd64:`MOVL\s\$123, \(.*\)\(.*\*1\)$`
   480  	// ppc64x:`MOVW\s`,-MOV[HB]`
   481  	binary.LittleEndian.PutUint32(b[idx:], 123)
   482  }
   483  
   484  func store_le16(b []byte, x uint16) {
   485  	// amd64:`MOVW\s`
   486  	// arm64:`MOVH`,-`MOVB`
   487  	// ppc64le:`MOVH\s`
   488  	// ppc64:`MOVHBR`
   489  	// s390x:`MOVHBR\s.*\(.*\)$`
   490  	binary.LittleEndian.PutUint16(b, x)
   491  }
   492  
   493  func store_le16_idx(b []byte, x uint16, idx int) {
   494  	// amd64:`MOVW\s`
   495  	// arm64:`MOVH\sR[0-9]+,\s\(R[0-9]+\)\(R[0-9]+\)`,-`MOVB`
   496  	// ppc64le:`MOVH\s`
   497  	// ppc64:`MOVHBR\s`
   498  	// s390x:`MOVHBR\s.*\(.*\)\(.*\*1\)$`
   499  	binary.LittleEndian.PutUint16(b[idx:], x)
   500  }
   501  
   502  func store_le16_idx_const(b []byte, idx int) {
   503  	// amd64:`MOVW\s\$123, \(.*\)\(.*\*1\)$`
   504  	// ppc64x:`MOVH\s`
   505  	binary.LittleEndian.PutUint16(b[idx:], 123)
   506  }
   507  
   508  func store_be64(b []byte, x uint64) {
   509  	// amd64/v1,amd64/v2:`BSWAPQ`,-`SHR.`
   510  	// amd64/v3: `MOVBEQ`
   511  	// arm64:`MOVD`,`REV`,-`MOV[WBH]`,-`REVW`,-`REV16W`
   512  	// ppc64le:`MOVDBR`
   513  	// ppc64:`MOVD\s`
   514  	// s390x:`MOVD\s.*\(.*\)$`,-`SRW\s`,-`SRD\s`
   515  	binary.BigEndian.PutUint64(b, x)
   516  }
   517  
   518  func store_be64_idx(b []byte, x uint64, idx int) {
   519  	// amd64/v1,amd64/v2:`BSWAPQ`,-`SHR.`
   520  	// amd64/v3:`MOVBEQ\t[A-Z]+[0-9]*, \([A-Z]+[0-9]*\)\([A-Z]+[0-9]*\*1\)`
   521  	// arm64:`REV`,`MOVD\sR[0-9]+,\s\(R[0-9]+\)\(R[0-9]+\)`,-`MOV[BHW]`,-`REV16W`,-`REVW`
   522  	// ppc64le:`MOVDBR`
   523  	// ppc64:`MOVD\s`
   524  	// s390x:`MOVD\s.*\(.*\)\(.*\*1\)$`,-`SRW\s`,-`SRD\s`
   525  	binary.BigEndian.PutUint64(b[idx:], x)
   526  }
   527  
   528  func store_be32(b []byte, x uint32) {
   529  	// amd64/v1,amd64/v2:`BSWAPL`,-`SHR.`
   530  	// amd64/v3:`MOVBEL`
   531  	// arm64:`MOVW`,`REVW`,-`MOV[BH]`,-`REV16W`
   532  	// ppc64le:`MOVWBR`
   533  	// ppc64:`MOVW\s`
   534  	// s390x:`MOVW\s.*\(.*\)$`,-`SRW\s`,-`SRD\s`
   535  	binary.BigEndian.PutUint32(b, x)
   536  }
   537  
   538  func store_be64_load(b, x *[8]byte) {
   539  	// arm64:-`REV`
   540  	// amd64:-`BSWAPQ`
   541  	binary.BigEndian.PutUint64(b[:], binary.BigEndian.Uint64(x[:]))
   542  }
   543  
   544  func store_be32_load(b, x *[8]byte) {
   545  	// arm64:-`REVW`
   546  	// amd64:-`BSWAPL`
   547  	binary.BigEndian.PutUint32(b[:], binary.BigEndian.Uint32(x[:]))
   548  }
   549  
   550  func store_be32_idx(b []byte, x uint32, idx int) {
   551  	// amd64/v1,amd64/v2:`BSWAPL`,-`SHR.`
   552  	// amd64/v3:`MOVBEL\t[A-Z]+[0-9]*, \([A-Z]+[0-9]*\)\([A-Z]+[0-9]*\*1\)`
   553  	// arm64:`REVW`,`MOVW\sR[0-9]+,\s\(R[0-9]+\)\(R[0-9]+\)`,-`MOV[BH]`,-`REV16W`
   554  	// ppc64le:`MOVWBR`
   555  	// ppc64:`MOVW\s`
   556  	// s390x:`MOVW\s.*\(.*\)\(.*\*1\)$`,-`SRW\s`,-`SRD\s`
   557  	binary.BigEndian.PutUint32(b[idx:], x)
   558  }
   559  
   560  func store_be16(b []byte, x uint16) {
   561  	// amd64/v1,amd64/v2:`ROLW\s\$8`,-`SHR.`
   562  	// amd64/v3:`MOVBEW`,-`ROLW`
   563  	// arm64:`MOVH`,`REV16W`,-`MOVB`
   564  	// ppc64le:`MOVHBR`
   565  	// ppc64:`MOVH\s`
   566  	// s390x:`MOVH\s.*\(.*\)$`,-`SRW\s`,-`SRD\s`
   567  	binary.BigEndian.PutUint16(b, x)
   568  }
   569  
   570  func store_be16_idx(b []byte, x uint16, idx int) {
   571  	// amd64/v1,amd64/v2:`ROLW\s\$8`,-`SHR.`
   572  	// amd64/v3:`MOVBEW\t[A-Z]+[0-9]*, \([A-Z]+[0-9]*\)\([A-Z]+[0-9]*\*1\)`
   573  	// arm64:`MOVH\sR[0-9]+,\s\(R[0-9]+\)\(R[0-9]+\)`,`REV16W`,-`MOVB`
   574  	// ppc64le:`MOVHBR`
   575  	// ppc64:`MOVH\s`
   576  	// s390x:`MOVH\s.*\(.*\)\(.*\*1\)$`,-`SRW\s`,-`SRD\s`
   577  	binary.BigEndian.PutUint16(b[idx:], x)
   578  }
   579  
   580  func store_le_byte_2(b []byte, val uint16) {
   581  	_ = b[2]
   582  	// arm64:`MOVH\sR[0-9]+,\s1\(R[0-9]+\)`,-`MOVB`
   583  	// 386:`MOVW\s[A-Z]+,\s1\([A-Z]+\)`,-`MOVB`
   584  	// amd64:`MOVW\s[A-Z]+,\s1\([A-Z]+\)`,-`MOVB`
   585  	// ppc64le:`MOVH\s`,-`MOVB`
   586  	// ppc64:`MOVHBR`,-`MOVB`
   587  	b[1], b[2] = byte(val), byte(val>>8)
   588  }
   589  
   590  func store_le_byte_2_inv(b []byte, val uint16) {
   591  	_ = b[2]
   592  	// 386:`MOVW\s[A-Z]+,\s1\([A-Z]+\)`,-`MOVB`
   593  	// amd64:`MOVW\s[A-Z]+,\s1\([A-Z]+\)`,-`MOVB`
   594  	// ppc64le:`MOVH\s`,-`MOVB`
   595  	// ppc64:`MOVHBR`,-`MOVB`
   596  	b[2], b[1] = byte(val>>8), byte(val)
   597  }
   598  
   599  func store_le_byte_4(b []byte, val uint32) {
   600  	_ = b[4]
   601  	// arm64:`MOVW\sR[0-9]+,\s1\(R[0-9]+\)`,-`MOVB`,-`MOVH`
   602  	// 386:`MOVL\s[A-Z]+,\s1\([A-Z]+\)`,-`MOVB`,-`MOVW`
   603  	// amd64:`MOVL\s[A-Z]+,\s1\([A-Z]+\)`,-`MOVB`,-`MOVW`
   604  	// ppc64le:`MOVW\s`
   605  	// ppc64:`MOVWBR\s`
   606  	b[1], b[2], b[3], b[4] = byte(val), byte(val>>8), byte(val>>16), byte(val>>24)
   607  }
   608  
   609  func store_le_byte_8(b []byte, val uint64) {
   610  	_ = b[8]
   611  	// arm64:`MOVD\sR[0-9]+,\s1\(R[0-9]+\)`,-`MOVB`,-`MOVH`,-`MOVW`
   612  	// amd64:`MOVQ\s[A-Z]+,\s1\([A-Z]+\)`,-`MOVB`,-`MOVW`,-`MOVL`
   613  	// ppc64le:`MOVD\s`,-`MOVW`
   614  	// ppc64:`MOVDBR\s`
   615  	b[1], b[2], b[3], b[4], b[5], b[6], b[7], b[8] = byte(val), byte(val>>8), byte(val>>16), byte(val>>24), byte(val>>32), byte(val>>40), byte(val>>48), byte(val>>56)
   616  }
   617  
   618  func store_be_byte_2(b []byte, val uint16) {
   619  	_ = b[2]
   620  	// arm64:`REV16W`,`MOVH\sR[0-9]+,\s1\(R[0-9]+\)`,-`MOVB`
   621  	// amd64/v1,amd64/v2:`MOVW\s[A-Z]+,\s1\([A-Z]+\)`,-`MOVB`
   622  	// amd64/v3: `MOVBEW`
   623  	// ppc64le:`MOVHBR`
   624  	// ppc64:`MOVH\s`
   625  	b[1], b[2] = byte(val>>8), byte(val)
   626  }
   627  
   628  func store_be_byte_4(b []byte, val uint32) {
   629  	_ = b[4]
   630  	// arm64:`REVW`,`MOVW\sR[0-9]+,\s1\(R[0-9]+\)`,-`MOVB`,-`MOVH`,-`REV16W`
   631  	// amd64/v1,amd64/v2:`MOVL\s[A-Z]+,\s1\([A-Z]+\)`,-`MOVB`,-`MOVW`
   632  	// amd64/v3:`MOVBEL\s[A-Z]+,\s1\([A-Z]+\)`
   633  	// ppc64le:`MOVWBR`
   634  	// ppc64:`MOVW\s`
   635  	b[1], b[2], b[3], b[4] = byte(val>>24), byte(val>>16), byte(val>>8), byte(val)
   636  }
   637  
   638  func store_be_byte_8(b []byte, val uint64) {
   639  	_ = b[8]
   640  	// arm64:`REV`,`MOVD\sR[0-9]+,\s1\(R[0-9]+\)`,-`MOVB`,-`MOVH`,-`MOVW`,-`REV16W`,-`REVW`
   641  	// amd64/v1,amd64/v2:`MOVQ\s[A-Z]+,\s1\([A-Z]+\)`,-`MOVB`,-`MOVW`,-`MOVL`
   642  	// amd64/v3:`MOVBEQ\s[A-Z]+,\s1\([A-Z]+\)`, -`MOVBEL`
   643  	// ppc64le:`MOVDBR`
   644  	// ppc64:`MOVD`
   645  	b[1], b[2], b[3], b[4], b[5], b[6], b[7], b[8] = byte(val>>56), byte(val>>48), byte(val>>40), byte(val>>32), byte(val>>24), byte(val>>16), byte(val>>8), byte(val)
   646  }
   647  
   648  func store_le_byte_2_idx(b []byte, idx int, val uint16) {
   649  	_, _ = b[idx+0], b[idx+1]
   650  	// arm64:`MOVH\sR[0-9]+,\s\(R[0-9]+\)\(R[0-9]+\)`,-`MOVB`
   651  	// 386:`MOVW\s[A-Z]+,\s\([A-Z]+\)\([A-Z]+`,-`MOVB`
   652  	// ppc64le:`MOVH\s`
   653  	// ppc64:`MOVHBR`
   654  	b[idx+1], b[idx+0] = byte(val>>8), byte(val)
   655  }
   656  
   657  func store_le_byte_2_idx_inv(b []byte, idx int, val uint16) {
   658  	_, _ = b[idx+0], b[idx+1]
   659  	// 386:`MOVW\s[A-Z]+,\s\([A-Z]+\)\([A-Z]+`,-`MOVB`
   660  	// ppc64le:`MOVH\s`
   661  	// ppc64:`MOVHBR`
   662  	b[idx+0], b[idx+1] = byte(val), byte(val>>8)
   663  }
   664  
   665  func store_le_byte_4_idx(b []byte, idx int, val uint32) {
   666  	_, _, _, _ = b[idx+0], b[idx+1], b[idx+2], b[idx+3]
   667  	// arm64:`MOVW\sR[0-9]+,\s\(R[0-9]+\)\(R[0-9]+\)`,-`MOVB`,-`MOVH`
   668  	// ppc64le:`MOVW\s`
   669  	// ppc64:`MOVWBR`
   670  	b[idx+3], b[idx+2], b[idx+1], b[idx+0] = byte(val>>24), byte(val>>16), byte(val>>8), byte(val)
   671  }
   672  
   673  func store_be_byte_2_idx(b []byte, idx int, val uint16) {
   674  	_, _ = b[idx+0], b[idx+1]
   675  	// arm64:`REV16W`,`MOVH\sR[0-9]+,\s\(R[0-9]+\)\(R[0-9]+\)`,-`MOVB`
   676  	// ppc64le:`MOVHBR`
   677  	// ppc64:`MOVH\s`
   678  	b[idx+0], b[idx+1] = byte(val>>8), byte(val)
   679  }
   680  
   681  func store_be_byte_4_idx(b []byte, idx int, val uint32) {
   682  	_, _, _, _ = b[idx+0], b[idx+1], b[idx+2], b[idx+3]
   683  	// arm64:`REVW`,`MOVW\sR[0-9]+,\s\(R[0-9]+\)\(R[0-9]+\)`,-`MOVB`,-`MOVH`,-`REV16W`
   684  	// ppc64le:`MOVWBR`
   685  	// ppc64:`MOVW\s`
   686  	b[idx+0], b[idx+1], b[idx+2], b[idx+3] = byte(val>>24), byte(val>>16), byte(val>>8), byte(val)
   687  }
   688  
   689  func store_be_byte_2_idx2(b []byte, idx int, val uint16) {
   690  	_, _ = b[(idx<<1)+0], b[(idx<<1)+1]
   691  	// arm64:`REV16W`,`MOVH\sR[0-9]+,\s\(R[0-9]+\)\(R[0-9]+<<1\)`,-`MOVB`
   692  	// ppc64le:`MOVHBR`
   693  	// ppc64:`MOVH\s`
   694  	b[(idx<<1)+0], b[(idx<<1)+1] = byte(val>>8), byte(val)
   695  }
   696  
   697  func store_le_byte_2_idx2(b []byte, idx int, val uint16) {
   698  	_, _ = b[(idx<<1)+0], b[(idx<<1)+1]
   699  	// arm64:`MOVH\sR[0-9]+,\s\(R[0-9]+\)\(R[0-9]+<<1\)`,-`MOVB`
   700  	// ppc64le:`MOVH\s`
   701  	// ppc64:`MOVHBR`
   702  	b[(idx<<1)+1], b[(idx<<1)+0] = byte(val>>8), byte(val)
   703  }
   704  
   705  func store_be_byte_4_idx4(b []byte, idx int, val uint32) {
   706  	_, _, _, _ = b[(idx<<2)+0], b[(idx<<2)+1], b[(idx<<2)+2], b[(idx<<2)+3]
   707  	// arm64:`REVW`,`MOVW\sR[0-9]+,\s\(R[0-9]+\)\(R[0-9]+<<2\)`,-`MOVB`,-`MOVH`,-`REV16W`
   708  	// ppc64le:`MOVWBR`
   709  	// ppc64:`MOVW\s`
   710  	b[(idx<<2)+0], b[(idx<<2)+1], b[(idx<<2)+2], b[(idx<<2)+3] = byte(val>>24), byte(val>>16), byte(val>>8), byte(val)
   711  }
   712  
   713  func store_le_byte_4_idx4_inv(b []byte, idx int, val uint32) {
   714  	_, _, _, _ = b[(idx<<2)+0], b[(idx<<2)+1], b[(idx<<2)+2], b[(idx<<2)+3]
   715  	// arm64:`MOVW\sR[0-9]+,\s\(R[0-9]+\)\(R[0-9]+<<2\)`,-`MOVB`,-`MOVH`
   716  	// ppc64le:`MOVW\s`
   717  	// ppc64:`MOVWBR`
   718  	b[(idx<<2)+3], b[(idx<<2)+2], b[(idx<<2)+1], b[(idx<<2)+0] = byte(val>>24), byte(val>>16), byte(val>>8), byte(val)
   719  }
   720  
   721  // ------------- //
   722  //    Zeroing    //
   723  // ------------- //
   724  
   725  // Check that zero stores are combined into larger stores
   726  
   727  func zero_byte_2(b1, b2 []byte) {
   728  	// bounds checks to guarantee safety of writes below
   729  	_, _ = b1[1], b2[1]
   730  	// arm64:"MOVH\tZR",-"MOVB"
   731  	// amd64:`MOVW\s[$]0,\s\([A-Z]+\)`
   732  	// 386:`MOVW\s[$]0,\s\([A-Z]+\)`
   733  	// ppc64x:`MOVH\s`
   734  	b1[0], b1[1] = 0, 0
   735  	// arm64:"MOVH\tZR",-"MOVB"
   736  	// 386:`MOVW\s[$]0,\s\([A-Z]+\)`
   737  	// amd64:`MOVW\s[$]0,\s\([A-Z]+\)`
   738  	// ppc64x:`MOVH`
   739  	b2[1], b2[0] = 0, 0
   740  }
   741  
   742  func zero_byte_4(b1, b2 []byte) {
   743  	_, _ = b1[3], b2[3]
   744  	// arm64:"MOVW\tZR",-"MOVB",-"MOVH"
   745  	// amd64:`MOVL\s[$]0,\s\([A-Z]+\)`
   746  	// 386:`MOVL\s[$]0,\s\([A-Z]+\)`
   747  	// ppc64x:`MOVW\s`
   748  	b1[0], b1[1], b1[2], b1[3] = 0, 0, 0, 0
   749  	// arm64:"MOVW\tZR",-"MOVB",-"MOVH"
   750  	// ppc64x:`MOVW\s`
   751  	b2[2], b2[3], b2[1], b2[0] = 0, 0, 0, 0
   752  }
   753  
   754  func zero_byte_8(b []byte) {
   755  	_ = b[7]
   756  	b[0], b[1], b[2], b[3] = 0, 0, 0, 0 // arm64:"MOVD\tZR",-"MOVB",-"MOVH",-"MOVW"
   757  	b[4], b[5], b[6], b[7] = 0, 0, 0, 0
   758  }
   759  
   760  func zero_byte_16(b []byte) {
   761  	_ = b[15]
   762  	b[0], b[1], b[2], b[3] = 0, 0, 0, 0 // arm64:"STP",-"MOVB",-"MOVH",-"MOVW"
   763  	b[4], b[5], b[6], b[7] = 0, 0, 0, 0
   764  	b[8], b[9], b[10], b[11] = 0, 0, 0, 0
   765  	b[12], b[13], b[14], b[15] = 0, 0, 0, 0
   766  }
   767  
   768  func zero_byte_30(a *[30]byte) {
   769  	*a = [30]byte{} // arm64:"STP",-"MOVB",-"MOVH",-"MOVW"
   770  }
   771  
   772  func zero_byte_39(a *[39]byte) {
   773  	*a = [39]byte{} // arm64:"MOVD",-"MOVB",-"MOVH",-"MOVW"
   774  }
   775  
   776  func zero_byte_2_idx(b []byte, idx int) {
   777  	_, _ = b[idx+0], b[idx+1]
   778  	// arm64:`MOVH\sZR,\s\(R[0-9]+\)\(R[0-9]+\)`,-`MOVB`
   779  	// ppc64x:`MOVH\s`
   780  	b[idx+0], b[idx+1] = 0, 0
   781  }
   782  
   783  func zero_byte_2_idx2(b []byte, idx int) {
   784  	_, _ = b[(idx<<1)+0], b[(idx<<1)+1]
   785  	// arm64:`MOVH\sZR,\s\(R[0-9]+\)\(R[0-9]+<<1\)`,-`MOVB`
   786  	// ppc64x:`MOVH\s`
   787  	b[(idx<<1)+0], b[(idx<<1)+1] = 0, 0
   788  }
   789  
   790  func zero_uint16_2(h1, h2 []uint16) {
   791  	_, _ = h1[1], h2[1]
   792  	// arm64:"MOVW\tZR",-"MOVB",-"MOVH"
   793  	// amd64:`MOVL\s[$]0,\s\([A-Z]+\)`
   794  	// 386:`MOVL\s[$]0,\s\([A-Z]+\)`
   795  	// ppc64x:`MOVW\s`
   796  	h1[0], h1[1] = 0, 0
   797  	// arm64:"MOVW\tZR",-"MOVB",-"MOVH"
   798  	// amd64:`MOVL\s[$]0,\s\([A-Z]+\)`
   799  	// 386:`MOVL\s[$]0,\s\([A-Z]+\)`
   800  	// ppc64x:`MOVW`
   801  	h2[1], h2[0] = 0, 0
   802  }
   803  
   804  func zero_uint16_4(h1, h2 []uint16) {
   805  	_, _ = h1[3], h2[3]
   806  	// arm64:"MOVD\tZR",-"MOVB",-"MOVH",-"MOVW"
   807  	// amd64:`MOVQ\s[$]0,\s\([A-Z]+\)`
   808  	// ppc64x:`MOVD\s`
   809  	h1[0], h1[1], h1[2], h1[3] = 0, 0, 0, 0
   810  	// arm64:"MOVD\tZR",-"MOVB",-"MOVH",-"MOVW"
   811  	// ppc64x:`MOVD\s`
   812  	h2[2], h2[3], h2[1], h2[0] = 0, 0, 0, 0
   813  }
   814  
   815  func zero_uint16_8(h []uint16) {
   816  	_ = h[7]
   817  	h[0], h[1], h[2], h[3] = 0, 0, 0, 0 // arm64:"STP",-"MOVB",-"MOVH"
   818  	h[4], h[5], h[6], h[7] = 0, 0, 0, 0
   819  }
   820  
   821  func zero_uint32_2(w1, w2 []uint32) {
   822  	_, _ = w1[1], w2[1]
   823  	// arm64:"MOVD\tZR",-"MOVB",-"MOVH",-"MOVW"
   824  	// amd64:`MOVQ\s[$]0,\s\([A-Z]+\)`
   825  	// ppc64x:`MOVD\s`
   826  	w1[0], w1[1] = 0, 0
   827  	// arm64:"MOVD\tZR",-"MOVB",-"MOVH",-"MOVW"
   828  	// amd64:`MOVQ\s[$]0,\s\([A-Z]+\)`
   829  	// ppc64x:`MOVD\s`
   830  	w2[1], w2[0] = 0, 0
   831  }
   832  
   833  func zero_uint32_4(w1, w2 []uint32) {
   834  	_, _ = w1[3], w2[3]
   835  	w1[0], w1[1], w1[2], w1[3] = 0, 0, 0, 0 // arm64:"STP",-"MOVB",-"MOVH"
   836  	w2[2], w2[3], w2[1], w2[0] = 0, 0, 0, 0 // arm64:"STP",-"MOVB",-"MOVH"
   837  }
   838  
   839  func zero_uint64_2(d1, d2 []uint64) {
   840  	_, _ = d1[1], d2[1]
   841  	d1[0], d1[1] = 0, 0 // arm64:"STP",-"MOVB",-"MOVH"
   842  	d2[1], d2[0] = 0, 0 // arm64:"STP",-"MOVB",-"MOVH"
   843  }
   844  
   845  func loadstore(p, q *[4]uint8) {
   846  	// amd64:"MOVL",-"MOVB"
   847  	// arm64:"MOVWU",-"MOVBU"
   848  	x0, x1, x2, x3 := q[0], q[1], q[2], q[3]
   849  	// amd64:"MOVL",-"MOVB"
   850  	// arm64:"MOVW",-"MOVB"
   851  	p[0], p[1], p[2], p[3] = x0, x1, x2, x3
   852  }
   853  
   854  type S1 struct {
   855  	a, b int16
   856  }
   857  
   858  func loadstore2(p, q *S1) {
   859  	// amd64:"MOVL",-"MOVWLZX"
   860  	// arm64:"MOVWU",-"MOVH"
   861  	a, b := p.a, p.b
   862  	// amd64:"MOVL",-"MOVW"
   863  	// arm64:"MOVW",-"MOVH"
   864  	q.a, q.b = a, b
   865  }
   866  
   867  func wideStore(p *[8]uint64) {
   868  	if p == nil {
   869  		return
   870  	}
   871  
   872  	// amd64:"MOVUPS",-"MOVQ"
   873  	// arm64:"STP",-"MOVD"
   874  	p[0] = 0
   875  	// amd64:-"MOVUPS",-"MOVQ"
   876  	// arm64:-"STP",-"MOVD"
   877  	p[1] = 0
   878  }
   879  
   880  func wideStore2(p *[8]uint64, x, y uint64) {
   881  	if p == nil {
   882  		return
   883  	}
   884  
   885  	// s390x:"STMG"
   886  	p[0] = x
   887  	// s390x:-"STMG",-"MOVD"
   888  	p[1] = y
   889  }
   890  
   891  func store32le(p *struct{ a, b uint32 }, x uint64) {
   892  	// amd64:"MOVQ",-"MOVL",-"SHRQ"
   893  	// arm64:"MOVD",-"MOVW",-"LSR"
   894  	// ppc64le:"MOVD",-"MOVW",-"SRD"
   895  	p.a = uint32(x)
   896  	// amd64:-"MOVL",-"SHRQ"
   897  	// arm64:-"MOVW",-"LSR"
   898  	// ppc64le:-"MOVW",-"SRD"
   899  	p.b = uint32(x >> 32)
   900  }
   901  func store32be(p *struct{ a, b uint32 }, x uint64) {
   902  	// ppc64:"MOVD",-"MOVW",-"SRD"
   903  	// s390x:"MOVD",-"MOVW",-"SRD"
   904  	p.a = uint32(x >> 32)
   905  	// ppc64:-"MOVW",-"SRD"
   906  	// s390x:-"MOVW",-"SRD"
   907  	p.b = uint32(x)
   908  }
   909  func store16le(p *struct{ a, b uint16 }, x uint32) {
   910  	// amd64:"MOVL",-"MOVW",-"SHRL"
   911  	// arm64:"MOVW",-"MOVH",-"UBFX"
   912  	// ppc64le:"MOVW",-"MOVH",-"SRW"
   913  	p.a = uint16(x)
   914  	// amd64:-"MOVW",-"SHRL"
   915  	// arm64:-"MOVH",-"UBFX"
   916  	// ppc64le:-"MOVH",-"SRW"
   917  	p.b = uint16(x >> 16)
   918  }
   919  func store16be(p *struct{ a, b uint16 }, x uint32) {
   920  	// ppc64:"MOVW",-"MOVH",-"SRW"
   921  	// s390x:"MOVW",-"MOVH",-"SRW"
   922  	p.a = uint16(x >> 16)
   923  	// ppc64:-"MOVH",-"SRW"
   924  	// s390x:-"MOVH",-"SRW"
   925  	p.b = uint16(x)
   926  }
   927  
   928  func storeBoolConst(p *struct{ a, b bool }) {
   929  	// amd64:"MOVW",-"MOVB"
   930  	// arm64:"MOVH",-"MOVB"
   931  	p.a = true
   932  	p.b = true
   933  }
   934  func issue66413(p *struct {
   935  	a byte
   936  	b bool
   937  	c bool
   938  	d int8
   939  }) {
   940  	// amd64:"MOVL",-"MOVB"
   941  	// arm64:"MOVW",-"MOVB"
   942  	p.a = 31
   943  	p.b = false
   944  	p.c = true
   945  	p.d = 12
   946  }
   947  
   948  func issue70300(v uint64) (b [8]byte) {
   949  	// amd64:"MOVQ",-"MOVB"
   950  	b[0] = byte(v)
   951  	b[1] = byte(v >> 8)
   952  	b[2] = byte(v >> 16)
   953  	b[3] = byte(v >> 24)
   954  	b[4] = byte(v >> 32)
   955  	b[5] = byte(v >> 40)
   956  	b[6] = byte(v >> 48)
   957  	b[7] = byte(v >> 56)
   958  	return b
   959  }
   960  
   961  func issue70300Reverse(v uint64) (b [8]byte) {
   962  	// amd64:"MOVQ",-"MOVB"
   963  	b[7] = byte(v >> 56)
   964  	b[6] = byte(v >> 48)
   965  	b[5] = byte(v >> 40)
   966  	b[4] = byte(v >> 32)
   967  	b[3] = byte(v >> 24)
   968  	b[2] = byte(v >> 16)
   969  	b[1] = byte(v >> 8)
   970  	b[0] = byte(v)
   971  	return b
   972  }
   973  

View as plain text