rotate.go 1.3 KB

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