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

use new byte-swap routines from CODA-OSS #650

Merged
merged 67 commits into from
May 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
4ee4d84
copy_externals.csh
Mar 13, 2023
a83139d
copy_externals.csh
Mar 13, 2023
32e2e98
copy_externals.csh
Mar 13, 2023
4fe7071
Squashed 'externals/coda-oss/' changes from 67d6362bc..cbfb20ce2
Mar 13, 2023
59d24d3
Merge commit '4fe707145f838153f252abdd8ccae3fc3c089043' into develop/…
Mar 13, 2023
2c7b84b
Squashed 'externals/nitro/' changes from 496bfba71..342f55276
Mar 13, 2023
7017536
sync_externals.csh
Mar 13, 2023
3cd487c
copy_externals.csh
Mar 13, 2023
b323f91
Merge branch 'main' into develop/sync_externals
Mar 20, 2023
91888f7
latest from coda-oss and NITRO
Mar 20, 2023
64fe1f2
Merge commit '1e9e7a04b35447de1130cd08c410399937776eac' into develop/…
Mar 20, 2023
1e9e7a0
Squashed 'externals/coda-oss/' changes from e87c32b4d..857ff0af3
Mar 20, 2023
945e2f5
Squashed 'externals/nitro/' changes from c8ecbe9ae..90d513ac5
Mar 20, 2023
016d035
latest from coda-oss and NITRO
Mar 20, 2023
6d5e24b
latest from coda-oss and NITRO
Mar 20, 2023
9df7646
Merge branch 'main' into develop/sync_externals
Apr 18, 2023
3693cf3
latest from coda-oss
Apr 18, 2023
687d2b9
Merge commit 'f0ef23ed33355348c98d8e9d705894308421dd05' into develop/…
Apr 18, 2023
f0ef23e
Squashed 'externals/coda-oss/' changes from 857ff0af3..f6489b6be
Apr 18, 2023
d6abcb8
Squashed 'externals/nitro/' changes from 90d513ac5..90c6263e2
Apr 18, 2023
3d8917b
latest from coda-oss
Apr 18, 2023
5b9889b
Merge branch 'main' into develop/sync_externals
Apr 25, 2023
869de5b
Merge commit 'f2a61ac8f2196b8b75e7c0e7e4277df21559527e' into develop/…
Apr 25, 2023
f2a61ac
Squashed 'externals/coda-oss/' changes from f6489b6be..0b7d581fa
Apr 25, 2023
7c911d7
latest from coda-oss
May 15, 2023
b76ff57
account for sys::byteSwap changes
May 15, 2023
40f3067
Squashed 'externals/coda-oss/' changes from 0b7d581fa..e85ec9331
May 15, 2023
7c021aa
Merge commit '40f306707cdaa49d691140341bb80cc45170ef69' into develop/…
May 15, 2023
e94347b
latest from coda-oss
May 15, 2023
b2edfc3
latest from NITRO
May 15, 2023
187e1a7
Squashed 'externals/coda-oss/' changes from e85ec9331..c120e3255
May 15, 2023
cfd20c7
Merge commit '187e1a73bdc100da9289a6a05e137ca321a58e5f' into develop/…
May 15, 2023
7d95f64
Squashed 'externals/nitro/' changes from 90c6263e2..3b52f0025
May 15, 2023
8f26aa5
sync_externals
May 15, 2023
72751fc
latest from NITRO
May 15, 2023
72acda2
account for sys::byteSwap changes
May 15, 2023
97f5a59
latest from coda-oss
May 15, 2023
81df874
byte-swapping single-bytes makes no sense
May 15, 2023
ad1aa1a
Merge branch 'main' into develop/sync_externals
May 16, 2023
72e96cb
latest from coda-oss
May 16, 2023
df94475
Merge commit '9590c1da93d1e3ac1a89ef035a3d618610eb04ca' into develop/…
May 16, 2023
9590c1d
Squashed 'externals/coda-oss/' changes from c120e3255..0774c03c4
May 16, 2023
9fb6e0f
Squashed 'externals/nitro/' changes from 3b52f0025..089ba0b5b
May 16, 2023
3407b60
sync_externals
May 16, 2023
d0c5210
copy_externals
May 16, 2023
82be86e
latest from coda-oss
May 17, 2023
75a22dd
Squashed 'externals/coda-oss/' changes from 0774c03c4..540ae763e
May 17, 2023
ed6c8c1
Merge commit '75a22dd5cc3ca8cf39b6331a0fd5fb9cee7a4085' into develop/…
May 17, 2023
188d5ba
restore commented-out unittests
May 17, 2023
73b4402
latest byteSwap() changes from coda-oss
May 18, 2023
893ae98
build with latest byteSwap() changes from coda-oss
May 18, 2023
24c1b6c
use mt::threadedByteSwap()
May 18, 2023
1e53451
specializations for common sizes
May 18, 2023
71c4213
more byteSwap() changes from coda-oss
May 18, 2023
17d9d9b
use sys::swapBytes() from coda-oss
May 18, 2023
9b4f462
latest from coda-oss
May 18, 2023
8bdf9ac
Squashed commit of the following:
May 18, 2023
1c06a11
fix call to sys::byteSwap()
May 18, 2023
018a203
latest from coda-oss
May 19, 2023
9de95e9
use new sys::swapBytes() overload
May 19, 2023
b513a96
coda-oss now provides as_bytes()
May 19, 2023
8e1df3b
latest byte-swap from coda-oss
May 19, 2023
51b033d
trying to get the SIX byteSwap routines working
May 19, 2023
fb15189
latest from coda-oss
May 22, 2023
adc1a01
make_span can be simpler
May 22, 2023
aa92cd6
isLittleEnndianSystem()
May 22, 2023
2ab7d04
Merge branch 'main' into develop/byteswap
May 22, 2023
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
93 changes: 20 additions & 73 deletions six/modules/c++/cphd/source/ByteSwap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,59 +21,34 @@
*/
#include <cphd/ByteSwap.h>

