Skip to content

Commit

Permalink
zehn_loader: Tell the compiler that the malloced header is aligned
Browse files Browse the repository at this point in the history
It doesn't know that the function call returns an aligned pointer, so tell
it explicitly. This way it uses aligned loads instead of multiple byte loads.

Here the size goes from 616 to 484, saving more than 20%!
  • Loading branch information
Vogtinator committed May 17, 2024
1 parent 61ab9fe commit 35f2d9a
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ndless-sdk/tools/zehn_loader/loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ int main(int argc, char **argv)

old_storage = reinterpret_cast<const uint8_t*>(header);
syscall<e_memcpy, void*>(mallocd, old_storage, header->file_size);
header = reinterpret_cast<const Zehn_header*>(mallocd);
header = reinterpret_cast<const Zehn_header*>(__builtin_assume_aligned(mallocd, 4));
}

const Zehn_reloc *reloc_table = reinterpret_cast<const Zehn_reloc*>(reinterpret_cast<const uint8_t*>(header) + sizeof(Zehn_header));
//This loader doesn't parse the flag table
const uint8_t *flag_table = reinterpret_cast<const uint8_t*>(reloc_table) + sizeof(Zehn_reloc) * header->reloc_count;
Expand Down

0 comments on commit 35f2d9a

Please sign in to comment.