Skip to content

Commit

Permalink
Switch to standard integer types in courgette/.
Browse files Browse the repository at this point in the history
BUG=138542
TBR=wfh@chromium.org
NOPRESUBMIT=true

Review URL: https://codereview.chromium.org/1543643002

Cr-Commit-Position: refs/heads/master@{#366439}
  • Loading branch information
avi authored and Commit bot committed Dec 21, 2015
1 parent 3431848 commit ab98dcc
Show file tree
Hide file tree
Showing 65 changed files with 797 additions and 664 deletions.
46 changes: 24 additions & 22 deletions courgette/adjustment_method.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@

#include "courgette/adjustment_method.h"

#include <stddef.h>
#include <stdint.h>

#include <algorithm>
#include <list>
#include <map>
#include <set>
#include <string>
#include <vector>

#include "base/basictypes.h"
#include "base/logging.h"
#include "base/macros.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
#include "courgette/assembly_program.h"
Expand Down Expand Up @@ -41,10 +44,10 @@ class LabelInfo {
Label* label_; // The label that this info a surrogate for.

// Information used only in debugging messages.
uint32 is_model_ : 1; // Is the label in the model?
uint32 debug_index_ : 31; // An unique small number for naming the label.
uint32_t is_model_ : 1; // Is the label in the model?
uint32_t debug_index_ : 31; // An unique small number for naming the label.

uint32 refs_; // Number of times this Label is referenced.
uint32_t refs_; // Number of times this Label is referenced.

LabelInfo* assignment_; // Label from other program corresponding to this.

Expand All @@ -53,7 +56,7 @@ class LabelInfo {
LabelInfo* next_addr_; // Label(Info) at next highest address.
LabelInfo* prev_addr_; // Label(Info) at next lowest address.

std::vector<uint32> positions_; // Offsets into the trace of references.
std::vector<uint32_t> positions_; // Offsets into the trace of references.

// Just a no-argument constructor and copy constructor. Actual LabelInfo
// objects are allocated in std::pair structs in a std::map.
Expand Down Expand Up @@ -149,9 +152,7 @@ struct Node {
bool in_queue_;
bool Extended() const { return !edges_.empty(); }

uint32 Weight() const {
return edges_in_frequency_order.front()->count_;
}
uint32_t Weight() const { return edges_in_frequency_order.front()->count_; }
};

static std::string ToString(Node* node) {
Expand Down Expand Up @@ -190,8 +191,8 @@ struct OrderNodeByWeightDecreasing {
bool operator()(Node* a, Node* b) const {
// (Maybe tie-break on total count, followed by lowest assigned node indexes
// in path.)
uint32 a_weight = a->Weight();
uint32 b_weight = b->Weight();
uint32_t a_weight = a->Weight();
uint32_t b_weight = b->Weight();
if (a_weight != b_weight)
return a_weight > b_weight;
if (a->length_ != b->length_)
Expand Down Expand Up @@ -254,7 +255,7 @@ class AssignmentProblem {

void SkipCommittedLabels(Node* node) {
ExtendNode(node, p_trace_);
uint32 skipped = 0;
uint32_t skipped = 0;
while (!node->edges_in_frequency_order.empty() &&
node->edges_in_frequency_order.front()->in_edge_->assignment_) {
++skipped;
Expand Down Expand Up @@ -421,9 +422,9 @@ class AssignmentProblem {
}
}

uint32 TryExtendSequence(uint32 p_pos_start, uint32 m_pos_start) {
uint32 p_pos = p_pos_start + 1;
uint32 m_pos = m_pos_start + 1;
uint32_t TryExtendSequence(uint32_t p_pos_start, uint32_t m_pos_start) {
uint32_t p_pos = p_pos_start + 1;
uint32_t m_pos = m_pos_start + 1;

while (p_pos < p_trace_.size() && m_pos < m_trace_.size()) {
LabelInfo* p_info = p_trace_[p_pos];
Expand Down Expand Up @@ -456,12 +457,13 @@ class AssignmentProblem {
return p_pos - p_pos_start;
}

uint32 TryExtendSequenceBackwards(uint32 p_pos_start, uint32 m_pos_start) {
uint32_t TryExtendSequenceBackwards(uint32_t p_pos_start,
uint32_t m_pos_start) {
if (p_pos_start == 0 || m_pos_start == 0)
return 0;

uint32 p_pos = p_pos_start - 1;
uint32 m_pos = m_pos_start - 1;
uint32_t p_pos = p_pos_start - 1;
uint32_t m_pos = m_pos_start - 1;

while (p_pos > 0 && m_pos > 0) {
LabelInfo* p_info = p_trace_[p_pos];
Expand Down Expand Up @@ -522,7 +524,7 @@ class AssignmentProblem {
Node* MakeRootNode(const Trace& trace) {
Node* node = new Node(NULL, NULL);
all_nodes_.push_back(node);
for (uint32 i = 0; i < trace.size(); ++i) {
for (uint32_t i = 0; i < trace.size(); ++i) {
++node->count_;
node->places_.push_back(i);
}
Expand All @@ -534,7 +536,7 @@ class AssignmentProblem {
if (node->Extended())
return;
for (size_t i = 0; i < node->places_.size(); ++i) {
uint32 index = node->places_.at(i);
uint32_t index = node->places_.at(i);
if (index < trace.size()) {
LabelInfo* item = trace.at(index);
Node*& slot = node->edges_[item];
Expand Down Expand Up @@ -633,11 +635,11 @@ class GraphAdjuster : public AdjustmentMethod {
}

void ReferenceLabel(Trace* trace, Label* label, bool is_model) {
trace->push_back(MakeLabelInfo(label, is_model,
static_cast<uint32>(trace->size())));
trace->push_back(
MakeLabelInfo(label, is_model, static_cast<uint32_t>(trace->size())));
}

LabelInfo* MakeLabelInfo(Label* label, bool is_model, uint32 position) {
LabelInfo* MakeLabelInfo(Label* label, bool is_model, uint32_t position) {
LabelInfo& slot = label_infos_[label];
if (slot.label_ == NULL) {
slot.label_ = label;
Expand Down
2 changes: 1 addition & 1 deletion courgette/adjustment_method.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#ifndef COURGETTE_ADJUSTMENT_METHOD_H_
#define COURGETTE_ADJUSTMENT_METHOD_H_

#include "base/basictypes.h"
#include "base/macros.h"

namespace courgette {

Expand Down
62 changes: 32 additions & 30 deletions courgette/adjustment_method_2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

#include "courgette/adjustment_method.h"

#include <stddef.h>
#include <stdint.h>

#include <algorithm>
#include <limits>
#include <list>
Expand All @@ -12,9 +15,9 @@
#include <string>
#include <vector>

#include "base/basictypes.h"
#include "base/format_macros.h"
#include "base/logging.h"
#include "base/macros.h"
#include "base/strings/stringprintf.h"
#include "base/time/time.h"
#include "courgette/assembly_program.h"
Expand Down Expand Up @@ -176,16 +179,16 @@ class LabelInfo {

Label* label_; // The label that this info a surrogate for.

uint32 is_model_ : 1; // Is the label in the model?
uint32 debug_index_ : 31; // A small number for naming the label in debug
// output. The pair (is_model_, debug_index_) is
// unique.
uint32_t is_model_ : 1; // Is the label in the model?
uint32_t debug_index_ : 31; // A small number for naming the label in debug
// output. The pair (is_model_, debug_index_) is
// unique.

int refs_; // Number of times this Label is referenced.

LabelInfo* assignment_; // Label from other program corresponding to this.

std::vector<uint32> positions_; // Offsets into the trace of references.
std::vector<uint32_t> positions_; // Offsets into the trace of references.

private:
AssignmentCandidates* candidates_;
Expand Down Expand Up @@ -213,7 +216,7 @@ class LabelInfoMaker {
public:
LabelInfoMaker() : debug_label_index_gen_(0) {}

LabelInfo* MakeLabelInfo(Label* label, bool is_model, uint32 position) {
LabelInfo* MakeLabelInfo(Label* label, bool is_model, uint32_t position) {
LabelInfo& slot = label_infos_[label];
if (slot.label_ == NULL) {
slot.label_ = label;
Expand Down Expand Up @@ -364,7 +367,7 @@ LabelInfo::~LabelInfo() {
// position of one of the occurrences in the Trace.
class Shingle {
public:
static const uint8 kWidth = 5;
static const uint8_t kWidth = 5;

struct InterningLess {
bool operator()(const Shingle& a, const Shingle& b) const;
Expand All @@ -388,7 +391,7 @@ class Shingle {

LabelInfo* at(size_t i) const { return trace_[exemplar_position_ + i]; }
void add_position(size_t position) {
positions_.push_back(static_cast<uint32>(position));
positions_.push_back(static_cast<uint32_t>(position));
}
int position_count() const { return static_cast<int>(positions_.size()); }

Expand All @@ -414,7 +417,7 @@ class Shingle {

const Trace& trace_; // The shingle lives inside trace_.
size_t exemplar_position_; // At this position (and other positions).
std::vector<uint32> positions_; // Includes exemplar_position_.
std::vector<uint32_t> positions_; // Includes exemplar_position_.

ShinglePattern* pattern_; // Pattern changes as LabelInfos are assigned.

Expand All @@ -430,7 +433,7 @@ class Shingle {
std::string ToString(const Shingle* instance) {
std::string s;
const char* sep = "<";
for (uint8 i = 0; i < Shingle::kWidth; ++i) {
for (uint8_t i = 0; i < Shingle::kWidth; ++i) {
// base::StringAppendF(&s, "%s%x ", sep, instance.at(i)->label_->rva_);
s += sep;
s += ToString(instance->at(i));
Expand All @@ -446,7 +449,7 @@ std::string ToString(const Shingle* instance) {
bool Shingle::InterningLess::operator()(
const Shingle& a,
const Shingle& b) const {
for (uint8 i = 0; i < kWidth; ++i) {
for (uint8_t i = 0; i < kWidth; ++i) {
LabelInfo* info_a = a.at(i);
LabelInfo* info_b = b.at(i);
if (info_a->label_->rva_ < info_b->label_->rva_)
Expand Down Expand Up @@ -478,11 +481,11 @@ class ShinglePattern {
// --> <kFixed+0, kVariable+1, kFixed+2, kVariable+1, kFixed+0>
struct Index {
explicit Index(const Shingle* instance);
uint8 kinds_[Shingle::kWidth];
uint8 variables_;
uint8 unique_variables_;
uint8 first_variable_index_;
uint32 hash_;
uint8_t kinds_[Shingle::kWidth];
uint8_t variables_;
uint8_t unique_variables_;
uint8_t first_variable_index_;
uint32_t hash_;
int assigned_indexes_[Shingle::kWidth];
};

Expand Down Expand Up @@ -526,10 +529,10 @@ std::string ToString(const ShinglePattern::Index* index) {
} else {
base::StringAppendF(&s, "<%d: ", index->variables_);
const char* sep = "";
for (uint8 i = 0; i < Shingle::kWidth; ++i) {
for (uint8_t i = 0; i < Shingle::kWidth; ++i) {
s += sep;
sep = ", ";
uint32 kind = index->kinds_[i];
uint32_t kind = index->kinds_[i];
int offset = kind & ShinglePattern::kOffsetMask;
if (kind & ShinglePattern::kVariable)
base::StringAppendF(&s, "V%d", offset);
Expand Down Expand Up @@ -622,7 +625,7 @@ struct ShinglePatternIndexLess {
if (a.hash_ < b.hash_) return true;
if (a.hash_ > b.hash_) return false;

for (uint8 i = 0; i < Shingle::kWidth; ++i) {
for (uint8_t i = 0; i < Shingle::kWidth; ++i) {
if (a.kinds_[i] < b.kinds_[i]) return true;
if (a.kinds_[i] > b.kinds_[i]) return false;
if ((a.kinds_[i] & ShinglePattern::kVariable) == 0) {
Expand All @@ -636,22 +639,22 @@ struct ShinglePatternIndexLess {
}
};

static uint32 hash_combine(uint32 h, uint32 v) {
static uint32_t hash_combine(uint32_t h, uint32_t v) {
h += v;
return (h * (37 + 0x0000d100)) ^ (h >> 13);
}

ShinglePattern::Index::Index(const Shingle* instance) {
uint32 hash = 0;
uint32_t hash = 0;
variables_ = 0;
unique_variables_ = 0;
first_variable_index_ = 255;

for (uint8 i = 0; i < Shingle::kWidth; ++i) {
for (uint8_t i = 0; i < Shingle::kWidth; ++i) {
LabelInfo* info = instance->at(i);
uint8 kind = 0;
uint8_t kind = 0;
int code = -1;
uint8 j = 0;
uint8_t j = 0;
for ( ; j < i; ++j) {
if (info == instance->at(j)) { // Duplicate LabelInfo
kind = kinds_[j];
Expand Down Expand Up @@ -942,7 +945,7 @@ class AssignmentProblem {

// For the positions in |info|, find the shingles that overlap that position.
void AddAffectedPositions(LabelInfo* info, ShingleSet* affected_shingles) {
const uint8 kWidth = Shingle::kWidth;
const uint8_t kWidth = Shingle::kWidth;
for (size_t i = 0; i < info->positions_.size(); ++i) {
size_t position = info->positions_[i];
// Find bounds to the subrange of |trace_| we are in.
Expand Down Expand Up @@ -1059,7 +1062,7 @@ class AssignmentProblem {
// int score = p1; // ? weigh all equally??
int score = std::min(p1, m1);

for (uint8 i = 0; i < Shingle::kWidth; ++i) {
for (uint8_t i = 0; i < Shingle::kWidth; ++i) {
LabelInfo* program_info = program_instance->at(i);
LabelInfo* model_info = model_instance->at(i);
if ((model_info->assignment_ == NULL) !=
Expand Down Expand Up @@ -1275,9 +1278,8 @@ class Adjuster : public AdjustmentMethod {
}

void ReferenceLabel(Trace* trace, Label* label, bool is_model) {
trace->push_back(
label_info_maker_.MakeLabelInfo(label, is_model,
static_cast<uint32>(trace->size())));
trace->push_back(label_info_maker_.MakeLabelInfo(
label, is_model, static_cast<uint32_t>(trace->size())));
}

AssemblyProgram* prog_; // Program to be adjusted, owned by caller.
Expand Down
Loading

0 comments on commit ab98dcc

Please sign in to comment.