Skip to content

Commit

Permalink
Fix endianess for bigendian archs (#178)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex-PLACET authored Aug 27, 2024
1 parent 9ef1947 commit 54f2a6e
Show file tree
Hide file tree
Showing 17 changed files with 560 additions and 184 deletions.
97 changes: 97 additions & 0 deletions .github/workflows/qemu.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
name: Exotic architectures
on:
workflow_dispatch:
pull_request:
push:
branches: [main]

jobs:
build_job:
runs-on: ubuntu-22.04
name: Build on ${{ matrix.target.arch }} / ${{ matrix.target.distro }} / ${{ matrix.config.name }} / date-polyfill ${{ matrix.target.date-polyfill}}

strategy:
matrix:
target:
- { arch: armv6, distro: alpine_latest, date-polyfill: 'ON' }
- { arch: armv7, distro: alpine_latest, date-polyfill: 'ON' }
- { arch: aarch64, distro: alpine_latest, date-polyfill: 'ON' }
- { arch: aarch64, distro: alpine_latest, date-polyfill: 'OFF' }
- { arch: riscv64, distro: alpine_latest, date-polyfill: 'ON' }
- { arch: s390x, distro: alpine_latest, date-polyfill: 'ON' }
- { arch: s390x, distro: alpine_latest, date-polyfill: 'OFF' }
- { arch: ppc64le, distro: alpine_latest, date-polyfill: 'ON' }
- { arch: ppc64le, distro: alpine_latest, date-polyfill: 'OFF' }

config:
- { name: Debug }
- { name: Release }

steps:
- name: Checkout code
uses: actions/checkout@v4
- uses: uraimo/run-on-arch-action@v2
name: Build artifact
id: build
with:
arch: ${{matrix.target.arch}}
distro: ${{matrix.target.distro}}

# Not required, but speeds up builds
githubToken: ${{github.token}}

# Create an artifacts directory
setup: |
mkdir -p "${PWD}/artifacts"
# Mount the artifacts directory as /artifacts in the container
dockerRunArgs: |
--volume "${PWD}/artifacts:/artifacts"
# The shell to run commands with in the container
shell: /bin/sh

# Install some dependencies in the container. This speeds up builds if
# you are also using githubToken. Any dependencies installed here will
# be part of the container image that gets cached, so subsequent
# builds don't have to re-install them. The image layer is cached
# publicly in your project's package repository, so it is vital that
# no secrets are present in the container state or logs.
install: |
case "${{matrix.target.distro}}" in
ubuntu*|bookworm)
apt-get update -q -y
apt-get install -q -y git cmake make doctest-dev libhowardhinnant-date-dev tzdata g++ ninja-build build-essential
;;
fedora*)
dnf -y update
dnf -y groupinstall "Development Tools"
dnf -y install git which cmake make doctest-devel date date-devel tzdata gcc-c++ ninja-build
;;
alpine*)
apk update
apk add git cmake make doctest-dev date-dev tzdata g++ samurai
;;
esac
run: |
CC=gcc
export CC
CXX=g++
export CXX
echo "Configuring"
cmake -G Ninja -Bbuild -DCMAKE_BUILD_TYPE:STRING=${{matrix.config.name}} -DUSE_DATE_POLYFILL=${{matrix.target.date-polyfill}} -DBUILD_TESTS=ON -DBUILD_EXAMPLES=ON
cd build
echo "Building"
cmake --build . --config ${{matrix.config.name}} --target test_sparrow_lib
echo "Running examples"
cmake --build . --config ${{matrix.config.name}} --target run_examples
echo "Running tests"
cmake --build . --config ${{matrix.config.name}} --target run_tests_with_junit_report
- name: Upload test results
uses: actions/upload-artifact@v4
if: success() || failure()
with:
name: test_sparrow_lib_report_Linux_${{matrix.target.distro}}_${{matrix.target.arch}}_${{matrix.config.name}}_date-polyfill_${{matrix.target.date-polyfill}}
path: '**/test_sparrow_lib_report.xml'
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

cmake_minimum_required(VERSION 3.27)
cmake_minimum_required(VERSION 3.22)

# This is better specified per target, but cmake keeps ignoring these language version
# specification when building this project by itself, in particular the gnu extensions,
Expand Down
14 changes: 14 additions & 0 deletions include/sparrow/buffer/buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -580,14 +580,28 @@ namespace sparrow
template <class U>
constexpr U* buffer<T>::data() noexcept
{
#if defined(__GNUC__)
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wcast-align"
#endif
return reinterpret_cast<U*>(get_data().p_begin);
#if defined(__GNUC__)
# pragma GCC diagnostic pop
#endif
}

