Skip to content

Commit 28c9d09

Browse files
committed
Add alignment
1 parent 57dfeb1 commit 28c9d09

File tree

3 files changed

+18
-14
lines changed

3 files changed

+18
-14
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ add_custom_target(generated ALL
180180
add_library(redirect_small STATIC src/redirect/redirect.cc)
181181
target_link_libraries(redirect_small snmalloc_lib)
182182
target_include_directories(redirect_small PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
183-
183+
add_dependencies(redirect_small generated)
184184

185185
# To build with just the header library target define SNMALLOC_ONLY_HEADER_LIBRARY
186186
# in containing Cmake file.

src/redirect/generate.cc

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,23 @@ int main(int argc, char* argv[])
1515
ofstream outfile;
1616
outfile.open(argv[1]);
1717

18-
for (size_t size = 1024; size > 0; size -= 16)
18+
for (size_t align = 0; align < 10; align++)
1919
{
20-
auto sizeclass = snmalloc::size_to_sizeclass(size);
21-
auto rsize = snmalloc::sizeclass_to_size(sizeclass);
22-
if (rsize == size)
20+
for (size_t size = 1024; size > 0; size -= 16)
2321
{
24-
outfile << "DEFINE_MALLOC_SIZE(malloc_size_" << size << ", " << size
25-
<< ");" << std::endl;
26-
}
27-
else
28-
{
29-
outfile << "REDIRECT_MALLOC_SIZE(malloc_size_" << size << ", malloc_size_"
30-
<< rsize << ");" << std::endl;
22+
auto asize = snmalloc::aligned_size(1ULL << align, size);
23+
auto sizeclass = snmalloc::size_to_sizeclass(asize);
24+
auto rsize = snmalloc::sizeclass_to_size(sizeclass);
25+
if (rsize == size && align == 0)
26+
{
27+
outfile << "DEFINE_MALLOC_SIZE(malloc_size_" << size << "_" << align << ", " << size
28+
<< ");" << std::endl;
29+
}
30+
else
31+
{
32+
outfile << "REDIRECT_MALLOC_SIZE(malloc_size_" << size << "_" << align << ", malloc_size_"
33+
<< rsize << "_" << 0 << ");" << std::endl;
34+
}
3135
}
3236
}
3337

src/redirect/redirect.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
__attribute__((alias(#b))) extern "C" void* a()
1515
#endif
1616

17-
#define DEFINE_MALLOC_SIZE(a, s) \
18-
extern "C" void* a() \
17+
#define DEFINE_MALLOC_SIZE(name, s) \
18+
extern "C" void* name() \
1919
{ \
2020
return snmalloc::ThreadAlloc::get_noncachable()->template alloc<s>(); \
2121
}

0 commit comments

Comments
 (0)