Assembly Code

What is the easiest way to tell if assembly code is hand written or compiler generated?

Attached: 1502627017219.png (238x286, 10K)

labels.

Just ask it.

You look whether the asm code does unnecessary things to assure semantics of a language you suppose was used to write it.

Are long chains of mov commands with advanced indexing like this cause for concern? I have those in my code sometimes

Attached: nervous snek.gif (364x489, 526K)

I thought modern compilers were tighter than hand written assembly.

They're not generally. The best human assembly writers can outperform compilers easily.

The problem is that the feature sets on modern processors are so large and convoluted that compilers can usually take advantage of them much better than the average assembly programmer can.

Modern compilers can't even make a 2D array 1D. Enjoy your cache misses.

just look at lua jit

Not when you want to use "modern" instructions which require specific data layout (simd) for maximal performance, then you might as well hand-write assembly since higher-level languages do not map well

No, the pipeline stalls give the cpu time to relax and unwind a bit.

Where did you get that from? Compilers are still shit at optimization.

Have you ever read the shit a compiler spews out?

Hand written assembly code is less efficient than compiler generated code.

Total retard.

>hur what are compiler builtins and intrinsics

Use of effectively nop instructions (such as lea edi,[edi+eiz*1+0x0]) for alignment purposes is one sign, I think.
repz ret is another one which uses the repz to align the next instruction. Compilers typically use that one.

Attached: 1512702662355.png (998x832, 118K)

intelligently scheduled instructions that make use of architecture ports(such as having certain alu instructions "oddly" dispatched before others) tends to imply compiler usage

also nop alignment for cache lines

If you see any of the following, could be a significant indication, depending if you are looking at the whole or part of a program being hand-written...

Padding with NOPs
Using instructions in unusual ways
SIMD code
Virtual calls using tables
Identifying compiler strings
Code which looks like it came from other C code (e.g. c lib)
Bridge code
Stack protection code in subs
Access to sourcecode indicating it's hand-written

If you see registers being used as variables, like a register referenced after more than a few lines, that would suggest it's hand written. If you see excessive memory addressing, its compiler generated.

Also
- platform specific instructions
- compilers never use xchg
- compilers always use SSE for floating points
- compilers never use sqrt* instructions
- excessive use of lea to perform arithmetic would suggest it's hand written
- compilers tend to check loop conditions at the start of a loop, in raw asm it's always preferable to check conditions at the end
- referencing constants suggests it's handwritten, compilers always inline constants

When in doubt, it's probably compiler generated because no one writes it by hand anymore.

>If you see excessive memory addressing, its compiler generated.
Either you have a shit compiler, or you forgot to enable optimizations.

Forgot one, if you see edx being referenced and eax ignored, that's 128 bit division and compilers never do it.

*after unsigned multiplication