P4C
The P4 Compiler
Loading...
Searching...
No Matches
match.h
1/*
2 * SPDX-FileCopyrightText: 2013 Barefoot Networks, Inc.
3 * Copyright 2013-present Barefoot Networks, Inc.
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 */
7
8#ifndef LIB_MATCH_H_
9#define LIB_MATCH_H_
10
11#include <stdint.h>
12
13#include <iostream>
14
15#include "big_int_util.h"
16
17namespace P4 {
18
27struct match_t {
28 big_int word0, word1;
29 match_t() : word0(0), word1(0) {}
30 match_t(big_int w0, big_int w1) : word0(w0), word1(w1) {}
31 explicit operator bool() const { return (word0 | word1) != 0; }
32 bool operator==(const match_t &a) const { return word0 == a.word0 && word1 == a.word1; }
33 bool operator!=(const match_t &a) const { return word0 != a.word0 || word1 != a.word1; }
34 bool matches(big_int v) const {
35 return (v | word1) == word1 && ((~v & word1) | word0) == word0;
36 }
37 void setwidth(int bits) {
38 big_int mask = (big_int(1) << bits) - 1;
39 word0 &= mask;
40 word1 &= mask;
41 mask &= ~(word0 | word1);
42 word0 |= mask;
43 word1 |= mask;
44 }
45 match_t(int size, big_int val, big_int mask) : word0(~val & mask), word1(val & mask) {
46 setwidth(size);
47 }
48 static match_t dont_care(int size) { return match_t(size, 0, 0); }
49};
50
51std::ostream &operator<<(std::ostream &, const match_t &);
52bool operator>>(const char *, match_t &);
53
54} // namespace P4
55
56#endif /* LIB_MATCH_H_ */
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:13
Definition match.h:27