compiler-optimization

Binutils LD creates huge files

让人想犯罪 __ 提交于 2021-02-09 11:12:46
问题 I'm trying to create as small ELF as possible. I created a test file like this (NASM syntax): SECTION .text dd 0xdeadbeef With this linker script: SECTIONS { .text : { *(.text) } } Then I checked sizes of flat binary and ELFs built two ways: nasm -f bin -o test test.asm It's flat binary, so 4 bytes. nasm -f elf -o test.o test.asm i686-elf-ld -Tlinker.ld test.o -o test I'd expect something like 500 bytes max, but the resulting file is 4396 bytes long! There is an option however, named --strip

Binutils LD creates huge files

不问归期 提交于 2021-02-09 11:12:05
问题 I'm trying to create as small ELF as possible. I created a test file like this (NASM syntax): SECTION .text dd 0xdeadbeef With this linker script: SECTIONS { .text : { *(.text) } } Then I checked sizes of flat binary and ELFs built two ways: nasm -f bin -o test test.asm It's flat binary, so 4 bytes. nasm -f elf -o test.o test.asm i686-elf-ld -Tlinker.ld test.o -o test I'd expect something like 500 bytes max, but the resulting file is 4396 bytes long! There is an option however, named --strip

Binutils LD creates huge files

安稳与你 提交于 2021-02-09 11:11:23
问题 I'm trying to create as small ELF as possible. I created a test file like this (NASM syntax): SECTION .text dd 0xdeadbeef With this linker script: SECTIONS { .text : { *(.text) } } Then I checked sizes of flat binary and ELFs built two ways: nasm -f bin -o test test.asm It's flat binary, so 4 bytes. nasm -f elf -o test.o test.asm i686-elf-ld -Tlinker.ld test.o -o test I'd expect something like 500 bytes max, but the resulting file is 4396 bytes long! There is an option however, named --strip

Can a vector be moved and modified without an extra allocation?

孤街醉人 提交于 2021-02-08 15:10:53
问题 Consider the following code: let u: Vec<u8> = (64..74).collect(); let v: Vec<u8> = u.iter().map(|i| i + 1).collect(); u was not moved, therefore v was inevitably newly allocated. But if I do the following: let w: Vec<u8> = u.into_iter().map(|i| i + 1).collect(); u was moved and w is the name of its transformation. Here is some pseudo-code representing what I mean: mark u as "moved" for i = 0..10: u[i] += 1 w = u There is (in my opinion) no need for a new allocation, since we map a type to

Does @tailrec affect compiler optimizations?

时光总嘲笑我的痴心妄想 提交于 2021-02-08 11:13:02
问题 I looked at this question trying to better understand @tailrec annotation in scala. What I'm not sure is whether the annotation also hints the compiler to do some optimizations or it's only used for warnings when you mark a method that is not a tail-recursion? More specifically - is this annotation might affect performance in any way? For example, if I don't put this annotation, the compiler will compile a tail-recursive function as non-tail recursive? 回答1: As per the scaladoc: A method

Is there a good reason why GCC would generate jump to jump just over one cheap instruction?

左心房为你撑大大i 提交于 2021-02-08 10:16:27
问题 I was benchmarking some counting in a loop code. g++ was used with -O2 code and I noticed that it has some perf problems when some condition is true in 50% of the cases. I assumed that may mean that code does unnecessary jumps(since clang produces faster code so it is not some fundamental limitation). What I find in this asm output funny is that code jumps over one simple add. => 0x42b46b <benchmark_many_ints()+1659>: movslq (%rdx),%rax 0x42b46e <benchmark_many_ints()+1662>: mov %rax,%rcx

Is there a good reason why GCC would generate jump to jump just over one cheap instruction?

怎甘沉沦 提交于 2021-02-08 10:15:16
问题 I was benchmarking some counting in a loop code. g++ was used with -O2 code and I noticed that it has some perf problems when some condition is true in 50% of the cases. I assumed that may mean that code does unnecessary jumps(since clang produces faster code so it is not some fundamental limitation). What I find in this asm output funny is that code jumps over one simple add. => 0x42b46b <benchmark_many_ints()+1659>: movslq (%rdx),%rax 0x42b46e <benchmark_many_ints()+1662>: mov %rax,%rcx

not used const static variable in class optimized out?

感情迁移 提交于 2021-02-08 07:25:18
问题 Can a reasonable decent compiler discard this const static variable class A{ const static int a = 3; } if it is nowhere used in the compiled binary or does it show up anyway in the binary? 回答1: Short answer: Maybe. The standard does not say the compiler HAS to keep the constants (or strings, or functions, or anything else), if it's never used. Long answer: It very much depends on the circumstances. If the compiler can clearly determine that it is not used, it will remove unused constants. If

not used const static variable in class optimized out?

一个人想着一个人 提交于 2021-02-08 07:21:37
问题 Can a reasonable decent compiler discard this const static variable class A{ const static int a = 3; } if it is nowhere used in the compiled binary or does it show up anyway in the binary? 回答1: Short answer: Maybe. The standard does not say the compiler HAS to keep the constants (or strings, or functions, or anything else), if it's never used. Long answer: It very much depends on the circumstances. If the compiler can clearly determine that it is not used, it will remove unused constants. If

not used const static variable in class optimized out?

天大地大妈咪最大 提交于 2021-02-08 07:21:18
问题 Can a reasonable decent compiler discard this const static variable class A{ const static int a = 3; } if it is nowhere used in the compiled binary or does it show up anyway in the binary? 回答1: Short answer: Maybe. The standard does not say the compiler HAS to keep the constants (or strings, or functions, or anything else), if it's never used. Long answer: It very much depends on the circumstances. If the compiler can clearly determine that it is not used, it will remove unused constants. If