-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c7c2c53
commit c0d0f6b
Showing
4 changed files
with
80 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#ifndef PYTHONIC_ARRAY_ARRAY_BYTESWAP_HPP | ||
#define PYTHONIC_ARRAY_ARRAY_BYTESWAP_HPP | ||
|
||
#include "pythonic/include/array/array/byteswap.hpp" | ||
#include "pythonic/utils/functor.hpp" | ||
|
||
#include <byteswap.h> | ||
|
||
PYTHONIC_NS_BEGIN | ||
|
||
namespace array | ||
{ | ||
|
||
namespace array | ||
{ | ||
void byteswap(char *buffer, size_t n, std::integral_constant<unsigned, 2>) | ||
{ | ||
auto *ibuffer = reinterpret_cast<uint16_t *>(buffer); | ||
for (size_t i = 0; i < n; i++) | ||
ibuffer[i] = bswap_16(ibuffer[i]); | ||
} | ||
void byteswap(char *buffer, size_t n, std::integral_constant<unsigned, 4>) | ||
{ | ||
auto *ibuffer = reinterpret_cast<uint32_t *>(buffer); | ||
for (size_t i = 0; i < n; i++) | ||
ibuffer[i] = bswap_32(ibuffer[i]); | ||
} | ||
void byteswap(char *buffer, size_t n, std::integral_constant<unsigned, 8>) | ||
{ | ||
auto *ibuffer = reinterpret_cast<uint64_t *>(buffer); | ||
for (size_t i = 0; i < n; i++) | ||
ibuffer[i] = bswap_64(ibuffer[i]); | ||
} | ||
|
||
template <class T> | ||
types::none_type byteswap(types::array<T> &seq) | ||
{ | ||
byteswap(reinterpret_cast<char *>(seq.data()), seq.size(), | ||
std::integral_constant<unsigned, sizeof(T)>{}); | ||
return {}; | ||
} | ||
|
||
} // namespace array | ||
} // namespace array | ||
PYTHONIC_NS_END | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#ifndef PYTHONIC_INCLUDE_ARRAY_ARRAY_BYTESWAP_HPP | ||
#define PYTHONIC_INCLUDE_ARRAY_ARRAY_BYTESWAP_HPP | ||
|
||
#include "pythonic/include/types/array.hpp" | ||
#include "pythonic/include/utils/functor.hpp" | ||
|
||
PYTHONIC_NS_BEGIN | ||
|
||
namespace array | ||
{ | ||
|
||
namespace array | ||
{ | ||
|
||
template <class T> | ||
types::none_type byteswap(types::array<T> &seq); | ||
|
||
template <class T> | ||
types::none_type byteswap(types::array<T> &&seq) | ||
{ | ||
return {}; | ||
} | ||
|
||
DEFINE_FUNCTOR(pythonic::array::array, byteswap); | ||
} // namespace array | ||
} // namespace array | ||
PYTHONIC_NS_END | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters