github.com/hikaru7719/go@v0.0.0-20181025140707-c8b2ac68906a/test/codegen/bitfield.go (about)

     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  // This file contains codegen tests related to bit field
    10  // insertion/extraction simplifications/optimizations.
    11  
    12  func extr1(x, x2 uint64) uint64 {
    13  	return x<<7 + x2>>57 // arm64:"EXTR\t[$]57,"
    14  }
    15  
    16  func extr2(x, x2 uint64) uint64 {
    17  	return x<<7 | x2>>57 // arm64:"EXTR\t[$]57,"
    18  }
    19  
    20  func extr3(x, x2 uint64) uint64 {
    21  	return x<<7 ^ x2>>57 // arm64:"EXTR\t[$]57,"
    22  }
    23  
    24  func extr4(x, x2 uint32) uint32 {
    25  	return x<<7 + x2>>25 // arm64:"EXTRW\t[$]25,"
    26  }
    27  
    28  func extr5(x, x2 uint32) uint32 {
    29  	return x<<7 | x2>>25 // arm64:"EXTRW\t[$]25,"
    30  }
    31  
    32  func extr6(x, x2 uint32) uint32 {
    33  	return x<<7 ^ x2>>25 // arm64:"EXTRW\t[$]25,"
    34  }
    35  
    36  // check 32-bit shift masking
    37  func mask32(x uint32) uint32 {
    38  	return (x << 29) >> 29 // arm64:"AND\t[$]7, R[0-9]+",-"LSR",-"LSL"
    39  }
    40  
    41  // check 16-bit shift masking
    42  func mask16(x uint16) uint16 {
    43  	return (x << 14) >> 14 // arm64:"AND\t[$]3, R[0-9]+",-"LSR",-"LSL"
    44  }
    45  
    46  // check 8-bit shift masking
    47  func mask8(x uint8) uint8 {
    48  	return (x << 7) >> 7 // arm64:"AND\t[$]1, R[0-9]+",-"LSR",-"LSL"
    49  }
    50  
    51  func maskshift(x uint64) uint64 {
    52  	// arm64:"AND\t[$]4095, R[0-9]+",-"LSL",-"LSR",-"UBFIZ",-"UBFX"
    53  	return ((x << 5) & (0xfff << 5)) >> 5
    54  }
    55  
    56  // bitfield ops
    57  // bfi
    58  func bfi1(x, y uint64) uint64 {
    59  	// arm64:"BFI\t[$]4, R[0-9]+, [$]12",-"LSL",-"LSR",-"AND"
    60  	return ((x & 0xfff) << 4) | (y & 0xffffffffffff000f)
    61  }
    62  
    63  func bfi2(x, y uint64) uint64 {
    64  	// arm64:"BFI\t[$]12, R[0-9]+, [$]40",-"LSL",-"LSR",-"AND"
    65  	return (x << 24 >> 12) | (y & 0xfff0000000000fff)
    66  }
    67  
    68  // bfxil
    69  func bfxil1(x, y uint64) uint64 {
    70  	// arm64:"BFXIL\t[$]5, R[0-9]+, [$]12",-"LSL",-"LSR",-"AND"
    71  	return ((x >> 5) & 0xfff) | (y & 0xfffffffffffff000)
    72  }
    73  
    74  func bfxil2(x, y uint64) uint64 {
    75  	// arm64:"BFXIL\t[$]12, R[0-9]+, [$]40",-"LSL",-"LSR",-"AND"
    76  	return (x << 12 >> 24) | (y & 0xffffff0000000000)
    77  }
    78  
    79  // sbfiz
    80  func sbfiz1(x int64) int64 {
    81  	// arm64:"SBFIZ\t[$]1, R[0-9]+, [$]60",-"LSL",-"ASR"
    82  	return (x << 4) >> 3
    83  }
    84  
    85  func sbfiz2(x int32) int64 {
    86  	return int64(x << 3) // arm64:"SBFIZ\t[$]3, R[0-9]+, [$]29",-"LSL"
    87  }
    88  
    89  func sbfiz3(x int16) int64 {
    90  	return int64(x << 3) // arm64:"SBFIZ\t[$]3, R[0-9]+, [$]13",-"LSL"
    91  }
    92  
    93  func sbfiz4(x int8) int64 {
    94  	return int64(x << 3) // arm64:"SBFIZ\t[$]3, R[0-9]+, [$]5",-"LSL"
    95  }
    96  
    97  func sbfiz5(x int32) int32 {
    98  	// arm64:"SBFIZ\t[$]1, R[0-9]+, [$]28",-"LSL",-"ASR"
    99  	return (x << 4) >> 3
   100  }
   101  
   102  // sbfx
   103  func sbfx1(x int64) int64 {
   104  	return (x << 3) >> 4 // arm64:"SBFX\t[$]1, R[0-9]+, [$]60",-"LSL",-"ASR"
   105  }
   106  
   107  func sbfx2(x int64) int64 {
   108  	return (x << 60) >> 60 // arm64:"SBFX\tZR, R[0-9]+, [$]4",-"LSL",-"ASR"
   109  }
   110  
   111  func sbfx3(x int32) int64 {
   112  	return int64(x) >> 3 // arm64:"SBFX\t[$]3, R[0-9]+, [$]29",-"ASR"
   113  }
   114  
   115  func sbfx4(x int16) int64 {
   116  	return int64(x) >> 3 // arm64:"SBFX\t[$]3, R[0-9]+, [$]13",-"ASR"
   117  }
   118  
   119  func sbfx5(x int8) int64 {
   120  	return int64(x) >> 3 // arm64:"SBFX\t[$]3, R[0-9]+, [$]5",-"ASR"
   121  }
   122  
   123  func sbfx6(x int32) int32 {
   124  	return (x << 3) >> 4 // arm64:"SBFX\t[$]1, R[0-9]+, [$]28",-"LSL",-"ASR"
   125  }
   126  
   127  // ubfiz
   128  func ubfiz1(x uint64) uint64 {
   129  	// arm64:"UBFIZ\t[$]3, R[0-9]+, [$]12",-"LSL",-"AND"
   130  	return (x & 0xfff) << 3
   131  }
   132  
   133  func ubfiz2(x uint64) uint64 {
   134  	// arm64:"UBFIZ\t[$]4, R[0-9]+, [$]12",-"LSL",-"AND"
   135  	return (x << 4) & 0xfff0
   136  }
   137  
   138  func ubfiz3(x uint32) uint64 {
   139  	return uint64(x+1) << 3 // arm64:"UBFIZ\t[$]3, R[0-9]+, [$]32",-"LSL"
   140  }
   141  
   142  func ubfiz4(x uint16) uint64 {
   143  	return uint64(x+1) << 3 // arm64:"UBFIZ\t[$]3, R[0-9]+, [$]16",-"LSL"
   144  }
   145  
   146  func ubfiz5(x uint8) uint64 {
   147  	return uint64(x+1) << 3 // arm64:"UBFIZ\t[$]3, R[0-9]+, [$]8",-"LSL"
   148  }
   149  
   150  func ubfiz6(x uint64) uint64 {
   151  	// arm64:"UBFIZ\t[$]1, R[0-9]+, [$]60",-"LSL",-"LSR"
   152  	return (x << 4) >> 3
   153  }
   154  
   155  func ubfiz7(x uint32) uint32 {
   156  	// arm64:"UBFIZ\t[$]1, R[0-9]+, [$]28",-"LSL",-"LSR"
   157  	return (x << 4) >> 3
   158  }
   159  
   160  func ubfiz8(x uint64) uint64 {
   161  	// arm64:"UBFIZ\t[$]1, R[0-9]+, [$]20",-"LSL",-"LSR"
   162  	return ((x & 0xfffff) << 4) >> 3
   163  }
   164  
   165  func ubfiz9(x uint64) uint64 {
   166  	// arm64:"UBFIZ\t[$]5, R[0-9]+, [$]13",-"LSL",-"LSR",-"AND"
   167  	return ((x << 3) & 0xffff) << 2
   168  }
   169  
   170  func ubfiz10(x uint64) uint64 {
   171  	// arm64:"UBFIZ\t[$]7, R[0-9]+, [$]12",-"LSL",-"LSR",-"AND"
   172  	return ((x << 5) & (0xfff << 5)) << 2
   173  }
   174  
   175  // ubfx
   176  func ubfx1(x uint64) uint64 {
   177  	// arm64:"UBFX\t[$]25, R[0-9]+, [$]10",-"LSR",-"AND"
   178  	return (x >> 25) & 1023
   179  }
   180  
   181  func ubfx2(x uint64) uint64 {
   182  	// arm64:"UBFX\t[$]4, R[0-9]+, [$]8",-"LSR",-"AND"
   183  	return (x & 0x0ff0) >> 4
   184  }
   185  
   186  func ubfx3(x uint32) uint64 {
   187  	return uint64(x >> 15) // arm64:"UBFX\t[$]15, R[0-9]+, [$]17",-"LSR"
   188  }
   189  
   190  func ubfx4(x uint16) uint64 {
   191  	return uint64(x >> 9) // arm64:"UBFX\t[$]9, R[0-9]+, [$]7",-"LSR"
   192  }
   193  
   194  func ubfx5(x uint8) uint64 {
   195  	return uint64(x >> 3) // arm64:"UBFX\t[$]3, R[0-9]+, [$]5",-"LSR"
   196  }
   197  
   198  func ubfx6(x uint64) uint64 {
   199  	return (x << 1) >> 2 // arm64:"UBFX\t[$]1, R[0-9]+, [$]62",-"LSL",-"LSR"
   200  }
   201  
   202  func ubfx7(x uint32) uint32 {
   203  	return (x << 1) >> 2 // arm64:"UBFX\t[$]1, R[0-9]+, [$]30",-"LSL",-"LSR"
   204  }
   205  
   206  func ubfx8(x uint64) uint64 {
   207  	// arm64:"UBFX\t[$]1, R[0-9]+, [$]12",-"LSL",-"LSR",-"AND"
   208  	return ((x << 1) >> 2) & 0xfff
   209  }
   210  
   211  func ubfx9(x uint64) uint64 {
   212  	// arm64:"UBFX\t[$]4, R[0-9]+, [$]11",-"LSL",-"LSR",-"AND"
   213  	return ((x >> 3) & 0xfff) >> 1
   214  }
   215  
   216  func ubfx10(x uint64) uint64 {
   217  	// arm64:"UBFX\t[$]5, R[0-9]+, [$]56",-"LSL",-"LSR"
   218  	return ((x >> 2) << 5) >> 8
   219  }
   220  
   221  func ubfx11(x uint64) uint64 {
   222  	// arm64:"UBFX\t[$]1, R[0-9]+, [$]19",-"LSL",-"LSR"
   223  	return ((x & 0xfffff) << 3) >> 4
   224  }
   225  
   226  // Check that we don't emit comparisons for constant shifts.
   227  //go:nosplit
   228  func shift_no_cmp(x int) int {
   229  	// arm64:`LSL\t[$]17`,-`CMP`
   230  	// mips64:`SLLV\t[$]17`,-`SGT`
   231  	return x << 17
   232  }