Commit 8827ef2b authored by mattijs's avatar mattijs
Browse files

sicortex unaligned access

parent 30b62fb3
......@@ -27,9 +27,8 @@ Description
\*---------------------------------------------------------------------------*/
#include "error.H"
#include "IPstream.H"
#include "error.H"
#include "int.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -51,17 +50,24 @@ inline void IPstream::checkEof()
template<class T>
inline void IPstream::readFromBuffer(T& t)
{
const size_t align = sizeof(T);
bufPosition_ = align + ((bufPosition_ - 1) & ~(align - 1));
t = reinterpret_cast<T&>(buf_[bufPosition_]);
bufPosition_ += sizeof(T);
checkEof();
//readFromBuffer(&t, sizeof(T));
}
inline void IPstream::readFromBuffer(void* data, size_t count)
inline void IPstream::readFromBuffer(void* data, size_t count, size_t align)
{
if (align > 1)
{
bufPosition_ = align + ((bufPosition_ - 1) & ~(align - 1));
}
register const char* bufPtr = &buf_[bufPosition_];
register char* dataPtr = reinterpret_cast<char*>(data);
register size_t i = count;
while (i--) *dataPtr++ = *bufPtr++;
......@@ -137,7 +143,7 @@ Istream& IPstream::read(char* data, std::streamsize count)
<< Foam::abort(FatalError);
}
readFromBuffer(data, count);
readFromBuffer(data, count, 8);
return *this;
}
......
......@@ -71,7 +71,7 @@ class IPstream
inline void readFromBuffer(T&);
//- Read data from the transfer buffer
inline void readFromBuffer(void* data, size_t count);
inline void readFromBuffer(void* data, size_t count, size_t align);
public:
......
......@@ -70,7 +70,7 @@ class OPstream
inline void writeToBuffer(const char&);
//- Write data to the transfer buffer
inline void writeToBuffer(const void* data, size_t count);
inline void writeToBuffer(const void* data, size_t count, size_t align);
public:
......
......@@ -40,7 +40,7 @@ inline void OPstream::writeToBuffer(const T& t)
//(T&)(buf_[bufPosition_]) = t;
//bufPosition_ += sizeof(T);
writeToBuffer(&t, sizeof(T));
writeToBuffer(&t, sizeof(T), sizeof(T));
}
......@@ -56,11 +56,24 @@ inline void OPstream::writeToBuffer(const char& c)
}
inline void OPstream::writeToBuffer(const void* data, size_t count)
inline void OPstream::writeToBuffer
(
const void* data,
size_t count,
size_t align
)
{
label oldPos = bufPosition_;
if (align > 1)
{
// Align bufPosition. Pads bufPosition_-oldPos characters.
bufPosition_ = align + ((bufPosition_ - 1) & ~(align - 1));
}
if (size_t(buf_.size()) < bufPosition_ + count)
{
enlargeBuffer(count);
enlargeBuffer(bufPosition_ - oldPos + count);
}
register char* bufPtr = &buf_[bufPosition_];
......
......@@ -111,7 +111,7 @@ Ostream& OPstream::write(const word& w)
size_t ws = w.size();
writeToBuffer(ws);
writeToBuffer(w.c_str(), ws + 1);
writeToBuffer(w.c_str(), ws + 1, 1);
return *this;
}
......@@ -123,7 +123,7 @@ Ostream& OPstream::write(const string& s)
size_t ss = s.size();
writeToBuffer(ss);
writeToBuffer(s.c_str(), ss + 1);
writeToBuffer(s.c_str(), ss + 1, 1);
return *this;
}
......@@ -168,7 +168,7 @@ Ostream& OPstream::write(const char* data, std::streamsize count)
<< Foam::abort(FatalError);
}
writeToBuffer(data, count);
writeToBuffer(data, count, 8);
return *this;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment