podman
126 строк · 3.1 Кб
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
5package s390x
6
7import (
8"fmt"
9)
10
11// CCMask represents a 4-bit condition code mask. Bits that
12// are not part of the mask should be 0.
13//
14// Condition code masks represent the 4 possible values of
15// the 2-bit condition code as individual bits. Since IBM Z
16// is a big-endian platform bits are numbered from left to
17// right. The lowest value, 0, is represented by 8 (0b1000)
18// and the highest value, 3, is represented by 1 (0b0001).
19//
20// Note that condition code values have different semantics
21// depending on the instruction that set the condition code.
22// The names given here assume that the condition code was
23// set by an integer or floating point comparison. Other
24// instructions may use these same codes to indicate
25// different results such as a carry or overflow.
26type CCMask uint8
27
28const (
29Never CCMask = 0 // no-op
30
31// 1-bit masks
32Equal CCMask = 1 << 3
33Less CCMask = 1 << 2
34Greater CCMask = 1 << 1
35Unordered CCMask = 1 << 0
36
37// 2-bit masks
38EqualOrUnordered CCMask = Equal | Unordered // not less and not greater
39LessOrEqual CCMask = Less | Equal // ordered and not greater
40LessOrGreater CCMask = Less | Greater // ordered and not equal
41LessOrUnordered CCMask = Less | Unordered // not greater and not equal
42GreaterOrEqual CCMask = Greater | Equal // ordered and not less
43GreaterOrUnordered CCMask = Greater | Unordered // not less and not equal
44
45// 3-bit masks
46NotEqual CCMask = Always ^ Equal
47NotLess CCMask = Always ^ Less
48NotGreater CCMask = Always ^ Greater
49NotUnordered CCMask = Always ^ Unordered
50
51// 4-bit mask
52Always CCMask = Equal | Less | Greater | Unordered
53
54// useful aliases
55Carry CCMask = GreaterOrUnordered
56NoCarry CCMask = LessOrEqual
57Borrow CCMask = NoCarry
58NoBorrow CCMask = Carry
59)
60
61// Inverse returns the complement of the condition code mask.
62func (c CCMask) Inverse() CCMask {
63return c ^ Always
64}
65
66// ReverseComparison swaps the bits at 0b0100 and 0b0010 in the mask,
67// reversing the behavior of greater than and less than conditions.
68func (c CCMask) ReverseComparison() CCMask {
69r := c & EqualOrUnordered
70if c&Less != 0 {
71r |= Greater
72}
73if c&Greater != 0 {
74r |= Less
75}
76return r
77}
78
79func (c CCMask) String() string {
80switch c {
81// 0-bit mask
82case Never:
83return "Never"
84
85// 1-bit masks
86case Equal:
87return "Equal"
88case Less:
89return "Less"
90case Greater:
91return "Greater"
92case Unordered:
93return "Unordered"
94
95// 2-bit masks
96case EqualOrUnordered:
97return "EqualOrUnordered"
98case LessOrEqual:
99return "LessOrEqual"
100case LessOrGreater:
101return "LessOrGreater"
102case LessOrUnordered:
103return "LessOrUnordered"
104case GreaterOrEqual:
105return "GreaterOrEqual"
106case GreaterOrUnordered:
107return "GreaterOrUnordered"
108
109// 3-bit masks
110case NotEqual:
111return "NotEqual"
112case NotLess:
113return "NotLess"
114case NotGreater:
115return "NotGreater"
116case NotUnordered:
117return "NotUnordered"
118
119// 4-bit mask
120case Always:
121return "Always"
122}
123
124// invalid
125return fmt.Sprintf("Invalid (%#x)", c)
126}
127