template <class T>
template <class U>
constexpr const U* buffer<T>::data() const noexcept
{
#if defined(__GNUC__)
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wcast-align"
#endif
return reinterpret_cast<U*>(get_data().p_begin);
#if defined(__GNUC__)
# pragma GCC diagnostic pop
#endif
}

template <class T>
Expand Down
14 changes: 14 additions & 0 deletions include/sparrow/buffer/buffer_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,28 @@ namespace sparrow
template <class U>
U* buffer_view<T>::data() noexcept
{
#if defined(__GNUC__)
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wcast-align"
#endif
return reinterpret_cast<U*>(p_data);
#if defined(__GNUC__)
# pragma GCC diagnostic pop
#endif
}

template <class T>
template <class U>
const U* buffer_view<T>::data() const noexcept
{
#if defined(__GNUC__)
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wcast-align"
#endif
return reinterpret_cast<const U*>(p_data);
#if defined(__GNUC__)
# pragma GCC diagnostic pop
#endif
}

template <class T>
Expand Down
20 changes: 6 additions & 14 deletions include/sparrow/layout/fixed_size_layout.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,7 @@ namespace sparrow
template <class T, data_storage DS>
auto fixed_size_layout<T, DS>::value_end() -> value_iterator
{
value_iterator it = value_begin();
std::advance(it, size());
return it;
return sparrow::next(value_begin(), size());
}

template <class T, data_storage DS>
Expand All @@ -271,37 +269,31 @@ namespace sparrow
template <class T, data_storage DS>
auto fixed_size_layout<T, DS>::value_cend() const -> const_value_iterator
{
auto it = value_cbegin();
std::advance(it, size());
return it;
return sparrow::next(value_cbegin(), size());
}

template <class T, data_storage DS>
auto fixed_size_layout<T, DS>::bitmap_begin() -> bitmap_iterator
{
return sparrow::bitmap(storage()).begin() + offset(storage());
return sparrow::next(sparrow::bitmap(storage()).begin(), offset(storage()));
}

template <class T, data_storage DS>
auto fixed_size_layout<T, DS>::bitmap_end() -> bitmap_iterator
{
bitmap_iterator it = bitmap_begin();
std::advance(it, size());
return it;
return sparrow::next(bitmap_begin(), size());
}

template <class T, data_storage DS>
auto fixed_size_layout<T, DS>::bitmap_cbegin() const -> const_bitmap_iterator
{
return sparrow::bitmap(storage()).cbegin() + offset(storage());
return sparrow::next(sparrow::bitmap(storage()).cbegin(), offset(storage()));
}

template <class T, data_storage DS>
auto fixed_size_layout<T, DS>::bitmap_cend() const -> const_bitmap_iterator
{
const_bitmap_iterator it = bitmap_cbegin();
std::advance(it, size());
return it;
return sparrow::next(bitmap_cbegin(), size());
}

template <class T, data_storage DS>
Expand Down
12 changes: 6 additions & 6 deletions include/sparrow/layout/list_layout/list_layout.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ namespace sparrow
if(bitmap_ref){
return reference(
inner_reference(
m_child_layout.begin() + element_offset(i),
m_child_layout.begin() + element_offset(i) + element_length(i)
sparrow::next(m_child_layout.begin(), element_offset(i)),
sparrow::next(m_child_layout.begin(), element_offset(i) + element_length(i))
),
bitmap_ref
);
Expand All @@ -117,8 +117,8 @@ namespace sparrow
if(bitmap_ref){
return const_reference(
inner_const_reference(
m_child_layout.begin() + element_offset(i),
m_child_layout.begin() + element_offset(i) + element_length(i)
sparrow::next(m_child_layout.begin(), element_offset(i)),
sparrow::next(m_child_layout.begin(), element_offset(i) + element_length(i))
),
bitmap_ref
);
Expand Down Expand Up @@ -178,15 +178,15 @@ namespace sparrow
}

bitmap_iterator bitmap_begin(){
return sparrow::bitmap(storage()).begin() + sparrow::offset(storage());
return sparrow::next(sparrow::bitmap(storage()).begin(), sparrow::offset(storage()));
}

bitmap_iterator bitmap_end(){
return sparrow::bitmap(storage()).end();
}

const_bitmap_iterator bitmap_cbegin() const{
return sparrow::bitmap(storage()).cbegin() + sparrow::offset(storage());
return sparrow::next(sparrow::bitmap(storage()).cbegin(), sparrow::offset(storage()));
}
const_bitmap_iterator bitmap_cend() const {
return sparrow::bitmap(storage()).cend();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ namespace sparrow


return list_value_type(
child_layout.begin() + offset,
child_layout.begin() + offset + length);
sparrow::next(child_layout.begin(), offset),
sparrow::next(child_layout.begin(), offset + length));
}

bool equal(const self_type& rhs) const
Expand Down
Loading

0 comments on commit 54f2a6e

Please sign in to comment.