From b1cff63e271440f84497e4f301ddcbeb0816ce60 Mon Sep 17 00:00:00 2001 From: Gard Spreemann Date: Mon, 2 Dec 2019 12:48:48 +0100 Subject: Add support for running on big endian architectures. --- debian/changelog | 6 ++ ...t-for-running-on-big-endian-architectures.patch | 102 +++++++++++++++++++++ debian/patches/series | 1 + debian/rules | 6 ++ 4 files changed, 115 insertions(+) create mode 100644 debian/patches/0001-Support-for-running-on-big-endian-architectures.patch create mode 100644 debian/patches/series diff --git a/debian/changelog b/debian/changelog index 0276690..48c61ea 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +ripser (1.1-2) UNRELEASED; urgency=medium + + * Add patch to support running on big endian architectures. + + -- Gard Spreemann Mon, 02 Dec 2019 12:48:05 +0100 + ripser (1.1-1) unstable; urgency=medium * Initial release. (Closes: #943817) diff --git a/debian/patches/0001-Support-for-running-on-big-endian-architectures.patch b/debian/patches/0001-Support-for-running-on-big-endian-architectures.patch new file mode 100644 index 0000000..b759dad --- /dev/null +++ b/debian/patches/0001-Support-for-running-on-big-endian-architectures.patch @@ -0,0 +1,102 @@ +From: Gard Spreemann +Date: Mon, 2 Dec 2019 11:52:42 +0100 +Subject: Support for running on big endian architectures. + +--- + README.md | 3 ++- + ripser.cpp | 33 +++++++++++++++++++++++++-------- + 2 files changed, 27 insertions(+), 9 deletions(-) + +diff --git a/README.md b/README.md +index 2ce826f..ca98030 100644 +--- a/README.md ++++ b/README.md +@@ -62,6 +62,7 @@ Ripser supports several compile-time options. They are switched on by defining t + - `INDICATE_PROGRESS`: indicate the current progress in the console + - `PRINT_PERSISTENCE_PAIRS`: output the computed persistence pairs (enabled by default in the code; comment out to disable) + - `USE_GOOGLE_HASHMAP`: enable support for Google's [sparsehash] data structure; may further reduce memory footprint ++ - `BIGENDIAN`: build for running on a big endian architecture + + For example, to build Ripser with support for Google's hashmap: + +@@ -128,4 +129,4 @@ Ripser is licensed under the [MIT] license (`COPYING.txt`), with an extra clause + [Perseus]: + [GUDHI]: + [sparsehash]: +-[MIT]: +\ No newline at end of file ++[MIT]: +diff --git a/ripser.cpp b/ripser.cpp +index 1ae62e1..f420f2a 100644 +--- a/ripser.cpp ++++ b/ripser.cpp +@@ -830,10 +830,27 @@ enum file_format { + BINARY + }; + +-template T read(std::istream& input_stream) { ++template inline void reverse_endianness(T& x) { ++ uint8_t* p = reinterpret_cast(&x); ++ std::reverse(p, p + sizeof(T)); ++} ++ ++template T read_le(std::istream& input_stream) { ++ T result; ++ input_stream.read(reinterpret_cast(&result), sizeof(T)); ++ #ifdef BIGENDIAN ++ reverse_endianness(result); ++ #endif ++ return result; ++} ++ ++template T read_be(std::istream& input_stream) { + T result; + input_stream.read(reinterpret_cast(&result), sizeof(T)); +- return result; // on little endian: boost::endian::little_to_native(result); ++ #ifndef BIGENDIAN ++ reverse_endianness(result); ++ #endif ++ return result; + } + + compressed_lower_distance_matrix read_point_cloud(std::istream& input_stream) { +@@ -929,33 +946,33 @@ compressed_lower_distance_matrix read_distance_matrix(std::istream& input_stream + } + + compressed_lower_distance_matrix read_dipha(std::istream& input_stream) { +- if (read(input_stream) != 8067171840) { ++ if (read_le(input_stream) != 8067171840) { + std::cerr << "input is not a Dipha file (magic number: 8067171840)" << std::endl; + exit(-1); + } + +- if (read(input_stream) != 7) { ++ if (read_le(input_stream) != 7) { + std::cerr << "input is not a Dipha distance matrix (file type: 7)" << std::endl; + exit(-1); + } + +- index_t n = read(input_stream); ++ index_t n = read_le(input_stream); + + std::vector distances; + + for (int i = 0; i < n; ++i) + for (int j = 0; j < n; ++j) + if (i > j) +- distances.push_back(read(input_stream)); ++ distances.push_back(read_le(input_stream)); + else +- read(input_stream); ++ read_le(input_stream); + + return compressed_lower_distance_matrix(std::move(distances)); + } + + compressed_lower_distance_matrix read_binary(std::istream& input_stream) { + std::vector distances; +- while (!input_stream.eof()) distances.push_back(read(input_stream)); ++ while (!input_stream.eof()) distances.push_back(read_le(input_stream)); + return compressed_lower_distance_matrix(std::move(distances)); + } + diff --git a/debian/patches/series b/debian/patches/series new file mode 100644 index 0000000..3b1501f --- /dev/null +++ b/debian/patches/series @@ -0,0 +1 @@ +0001-Support-for-running-on-big-endian-architectures.patch diff --git a/debian/rules b/debian/rules index f7ab00f..5e7de73 100755 --- a/debian/rules +++ b/debian/rules @@ -5,6 +5,12 @@ CPPFLAGS:=$(shell dpkg-buildflags --get CPPFLAGS) CXXFLAGS:=$(shell dpkg-buildflags --get CXXFLAGS) LDFLAGS:=$(shell dpkg-buildflags --get LDFLAGS) +ENDIANNESS:=$(shell dpkg-architecture -qDEB_TARGET_ARCH_ENDIAN) + +ifeq (big, $(ENDIANNESS)) + CPPFLAGS+=-DBIGENDIAN +endif + %: dh $@ -- cgit v1.2.3