Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #114

Open
wants to merge 24 commits into
base: dev
Choose a base branch
from
Open

Dev #114

Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
e8c0df8
warning --
ThomasRetornaz Feb 26, 2018
d70bbc3
fix TestData& operator=(const TestData& other) assignment operator
ThomasRetornaz Feb 26, 2018
8d91b7e
wip issue #107 add transform/reduce algorithm
ThomasRetornaz Feb 26, 2018
c679f81
issue #107 add fill,copy,copy_n algorithm
ThomasRetornaz Feb 26, 2018
4bc2c63
issue #107 gcc compil fix
Feb 28, 2018
22e5357
issue #107 add search max/min
ThomasRetornaz Mar 5, 2018
5c48da0
issue #107 add find,find_if,find_if_not
ThomasRetornaz Mar 5, 2018
ab3e92b
issue #107 fix gcc and release mode for find*
Mar 5, 2018
b0735f5
issue #107 add max_element and min_element
ThomasRetornaz Mar 6, 2018
0025a8f
issue #107 gcc compil/warning fix
Mar 6, 2018
ae48025
issue #107 add count, count_if
ThomasRetornaz Mar 7, 2018
c8d12f4
Merge branch 'dev' of https://github.com/ThomasRetornaz/libsimdpp int…
ThomasRetornaz Mar 7, 2018
dc33d00
issue #107 add all_of, any_of, none_of
Mar 7, 2018
d6a6bfa
issue #107 add replace,replace_if
Mar 8, 2018
f95aa05
issue #107 add equal and lexicographic_compare
Mar 10, 2018
b8b0b34
issue #107 add transform_reduce
Mar 11, 2018
179cc90
issue #107 ras
Mar 11, 2018
f57deb0
issue #107 visual compilation fix
ThomasRetornaz Mar 11, 2018
3d9fb98
issue #107
ThomasRetornaz Apr 9, 2018
d8b2eda
issue #107 gcc and c++11 only compil fix
Apr 9, 2018
9a3636a
issue #107
ThomasRetornaz Apr 11, 2018
6ae2a4a
issue #115 Proof of concept
ThomasRetornaz Jul 16, 2018
5977ee9
#issue 115 linux/gcc fix
Jul 20, 2018
e286519
* warn --
ThomasRetornaz Oct 26, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions simdpp/dispatch/dispatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ struct FnVersion {
const char* arch_name;
};

inline FnVersion select_version_any(FnVersion* versions, unsigned size,
inline FnVersion select_version_any(FnVersion* versions, std::size_t size,
Arch arch)
{
// No need to try to be very efficient here.
Expand All @@ -76,7 +76,7 @@ inline FnVersion select_version_any(FnVersion* versions, unsigned size,
return lhs.needed_arch > rhs.needed_arch;
});

unsigned i;
std::size_t i;
for (i = 0; i < size; ++i) {
if (versions[i].fun_ptr == nullptr)
continue;
Expand Down
6 changes: 3 additions & 3 deletions simdpp/dispatch/get_arch_string_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ inline Arch get_arch_string_list(const char* const strings[], int count, const c
return res;
#endif

int prefixlen = std::strlen(prefix);
for (int i = 0; i < count; ++i) {
auto prefixlen = std::strlen(prefix);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer the explicit type for the simple numeric types. Auto makes the code less readable in these cases.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK use size_t instead

for (auto i = 0; i < count; ++i) {
const char* s = *strings++;
int len = std::strlen(s);
auto len = std::strlen(s);

// check if s matches prefix
if (len < prefixlen)
Expand Down
76 changes: 38 additions & 38 deletions test/utils/test_results_set.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ TestResultsSet::TestResultsSet(const char* name) :
reset_seq();
}

TestResultsSet::Result& TestResultsSet::push(ElementType type, unsigned length,
const char* file, unsigned line)
TestResultsSet::Result& TestResultsSet::push(ElementType type, std::size_t length,
const char* file, std::size_t line)
{
results_.emplace_back(type, length, element_size_for_type(type), file, line,
seq_++, curr_precision_ulp_, curr_fp_zero_equal_);
return results_.back();
}

unsigned precision_for_result(const TestResultsSet::Result& res)
std::size_t precision_for_result(const TestResultsSet::Result& res)
{
switch (res.type) {
case TYPE_FLOAT32:
Expand All @@ -48,13 +48,13 @@ template<> struct fix_char_type<uint8_t> { using type = int; };
template<> struct fix_char_type<int8_t> { using type = int; };

template<class T>
void print_hex(std::ostream& err, unsigned num_elems, unsigned width,
void print_hex(std::ostream& err, std::size_t num_elems, std::size_t width,
const T* p)
{
static_assert(std::is_unsigned<T>::value, "T must be unsigned");
err << "[ " << std::hex << std::setfill('0');
err.precision(width);
for (unsigned i = 0; i < num_elems; i++, p++) {
for (std::size_t i = 0; i < num_elems; i++, p++) {
err << std::setw(width*2) << uint64_t(*p);
if (i != num_elems - 1) {
err << " ; ";
Expand All @@ -65,12 +65,12 @@ void print_hex(std::ostream& err, unsigned num_elems, unsigned width,
}

template<class T>
void print_numeric(std::ostream& err, unsigned num_elems, unsigned precision,
void print_numeric(std::ostream& err, std::size_t num_elems, std::size_t precision,
const T* p)
{
err << "[ ";
err.precision(precision);
for (unsigned i = 0; i < num_elems; i++, p++) {
for (std::size_t i = 0; i < num_elems; i++, p++) {
err << typename fix_char_type<T>::type(*p);
if (i != num_elems - 1) {
err << " ; ";
Expand All @@ -80,7 +80,7 @@ void print_numeric(std::ostream& err, unsigned num_elems, unsigned precision,
err << std::dec;
}

void print_vector_hex(std::ostream& out, ElementType type, unsigned num_elems,
void print_vector_hex(std::ostream& out, ElementType type, std::size_t num_elems,
const void* data)
{
switch (type) {
Expand Down Expand Up @@ -118,7 +118,7 @@ void print_vector_hex(std::ostream& out, ElementType type, unsigned num_elems,
}

void print_vector_numeric(std::ostream& out, ElementType type,
unsigned num_elems, const void* data)
std::size_t num_elems, const void* data)
{
switch (type) {
case TYPE_UINT8:
Expand Down Expand Up @@ -171,7 +171,7 @@ const char* vector_type_to_str(ElementType type)
}
}

void print_data_diff(std::ostream& out, ElementType type, unsigned num_elems,
void print_data_diff(std::ostream& out, ElementType type, std::size_t num_elems,
const void* data_a, const void* data_b)
{
out << "type: " << vector_type_to_str(type)
Expand Down Expand Up @@ -202,7 +202,7 @@ void print_file_info(std::ostream& out, const char* file)
out << " In file \"" << file << "\" :\n";
}

void print_file_info(std::ostream& out, const char* file, unsigned line)
void print_file_info(std::ostream& out, const char* file, std::size_t line)
{
if (file == nullptr) {
file = "<unknown>";
Expand All @@ -220,12 +220,12 @@ void print_test_case_name(std::ostream& out, const char* name)
out << " In test case \"" << name << "\" :\n";
}

void print_seq_num(std::ostream& out, unsigned num)
void print_seq_num(std::ostream& out, std::size_t num)
{
out << " Sequence number: " << num << "\n";
}

void print_precision(std::ostream& out, unsigned prec)
void print_precision(std::ostream& out, std::size_t prec)
{
if (prec > 0) {
out << " Precision: " << prec << "ULP\n";
Expand Down Expand Up @@ -304,10 +304,10 @@ T nextafter_ulps(T from, T to)

// T is either double or float
template<class T>
bool cmpeq_arrays(const T* a, const T* b, unsigned num_elems,
unsigned prec, bool zero_eq)
bool cmpeq_arrays(const T* a, const T* b, std::size_t num_elems,
std::size_t prec, bool zero_eq)
{
for (unsigned i = 0; i < num_elems; i++) {
for (std::size_t i = 0; i < num_elems; i++) {
// we need to be extra-precise here. nextafter is used because it won't
// introduce any rounding errors
T ia = *a++;
Expand All @@ -318,7 +318,7 @@ bool cmpeq_arrays(const T* a, const T* b, unsigned num_elems,
if (zero_eq && is_zero_or_neg_zero(ia) && is_zero_or_neg_zero(ib)) {
continue;
}
for (unsigned i = 0; i < prec; i++) {
for (std::size_t i = 0; i < prec; i++) {
ia = nextafter_ulps(ia, ib);
}
if (std::memcmp(&ia, &ib, sizeof(ia)) != 0) {
Expand All @@ -345,12 +345,12 @@ const char* get_filename_from_results_set(const TestResultsSet& a,
}

struct TestSequence {
unsigned begin_index, end_index;
std::size_t begin_index, end_index;
const char* begin_file;
// For comparisons we want to strip the arch suffix from the file name.
// To reduce the number of duplicate computations it is cached here.
std::string begin_file_stripped;
unsigned begin_line;
std::size_t begin_line;
};

bool is_test_seq_from_same_test(const TestSequence& a, const TestSequence& b)
Expand All @@ -370,25 +370,25 @@ using TestSequenceList = std::vector<TestSequence>;

Returns true if test results were skipped, false otherwise.
*/
bool skip_results_until_same_test(unsigned& ia, unsigned& ib,
bool skip_results_until_same_test(std::size_t& ia, std::size_t& ib,
const TestSequenceList& a,
const TestSequenceList& b)
{
if (is_test_seq_from_same_test(a[ia], b[ib]))
return false;
unsigned max_skipped = a.size() - ia + b.size() - ib;
auto max_skipped = a.size() - ia + b.size() - ib;

// This problem is solved by brute force as the number of skipped sequences
// is very likely small. We evaluate all possible ways to skip sequences
// starting with the smallest total number of skipped sequences.
for (unsigned num_skipped = 1; num_skipped < max_skipped; ++num_skipped) {
for (auto num_skipped = 1; num_skipped < max_skipped; ++num_skipped) {

for (unsigned i = 0; i <= num_skipped; ++i) {
unsigned skip_from_a = i;
unsigned skip_from_b = num_skipped - i;
for (auto i = 0; i <= num_skipped; ++i) {
auto skip_from_a = i;
auto skip_from_b = num_skipped - i;

unsigned new_ia = ia + skip_from_a;
unsigned new_ib = ib + skip_from_b;
auto new_ia = ia + skip_from_a;
auto new_ib = ib + skip_from_b;

if (new_ia < a.size() && new_ib < b.size()) {
if (is_test_seq_from_same_test(a[new_ia], b[new_ib])) {
Expand Down Expand Up @@ -424,12 +424,12 @@ TestSequenceList build_test_sequences(const std::vector<TestResultsSet::Result>&

TestSequence next_seq;

unsigned i = 0;
std::size_t i = 0;
next_seq.begin_index = i;
next_seq.begin_file = results[i].file;
next_seq.begin_file_stripped = strip_arch_suffix_from_file(results[i].file);
next_seq.begin_line = results[i].line;
unsigned last_seq_num = results[i].seq;
auto last_seq_num = results[i].seq;

++i;

Expand All @@ -453,7 +453,7 @@ TestSequenceList build_test_sequences(const std::vector<TestResultsSet::Result>&
}

bool cmpeq_result(const TestResultsSet::Result& ia, const TestResultsSet::Result& ib,
unsigned fp_prec, bool fp_zero_eq)
std::size_t fp_prec, bool fp_zero_eq)
{
if (std::memcmp(ia.d(), ib.d(), ia.el_size * ia.length) == 0) {
return true;
Expand Down Expand Up @@ -491,8 +491,8 @@ void report_test_comparison(const TestResultsSet& a, const char* a_arch,
TestSequenceList b_seqs = build_test_sequences(b.results());

// Compare results
unsigned ia_seq = 0;
unsigned ib_seq = 0;
std::size_t ia_seq = 0u;
std::size_t ib_seq = 0u;

while (ia_seq < a_seqs.size() && ib_seq < b_seqs.size()) {
if (skip_results_until_same_test(ia_seq, ib_seq, a_seqs, b_seqs)) {
Expand All @@ -502,8 +502,8 @@ void report_test_comparison(const TestResultsSet& a, const char* a_arch,
const auto& a_seq = a_seqs[ia_seq];
const auto& b_seq = b_seqs[ib_seq];

unsigned a_seq_size = a_seq.end_index - a_seq.begin_index;
unsigned b_seq_size = b_seq.end_index - b_seq.begin_index;
std::size_t a_seq_size = a_seq.end_index - a_seq.begin_index;
std::size_t b_seq_size = b_seq.end_index - b_seq.begin_index;

if (a_seq_size != b_seq_size) {
print_separator(tr.out());
Expand All @@ -522,9 +522,9 @@ void report_test_comparison(const TestResultsSet& a, const char* a_arch,
return;
}

for (unsigned i = 0; i < a_seq_size; ++i) {
unsigned ia = a_seq.begin_index + i;
unsigned ib = b_seq.begin_index + i;
for (auto i = 0; i < a_seq_size; ++i) {
auto ia = a_seq.begin_index + i;
auto ib = b_seq.begin_index + i;

const auto& a_res = a.results()[ia];
const auto& b_res = b.results()[ib];
Expand Down Expand Up @@ -573,7 +573,7 @@ void report_test_comparison(const TestResultsSet& a, const char* a_arch,
return;
}

unsigned prec = std::max(precision_for_result(a_res),
std::size_t prec = std::max(precision_for_result(a_res),
precision_for_result(b_res));

bool fp_zero_eq = a_res.fp_zero_eq || b_res.fp_zero_eq;
Expand Down
36 changes: 18 additions & 18 deletions test/utils/test_results_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@
#include "element_type.h"

// Prints two vectors side by side for comparison
void print_data_diff(std::ostream& out, ElementType type, unsigned num_elems,
void print_data_diff(std::ostream& out, ElementType type, std::size_t num_elems,
const void* data_a, const void* data_b);

void print_separator(std::ostream& out);
void print_file_info(std::ostream& out, const char* file);
void print_file_info(std::ostream& out, const char* file, unsigned line);
void print_file_info(std::ostream& out, const char* file, std::size_t line);

void print_vector_hex(std::ostream& out, ElementType type, unsigned num_elems,
void print_vector_hex(std::ostream& out, ElementType type, std::size_t num_elems,
const void* data);

void print_vector_numeric(std::ostream& out, ElementType type,
unsigned num_elems, const void* data);
std::size_t num_elems, const void* data);

/** The class represents test results for certain instruction set. We later
compare the results with other instruction sets and assume that all
Expand All @@ -40,11 +40,11 @@ class TestResultsSet {

// Holds one result vector
struct Result {
static const unsigned num_bytes = 32;
static const std::size_t num_bytes = 32;

Result(ElementType atype, unsigned alength, unsigned ael_size,
const char* afile, unsigned aline, unsigned aseq,
unsigned aprec_ulp, bool afp_zero_eq)
Result(ElementType atype, std::size_t alength, std::size_t ael_size,
const char* afile, std::size_t aline, std::size_t aseq,
std::size_t aprec_ulp, bool afp_zero_eq)
{
type = atype;
file = afile;
Expand All @@ -58,15 +58,15 @@ class TestResultsSet {
}

ElementType type;
unsigned line;
unsigned seq;
unsigned prec_ulp;
std::size_t line;
std::size_t seq;
std::size_t prec_ulp;
bool fp_zero_eq;
const char* file;
unsigned length;
unsigned el_size;
std::size_t length;
std::size_t el_size;

void set(unsigned id, void* adata)
void set(std::size_t id, void* adata)
{
std::memcpy(data.data() + id*el_size, adata, el_size);
}
Expand All @@ -80,11 +80,11 @@ class TestResultsSet {
};

/// Stores the results into the results set.
Result& push(ElementType type, unsigned length, const char* file, unsigned line);
Result& push(ElementType type, std::size_t length, const char* file, std::size_t line);

/// Sets the allowed error in ULPs. Only meaningful for floating-point data.
/// Affects all pushed data until the next call to @a unset_precision
void set_precision(unsigned num_ulp) { curr_precision_ulp_ = num_ulp; }
void set_precision(std::size_t num_ulp) { curr_precision_ulp_ = num_ulp; }
void unset_precision() { curr_precision_ulp_ = 0; }

/// Sets whether floating-point zero and negative zero are considered
Expand All @@ -106,8 +106,8 @@ class TestResultsSet {
TestResultsSet(const char* name);

const char* name_;
unsigned seq_;
unsigned curr_precision_ulp_;
std::size_t seq_;
std::size_t curr_precision_ulp_;
bool curr_fp_zero_equal_;

std::vector<Result> results_;
Expand Down