github.com/gagliardetto/golang-go@v0.0.0-20201020153340-53909ea70814/cmd/internal/obj/s390x/rotate.go (about)

     1  // Copyright 2019 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  package s390x
     6  
     7  // RotateParams represents the immediates required for a "rotate
     8  // then ... selected bits instruction".
     9  //
    10  // The Start and End values are the indexes that represent
    11  // the masked region. They are inclusive and are in big-
    12  // endian order (bit 0 is the MSB, bit 63 is the LSB). They
    13  // may wrap around.
    14  //
    15  // Some examples:
    16  //
    17  // Masked region             | Start | End
    18  // --------------------------+-------+----
    19  // 0x00_00_00_00_00_00_00_0f | 60    | 63
    20  // 0xf0_00_00_00_00_00_00_00 | 0     | 3
    21  // 0xf0_00_00_00_00_00_00_0f | 60    | 3
    22  //
    23  // The Amount value represents the amount to rotate the
    24  // input left by. Note that this rotation is performed
    25  // before the masked region is used.
    26  type RotateParams struct {
    27  	Start  uint8 // big-endian start bit index [0..63]
    28  	End    uint8 // big-endian end bit index [0..63]
    29  	Amount uint8 // amount to rotate left
    30  }
    31  
    32  func NewRotateParams(start, end, amount int64) RotateParams {
    33  	if start&^63 != 0 {
    34  		panic("start out of bounds")
    35  	}
    36  	if end&^63 != 0 {
    37  		panic("end out of bounds")
    38  	}
    39  	if amount&^63 != 0 {
    40  		panic("amount out of bounds")
    41  	}
    42  	return RotateParams{
    43  		Start:  uint8(start),
    44  		End:    uint8(end),
    45  		Amount: uint8(amount),
    46  	}
    47  }