Skip to content

Commit

Permalink
Squashed 'externals/coda-oss/' changes from e3e70cf74..df73cbb6e
Browse files Browse the repository at this point in the history
df73cbb6e Merge pull request ngageoint#345 from mdaus/mem-align
2167292c7 alignment method
ebf630751 Merge pull request ngageoint#344 from mdaus/range-list-type
f904fab49 doxygen
e59888523 incorrect start element in unit test
fd5baf864 Range split
918b3f546 polygon --> types
0a5d6cec2 style
21d8c551b RangeList type

git-subtree-dir: externals/coda-oss
git-subtree-split: df73cbb6ea5e789546ac5be1f11dba349fa0ed18
  • Loading branch information
JonathanMeans committed Feb 24, 2020
1 parent 5ec496c commit 24ce07d
Show file tree
Hide file tree
Showing 10 changed files with 918 additions and 17 deletions.
41 changes: 41 additions & 0 deletions modules/c++/mem/include/mem/Align.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/* =========================================================================
* This file is part of mem-c++
* =========================================================================
*
* (C) Copyright 2004 - 2020, Radiant Geospatial Solutions
*
* mem-c++ is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; If not,
* see <http://www.gnu.org/licenses/>.
*
*/
#ifndef __MEM_ALIGN_H__
#define __MEM_ALIGN_H__

#include <sys/Conf.h>

namespace mem
{
/*!
* Align the input pointer to lay at the next multiple of
* of the provided alignment.
*
* \param[in, out] data Pointer to the address to align to a multiple
* alignment
* \param alignment The alignment to use
*/
void align(sys::ubyte* __restrict* data,
size_t alignment = sys::SSE_INSTRUCTION_ALIGNMENT);
}

#endif
35 changes: 35 additions & 0 deletions modules/c++/mem/source/Align.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/* =========================================================================
* This file is part of mem-c++
* =========================================================================
*
* (C) Copyright 2004 - 2020, Radiant Geospatial Solutions
*
* mem-c++ is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; If not,
* see <http://www.gnu.org/licenses/>.
*
*/
#include <mem/Align.h>

namespace mem
{
void align(sys::ubyte* __restrict* data, size_t alignment)
{
const size_t beyondBoundary = reinterpret_cast<size_t>(*data) %
alignment;
if (beyondBoundary != 0)
{
*data += alignment - beyondBoundary;
}
}
}
19 changes: 2 additions & 17 deletions modules/c++/mem/source/ScratchMemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,10 @@
* see <http://www.gnu.org/licenses/>.
*
*/
#include <mem/Align.h>

#include <mem/ScratchMemory.h>

namespace
{
/*!
* \brief Advance sys::ubyte pointer to next alignment boundary
*/
void align(sys::ubyte*& dataPtr, size_t alignment)
{
const size_t beyondBoundary = reinterpret_cast<size_t>(dataPtr) % alignment;

if (beyondBoundary != 0)
{
dataPtr += alignment - beyondBoundary;
}
}
}

namespace mem
{
ScratchMemory::ScratchMemory() :
Expand Down Expand Up @@ -218,7 +203,7 @@ void ScratchMemory::setup(const BufferView<sys::ubyte>& scratchBuffer)
for (size_t i = 0; i < segment.numBuffers; ++i)
{
segment.buffers[i] = mBuffer.data + currentOffset;
align(segment.buffers[i], segment.alignment);
align(&segment.buffers[i], segment.alignment);
currentOffset = segment.buffers[i] + segment.numBytes -
mBuffer.data;
}
Expand Down
1 change: 1 addition & 0 deletions modules/c++/types/include/import/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@
#include <types/RowCol.h>
#include <types/PageRowCol.h>
#include <types/Range.h>
#include <types/RangeList.h>

#endif
14 changes: 14 additions & 0 deletions modules/c++/types/include/types/Range.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,20 @@ struct Range
return overlap.mNumElements;
}

/*!
* Given an input range, removes numElementsReq elements from the end of it
* (if possible), and provides the new range composed of these elements
*
* \param inputRange Initial Range object
* \param numElementsReq The number elements requested to be split from
* the end of inputRange
*
* \returns The resulting range formed from the removed elements of
* inputRange. Has no more than numElementsReq elements,
* but may have fewer depending on the size of inputRange.
*/
Range split(size_t numElementsReq) const;

//! \return True if there are no elements in this range, false otherwise
bool empty() const
{
Expand Down
Loading

0 comments on commit 24ce07d

Please sign in to comment.