0

If I had program foo compiled and ready to be assembled and put it through GAS, NASM, or FASM would there be a noticeable difference in speed? Or does the assembler have no impact on how fast the final binary is?

XTAGz
  • 1
  • 2
    While assemblers do some times make different choices with respect to instruction encoding, there usually isn't really a measurable difference in performance. I cannot exclude that it would be possible to construct a case where there is such a measurable difference though. – fuz Mar 09 '21 at 20:23
  • I agree with that, while technically possible with some strange corner cases that could happen, it is not expected. The differences might be alignment, etc. also note that assembly language is defined by the tool not the target so one file is not expected to assemble for all three of those tools. (not just an intel vs at&t thing, the whole language/syntax) I would expect the differences if any on an x86 to be immesurable. – old_timer Mar 10 '21 at 00:39
  • what did you see when you tried this? does the disassembly and/or machine code vary? – old_timer Mar 10 '21 at 00:48
  • 1
    @fuz: [How to force NASM to encode \[1 + rax\*2\] as disp32 + index\*2 instead of disp8 + base + index?](https://stackoverflow.com/q/48848230) is an example of a case where encoding choice affects latency, and could affect performance if part of a critical-path dependency chain. GAS doesn't turn `lea 1(,%rax,2), %eax` into `lea 1(%rax,%rax), %eax` the way NASM does (including for intel-syntax mode), so you'll get the larger, lower-latency instruction which might be faster or slower. – Peter Cordes Mar 10 '21 at 06:09
  • 1
    But it's definitely not like one assembler "makes faster code" the way some compiler are better than others. The differences if any can include alignment like old_timer said, and they use different directives at least, and the same source won't work for both GAS and NASM except for the simplest toy cases (`mov edi, symbol` mean different things), and even then `.intel_syntax noprefix` is GAS only. (Although FASM and NASM are pretty compatible). – Peter Cordes Mar 10 '21 at 06:14

0 Answers0