Make storage blocks aligned to 4 bytes for ARM NEON/VFP instructions
Aligned blocks prevent bus errors in NEON/VFP instructions. Block pointers are aligned to 4 bytes, that is guaranteed by aligned mmaped-pointers, the 4 bytes size of the CANARY block and aligned sizes of blocks.
This commit is contained in:
parent
12d4832037
commit
04e334e3e2
@ -14,7 +14,7 @@ namespace storage
|
|||||||
{
|
{
|
||||||
|
|
||||||
// Added at the start and end of each block as sanity check
|
// Added at the start and end of each block as sanity check
|
||||||
const constexpr char CANARY[] = "OSRM";
|
const constexpr char CANARY[4] = {'O', 'S', 'R', 'M'};
|
||||||
|
|
||||||
struct SharedDataLayout
|
struct SharedDataLayout
|
||||||
{
|
{
|
||||||
@ -63,15 +63,20 @@ struct SharedDataLayout
|
|||||||
entry_size[bid] = sizeof(T);
|
entry_size[bid] = sizeof(T);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline uint64_t AlignBlockSize(uint64_t block_size) const
|
||||||
|
{
|
||||||
|
const uint64_t alignment = 4;
|
||||||
|
return (block_size + (alignment - 1)) & ~(alignment - 1);
|
||||||
|
}
|
||||||
|
|
||||||
inline uint64_t GetBlockSize(BlockID bid) const
|
inline uint64_t GetBlockSize(BlockID bid) const
|
||||||
{
|
{
|
||||||
// special bit encoding
|
// special bit encoding
|
||||||
if (bid == CORE_MARKER)
|
if (bid == CORE_MARKER)
|
||||||
{
|
{
|
||||||
return (num_entries[bid] / 32 + 1) * entry_size[bid];
|
return AlignBlockSize((num_entries[bid] / 32 + 1) * entry_size[bid]);
|
||||||
}
|
}
|
||||||
|
return AlignBlockSize(num_entries[bid] * entry_size[bid]);
|
||||||
return num_entries[bid] * entry_size[bid];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline uint64_t GetSizeOfLayout() const
|
inline uint64_t GetSizeOfLayout() const
|
||||||
|
@ -426,7 +426,7 @@ int Storage::Run()
|
|||||||
unsigned temp_length;
|
unsigned temp_length;
|
||||||
name_stream.read((char *)&temp_length, sizeof(unsigned));
|
name_stream.read((char *)&temp_length, sizeof(unsigned));
|
||||||
|
|
||||||
BOOST_ASSERT_MSG(temp_length ==
|
BOOST_ASSERT_MSG(shared_layout_ptr->AlignBlockSize(temp_length) ==
|
||||||
shared_layout_ptr->GetBlockSize(SharedDataLayout::NAME_CHAR_LIST),
|
shared_layout_ptr->GetBlockSize(SharedDataLayout::NAME_CHAR_LIST),
|
||||||
"Name file corrupted!");
|
"Name file corrupted!");
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user