1 : /*
2 : * Copyright 2012 The Native Client Authors. All rights reserved.
3 : * Use of this source code is governed by a BSD-style license that can
4 : * be found in the LICENSE file.
5 : * Copyright 2012, Google Inc.
6 : */
7 :
8 : #ifndef NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_MIPS_MODEL_INL_H
9 : #define NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_MIPS_MODEL_INL_H
10 : /*
11 : * Inline definitions for the classes defined in model.h
12 : */
13 :
14 : namespace nacl_mips_dec {
15 :
16 1089 : Register::Register(uint32_t number) : _number(number) {}
17 165 : uint32_t Register::Bitmask() const {
18 165 : if (_number == 31) return 0;
19 :
20 163 : return (1 << _number);
21 : }
22 :
23 474 : bool Register::Equals(const Register &other) const {
24 474 : return _number == other._number;
25 : }
26 :
27 20 : RegisterList::RegisterList(uint32_t bits) : _bits(bits) {}
28 134 : RegisterList::RegisterList(Register reg) : _bits(reg.Bitmask()) {}
29 :
30 31 : bool RegisterList::operator[](Register reg) const {
31 31 : return _bits & reg.Bitmask();
32 : }
33 :
34 16 : bool RegisterList::ContainsAll(const RegisterList other) const {
35 16 : return (_bits & other._bits) == other._bits;
36 : }
37 :
38 118 : bool RegisterList::ContainsAny(const RegisterList other) const {
39 118 : return _bits & other._bits;
40 : }
41 :
42 : const RegisterList RegisterList::operator&(const RegisterList other) const {
43 : return RegisterList(_bits & other._bits);
44 : }
45 :
46 308 : inline Instruction::Instruction(uint32_t bits) : _bits(bits) {}
47 :
48 614 : inline uint32_t Instruction::Bits(int hi, int lo) const {
49 614 : uint32_t right_justified = _bits >> lo;
50 614 : int bit_count = hi - lo + 1;
51 614 : uint32_t mask = (1 << bit_count) - 1;
52 614 : return right_justified & mask;
53 : }
54 :
55 547 : inline const Register Instruction::Reg(int hi, int lo) const {
56 547 : return Register(Bits(hi, lo));
57 : }
58 :
59 : inline bool Instruction::Bit(int index) const {
60 : return (_bits >> index) & 1;
61 : }
62 :
63 2266 : inline uint32_t Instruction::operator&(uint32_t mask) const {
64 2266 : return _bits & mask;
65 : }
66 :
67 : } // namespace
68 :
69 : #endif // NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_MIPS_MODEL_INL_H
|