#include <stdint.h>

#include <string>
#include <std/memory>
#include <memory>
#include <type_traits>
#include <std/span>
#include <std/cstddef>
#include <tuple>

#include <sys/Conf.h>
#include <sys/ByteSwap.h>
#include <sys/ByteSwapValue.h>
#include <sys/Span.h>
#include <sys/Runnable.h>
#include <mt/ThreadPlanner.h>
#include <mt/ThreadGroup.h>
#include <mt/ThreadedByteSwap.h>
#include <nitf/coda-oss.hpp>

namespace
{
// TODO: Maybe this should go in sys/Conf.h
// It's more flexible in that it properly handles float's - you can't
// just call sys::byteSwap(floatVal) because the compiler may change the
// byte-swapped float value into a valid IEEE value beforehand.
// TODO: If we're really looking to optimize this, could specialize it for
// sizes of 2, 4, and 8 to eliminate the for loop
template <typename T>
inline
void byteSwap(const void* in, T& out)
inline void byteSwap(const void* in, T& out)
{
const std::byte* const inPtr = static_cast<const std::byte*>(in);
std::byte* const outPtr = reinterpret_cast<std::byte*>(&out);

for (size_t ii = 0, jj = sizeof(T) - 1; ii < jj; ++ii, --jj)
{
outPtr[ii] = inPtr[jj];
outPtr[jj] = inPtr[ii];
}
auto const inBytes = sys::make_span<std::byte>(in, sizeof(T));
out = sys::swapBytes<T>(inBytes);
}

struct ByteSwapRunnable final : public sys::Runnable
{
ByteSwapRunnable(void* buffer,
size_t elemSize,
size_t startElement,
size_t numElements) :
mBuffer(static_cast<std::byte*>(buffer) + startElement * elemSize),
mElemSize(static_cast<unsigned short>(elemSize)),
mNumElements(numElements)
{
}

virtual void run()
{
sys::byteSwap(mBuffer, mElemSize, mNumElements);
}

private:
std::byte* const mBuffer;
const unsigned short mElemSize;
const size_t mNumElements;
};

inline const std::byte* calc_offset(const void* input_, size_t offset)
{
auto input = static_cast<const std::byte*>(input_);
Expand All @@ -94,7 +69,7 @@ struct ByteSwapAndPromoteRunnable final : public sys::Runnable
{
}

virtual void run()
void run() override
{
InT real(0);
InT imag(0);
Expand Down Expand Up @@ -123,9 +98,8 @@ struct ByteSwapAndPromoteRunnable final : public sys::Runnable


template <typename InT>
class ByteSwapAndScaleRunnable : public sys::Runnable
struct ByteSwapAndScaleRunnable final : public sys::Runnable
{
public:
ByteSwapAndScaleRunnable(const void* input,
size_t startRow,
size_t numRows,
Expand All @@ -139,7 +113,7 @@ class ByteSwapAndScaleRunnable : public sys::Runnable
{
}

virtual void run()
void run() override
{
InT real(0);
InT imag(0);
Expand Down Expand Up @@ -249,36 +223,9 @@ void byteSwapAndScale(const void* input,

namespace cphd
{
void byteSwap(void* buffer,
size_t elemSize,
size_t numElements,
size_t numThreads)
void byteSwap(void* buffer, size_t elemSize, size_t numElements, size_t numThreads)
{
if (numThreads <= 1)
{
sys::byteSwap(buffer, elemSize, numElements);
}
else
{
mt::ThreadGroup threads;
const mt::ThreadPlanner planner(numElements, numThreads);

size_t threadNum(0);
size_t startElement(0);
size_t numElementsThisThread(0);
while (planner.getThreadInfo(threadNum++,
startElement,
numElementsThisThread))
{
auto thread = std::make_unique<ByteSwapRunnable>(
buffer,
elemSize,
startElement,
numElementsThisThread);
threads.createThread(std::move(thread));
}
threads.joinAll();
}
return mt::threadedByteSwap(buffer, elemSize, numElements, numThreads);
}

void byteSwapAndPromote(const void* input,
Expand Down
9 changes: 5 additions & 4 deletions six/modules/c++/six.sicd/tests/test_sicd_byte_provider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,12 @@ struct Tester final
}

mBigEndianImage = mImage;
if (std::endian::native == std::endian::little)
if (sys::isLittleEndianSystem())
{
sys::byteSwap(mBigEndianImage.data(),
sizeof(DataTypeT),
mBigEndianImage.size() * 2);
void* const buffer = mBigEndianImage.data();
constexpr auto elemSize = sizeof(DataTypeT);
const auto numElems = mBigEndianImage.size() * 2; // real and imag
sys::byteSwap(buffer, elemSize, numElems);
}

normalWrite();
Expand Down