OLD | NEW |
(Empty) | |
| 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 Register::Register(uint32_t number) : _number(number) {} |
| 17 uint32_t Register::Bitmask() const { |
| 18 if (_number == 31) return 0; |
| 19 |
| 20 return (1 << _number); |
| 21 } |
| 22 |
| 23 bool Register::Equals(const Register &other) const { |
| 24 return _number == other._number; |
| 25 } |
| 26 |
| 27 RegisterList::RegisterList(uint32_t bits) : _bits(bits) {} |
| 28 RegisterList::RegisterList(Register reg) : _bits(reg.Bitmask()) {} |
| 29 |
| 30 bool RegisterList::operator[](Register reg) const { |
| 31 return _bits & reg.Bitmask(); |
| 32 } |
| 33 |
| 34 bool RegisterList::ContainsAll(const RegisterList other) const { |
| 35 return (_bits & other._bits) == other._bits; |
| 36 } |
| 37 |
| 38 bool RegisterList::ContainsAny(const RegisterList other) const { |
| 39 return _bits & other._bits; |
| 40 } |
| 41 |
| 42 const RegisterList RegisterList::operator&(const RegisterList other) const { |
| 43 return RegisterList(_bits & other._bits); |
| 44 } |
| 45 |
| 46 inline Instruction::Instruction(uint32_t bits) : _bits(bits) {} |
| 47 |
| 48 inline uint32_t Instruction::Bits(int hi, int lo) const { |
| 49 uint32_t right_justified = _bits >> lo; |
| 50 int bit_count = hi - lo + 1; |
| 51 uint32_t mask = (1 << bit_count) - 1; |
| 52 return right_justified & mask; |
| 53 } |
| 54 |
| 55 inline const Register Instruction::Reg(int hi, int lo) const { |
| 56 return Register(Bits(hi, lo)); |
| 57 } |
| 58 |
| 59 inline bool Instruction::Bit(int index) const { |
| 60 return (_bits >> index) & 1; |
| 61 } |
| 62 |
| 63 inline uint32_t Instruction::operator&(uint32_t mask) const { |
| 64 return _bits & mask; |
| 65 } |
| 66 |
| 67 } // namespace |
| 68 |
| 69 #endif // NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_MIPS_MODEL_INL_H |
OLD | NEW |