Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(250)

Side by Side Diff: src/trusted/validator_arm/address_set.cc

Issue 7799013: Intial Thumb2 Sandbox (naclrev 6680) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client
Patch Set: fix thumb2 vs build_arm_thumb2 Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright 2009 The Native Client Authors. All rights reserved. 2 * Copyright 2009 The Native Client Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can 3 * Use of this source code is governed by a BSD-style license that can
4 * be found in the LICENSE file. 4 * be found in the LICENSE file.
5 * Copyright 2009, Google Inc. 5 * Copyright 2009, Google Inc.
6 */ 6 */
7 7
8 #include "native_client/src/trusted/validator_arm/address_set.h" 8 #include "native_client/src/trusted/validator_arm/address_set.h"
9 #include <stdio.h> 9 #include <stdio.h>
10 #include <string.h> 10 #include <string.h>
11 11
12 #define ADDRFACTOR sizeof(uint16_t)
13
12 namespace nacl_arm_val { 14 namespace nacl_arm_val {
13 15
14 AddressSet::AddressSet(uint32_t base, uint32_t size) 16 AddressSet::AddressSet(uint32_t base, uint32_t size)
Karl 2011/08/30 19:53:52 There appears to be inconsistencies between sizes.
15 : base_(base), size_(size), bits_(new uint32_t[(size + 3) / 4]) { 17 : base_(base), size_(size), bits_(new uint32_t[(size + 3) / ADDRFACTOR]) {
Karl 2011/08/30 19:53:52 Isn't 3 based on ADDRFACTOR?
16 memset(bits_, 0, sizeof(uint32_t) * ((size + 3) / 4)); 18 memset(bits_, 0, sizeof(uint32_t) * ((size + 3) / ADDRFACTOR));
17 } 19 }
18 20
19 AddressSet::~AddressSet() { 21 AddressSet::~AddressSet() {
20 delete[] bits_; 22 delete[] bits_;
21 } 23 }
22 24
23 void AddressSet::add(uint32_t address) { 25 void AddressSet::add(uint32_t address) {
24 if ((address - base_) < size_) { 26 if ((address - base_) < size_) {
25 uint32_t word_address = (address - base_) / sizeof(uint32_t); 27 uint32_t word_address = (address - base_) / ADDRFACTOR;
26 28
27 bits_[word_address / 32] |= 1 << (word_address % 32); 29 bits_[word_address / 32] |= 1 << (word_address % 32);
Karl 2011/08/30 19:53:52 Doesn't 32 conflict with size of ADDRFACTOR?
28 } 30 }
29 } 31 }
30 32
31 bool AddressSet::contains(uint32_t address) const { 33 bool AddressSet::contains(uint32_t address) const {
32 if ((address - base_) < size_) { 34 if ((address - base_) < size_) {
33 uint32_t word_address = (address - base_) / sizeof(uint32_t); 35 uint32_t word_address = (address - base_) / ADDRFACTOR;
34 36
35 return bits_[word_address / 32] & (1 << (word_address % 32)); 37 return bits_[word_address / 32] & (1 << (word_address % 32));
Karl 2011/08/30 19:53:52 Again, is 32 consistent with ADDRFACTOR?
36 } else { 38 } else {
37 return false; 39 return false;
38 } 40 }
39 } 41 }
40 42
41 AddressSet::Iterator AddressSet::begin() const { 43 AddressSet::Iterator AddressSet::begin() const {
42 return Iterator(*this, 0, 0); 44 return Iterator(*this, 0, 0);
43 } 45 }
44 46
45 AddressSet::Iterator AddressSet::end() const { 47 AddressSet::Iterator AddressSet::end() const {
46 return Iterator(*this, (size_ + 3) / 4, 0); 48 return Iterator(*this, (size_ + 3) / 4, 0);
Karl 2011/08/30 19:53:52 Is 4 supposed to be ADDRFACTOR (to match size allo
47 } 49 }
48 50
49 AddressSet::Iterator::Iterator(const AddressSet &parent, 51 AddressSet::Iterator::Iterator(const AddressSet &parent,
50 uint32_t index, 52 uint32_t index,
51 uint32_t shift) 53 uint32_t shift)
52 : parent_(parent), index_(index), shift_(shift) { 54 : parent_(parent), index_(index), shift_(shift) {
53 advance(); 55 advance();
54 } 56 }
55 57
56 AddressSet::Iterator &AddressSet::Iterator::operator++() { 58 AddressSet::Iterator &AddressSet::Iterator::operator++() {
57 shift_++; // Skip the current bit, if any, and 59 shift_++; // Skip the current bit, if any, and
58 advance(); // seek to the next 1 bit. 60 advance(); // seek to the next 1 bit.
59 return *this; 61 return *this;
60 } 62 }
61 63
62 bool AddressSet::Iterator::operator!=(const AddressSet::Iterator &other) const { 64 bool AddressSet::Iterator::operator!=(const AddressSet::Iterator &other) const {
63 return index_ != other.index_ || shift_ != other.shift_; 65 return index_ != other.index_ || shift_ != other.shift_;
64 } 66 }
65 67
66 uint32_t AddressSet::Iterator::operator*() const { 68 uint32_t AddressSet::Iterator::operator*() const {
67 return parent_.base_ + 4 * ((index_ * 32) + shift_); 69 return parent_.base_ + ADDRFACTOR * ((index_ * 32) + shift_);
68 } 70 }
69 71
70 void AddressSet::Iterator::advance() { 72 void AddressSet::Iterator::advance() {
71 uint32_t max_index = (parent_.size_ + 3) / 4; 73 uint32_t max_index = (parent_.size_ + 3) / ADDRFACTOR;
bsy 2011/09/01 00:30:00 s/3/(ADDRFACTOR-1)/?
jasonwkim 2011/09/16 20:09:16 Done
72 74
73 for (; index_ < max_index; index_++) { 75 for (; index_ < max_index; index_++) {
74 uint32_t word = (shift_ > 31)? 0 : parent_.bits_[index_] >> shift_; 76 uint32_t word = (shift_ > 31)? 0 : parent_.bits_[index_] >> shift_;
Karl 2011/08/30 19:53:52 Does this conflict with ADDRFACTOR value?
75 while (word) { 77 while (word) {
76 if (word & 1) return; 78 if (word & 1) return;
77 79
78 // A meager optimization for sparse words 80 // A meager optimization for sparse words
79 if (!(word & 0xFFFF)) { 81 if (!(word & 0xFFFF)) {
80 word >>= 16; 82 word >>= 16;
81 shift_ += 16; 83 shift_ += 16;
82 } else if (!(word & 0xFF)) { 84 } else if (!(word & 0xFF)) {
83 word >>= 8; 85 word >>= 8;
84 shift_ += 8; 86 shift_ += 8;
85 } else { 87 } else {
86 word >>= 1; 88 word >>= 1;
87 shift_++; 89 shift_++;
88 } 90 }
89 } 91 }
90 shift_ = 0; 92 shift_ = 0;
91 } 93 }
92 } 94 }
93 95
94 } // namespace 96 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698