Closed n0tknowing closed 1 year ago
It's also produces incomplete expansion (ignore broken newline printing):
char const *
foo_string ="foo"; char const *bar_string ="bar"; MAP1(STRING, baz, ()()(), ()()(), ()()(), 0)void function(int foo , int bar , MAP_LIST1(PARAM, baz, ()()(), ()()(), ()()(), 0));
putchar ('a'); putchar ('b'); MAP1(CALL, ('c'), ()()(), ()()(), ()()(), 0)
putchar ('a') , putchar ('b') , MAP_LIST1(CALL_LIST, ('c'), ()()(), ()()(), ()()(), 0);
Just for curiosity, I did memusage
on clang, GCC, and TCC:
With 5976d6a32f86c7af5af8878f6dc8f9090597e283, it only consumes ~24MiB
Memory usage summary: heap total: 25386440, heap peak: 25288317, stack peak: 4768
total calls total memory failed calls
malloc| 86 20485 0
realloc| 12 24 0 (nomove:11, dec:10, free:0)
calloc| 231743 25365931 0
free| 19 18744
Histogram for block sizes:
0-15 72 <1%
16-31 37704 16% =========
32-47 1615 <1%
48-63 78 <1%
64-79 3 <1%
112-127 5 <1%
128-143 192329 82% ==================================================
160-175 1 <1%
384-399 2 <1%
464-479 3 <1%
496-511 10 <1%
528-543 1 <1%
768-783 1 <1%
1024-1039 1 <1%
1536-1551 1 <1%
1920-1935 1 <1%
3072-3087 1 <1%
4096-4111 3 <1%
8192-8207 10 <1%
perf
results:
Overhead Command Shared Object Symbol
21.62% chibicc libc.so.6 [.] __strlen_sse2
21.06% chibicc libc.so.6 [.] __strncmp_sse42
13.87% chibicc libc.so.6 [.] _int_malloc
11.98% chibicc chibicc [.] hideset_union
8.06% chibicc chibicc [.] preprocess2
7.09% chibicc libc.so.6 [.] __libc_calloc
3.74% chibicc libc.so.6 [.] __memset_sse2_unaligned_erms
2.09% chibicc chibicc [.] equal
1.87% chibicc chibicc [.] read_macro_arg_one
1.47% chibicc [unknown] [k] 0xffffffff9ae012b0
1.29% chibicc libc.so.6 [.] __memset_sse2_unaligned
1.23% chibicc chibicc [.] strlen@plt
1.20% chibicc chibicc [.] get_entry
1.05% chibicc chibicc [.] strncmp@plt
0.43% chibicc libc.so.6 [.] __memcmp_sse2
0.26% chibicc chibicc [.] calloc@plt
0.24% chibicc libc.so.6 [.] alloc_perturb
0.23% chibicc libc.so.6 [.] __cxa_finalize
0.20% chibicc ld-linux-x86-64.so.2 [.] strcmp
0.16% chibicc chibicc [.] is_ident2
0.15% chibicc libc.so.6 [.] sysmalloc
0.13% chibicc chibicc [.] tokenize
Not surprised with the current compiler design. Here's result from
memusage
andperf
when run https://github.com/swansontec/map-macro.memusage
results:For the slowness, it's mostly from the allocator when doing hideset stuff,
perf
reports: