0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-26 15:33:54 +01:00

ircd::simd: Add pointer cast template w/ alignment assertion.

This commit is contained in:
Jason Volk 2020-10-09 06:22:12 -07:00
parent a88934f4e7
commit 5b63366e5d
2 changed files with 44 additions and 0 deletions

43
include/ircd/simd/cast.h Normal file
View file

@ -0,0 +1,43 @@
// The Construct
//
// Copyright (C) The Construct Developers, Authors & Contributors
// Copyright (C) 2016-2020 Jason Volk <jason@zemos.net>
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice is present in all copies. The
// full license for this software is available in the LICENSE file.
#pragma once
#define HAVE_IRCD_CAST_H
namespace ircd::simd
{
template<class R,
class T>
const R *cast(const T *const &) noexcept;
template<class R,
class T>
R *cast(T *const &) noexcept;
}
template<class R,
class T>
inline R *
ircd::simd::cast(T *const &in)
noexcept
{
assert(uintptr_t(in) % std::alignment_of<R>::value == 0);
return reinterpret_cast<R *>(in);
}
template<class R,
class T>
inline const R *
ircd::simd::cast(const T *const &in)
noexcept
{
assert(uintptr_t(in) % std::alignment_of<R>::value == 0);
return reinterpret_cast<const R *>(in);
}

View file

@ -14,6 +14,7 @@
#include "type.h" #include "type.h"
#include "unaligned.h" #include "unaligned.h"
#include "traits.h" #include "traits.h"
#include "cast.h"
#include "lane_cast.h" #include "lane_cast.h"
#include "broad_cast.h" #include "broad_cast.h"
#include "split.h" #include "split.h"