summaryrefslogtreecommitdiff
path: root/vendor/github.com/tetratelabs/wazero/internal/engine/wazevo/ssa/cmp.go
blob: 15b62ca8ee46771ea0469062cb0b41a75487fe52 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package ssa

// IntegerCmpCond represents a condition for integer comparison.
type IntegerCmpCond byte

const (
	// IntegerCmpCondInvalid represents an invalid condition.
	IntegerCmpCondInvalid IntegerCmpCond = iota
	// IntegerCmpCondEqual represents "==".
	IntegerCmpCondEqual
	// IntegerCmpCondNotEqual represents "!=".
	IntegerCmpCondNotEqual
	// IntegerCmpCondSignedLessThan represents Signed "<".
	IntegerCmpCondSignedLessThan
	// IntegerCmpCondSignedGreaterThanOrEqual represents Signed ">=".
	IntegerCmpCondSignedGreaterThanOrEqual
	// IntegerCmpCondSignedGreaterThan represents Signed ">".
	IntegerCmpCondSignedGreaterThan
	// IntegerCmpCondSignedLessThanOrEqual represents Signed "<=".
	IntegerCmpCondSignedLessThanOrEqual
	// IntegerCmpCondUnsignedLessThan represents Unsigned "<".
	IntegerCmpCondUnsignedLessThan
	// IntegerCmpCondUnsignedGreaterThanOrEqual represents Unsigned ">=".
	IntegerCmpCondUnsignedGreaterThanOrEqual
	// IntegerCmpCondUnsignedGreaterThan represents Unsigned ">".
	IntegerCmpCondUnsignedGreaterThan
	// IntegerCmpCondUnsignedLessThanOrEqual represents Unsigned "<=".
	IntegerCmpCondUnsignedLessThanOrEqual
)

// String implements fmt.Stringer.
func (i IntegerCmpCond) String() string {
	switch i {
	case IntegerCmpCondEqual:
		return "eq"
	case IntegerCmpCondNotEqual:
		return "neq"
	case IntegerCmpCondSignedLessThan:
		return "lt_s"
	case IntegerCmpCondSignedGreaterThanOrEqual:
		return "ge_s"
	case IntegerCmpCondSignedGreaterThan:
		return "gt_s"
	case IntegerCmpCondSignedLessThanOrEqual:
		return "le_s"
	case IntegerCmpCondUnsignedLessThan:
		return "lt_u"
	case IntegerCmpCondUnsignedGreaterThanOrEqual:
		return "ge_u"
	case IntegerCmpCondUnsignedGreaterThan:
		return "gt_u"
	case IntegerCmpCondUnsignedLessThanOrEqual:
		return "le_u"
	default:
		panic("invalid integer comparison condition")
	}
}

// Signed returns true if the condition is signed integer comparison.
func (i IntegerCmpCond) Signed() bool {
	switch i {
	case IntegerCmpCondSignedLessThan, IntegerCmpCondSignedGreaterThanOrEqual,
		IntegerCmpCondSignedGreaterThan, IntegerCmpCondSignedLessThanOrEqual:
		return true
	default:
		return false
	}
}

type FloatCmpCond byte

const (
	// FloatCmpCondInvalid represents an invalid condition.
	FloatCmpCondInvalid FloatCmpCond = iota
	// FloatCmpCondEqual represents "==".
	FloatCmpCondEqual
	// FloatCmpCondNotEqual represents "!=".
	FloatCmpCondNotEqual
	// FloatCmpCondLessThan represents "<".
	FloatCmpCondLessThan
	// FloatCmpCondLessThanOrEqual represents "<=".
	FloatCmpCondLessThanOrEqual
	// FloatCmpCondGreaterThan represents ">".
	FloatCmpCondGreaterThan
	// FloatCmpCondGreaterThanOrEqual represents ">=".
	FloatCmpCondGreaterThanOrEqual
)

// String implements fmt.Stringer.
func (f FloatCmpCond) String() string {
	switch f {
	case FloatCmpCondEqual:
		return "eq"
	case FloatCmpCondNotEqual:
		return "neq"
	case FloatCmpCondLessThan:
		return "lt"
	case FloatCmpCondLessThanOrEqual:
		return "le"
	case FloatCmpCondGreaterThan:
		return "gt"
	case FloatCmpCondGreaterThanOrEqual:
		return "ge"
	default:
		panic("invalid float comparison condition")
	}
}