简体   繁体   中英

GCC Loop Increment Optimization -O2 and above

I've been doing some research involving optimization and loop unrolling and I've been looking at the generated assembly code for different optimization levels. I've come across a weird optimization strategy that gcc uses at -O2 and above. I was wondering if there was a name for this. Here's the generated assembly code:

mov    %rsi,(%rcx)
mov    %rsi,0x8(%rcx)
mov    %rsi,0x10(%rcx)
mov    %rsi,0x18(%rcx)
sub    $0xffffffffffffff80,%rcx // What is this called?
mov    %rsi,-0x60(%rcx)
mov    %rsi,-0x58(%rcx)
mov    %rsi,-0x50(%rcx)
mov    %rsi,-0x48(%rcx)
mov    %rsi,-0x38(%rcx)
mov    %rsi,-0x30(%rcx)
mov    %rsi,-0x28(%rcx)
mov    %rsi,-0x20(%rcx)
mov    %rsi,-0x18(%rcx)
mov    %rsi,-0x10(%rcx)
mov    %rsi,-0x8(%rcx)
cmp    %rdx,%r8

0xffffffffffffff80 is -128 in 64-bit signed integers (I think). RCX is a scratch register, probably being used from some sort of pointer in this case. As it's subtracting, the -128 becomes +128. The compiler issues a set of instructions decrementing the offset by jumps of 64-bits. This indicates that the compiler is using loop-unrolling on blocks of 128-bits with a very specific set of operations all of which involve subtractions which may possibly be faster on your specific processor. It would be interesting to know your CPU type and the source code that produced this assembly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM