简体   繁体   English

GCC循环增量优化-O2及以上

[英]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.我遇到了一个奇怪的优化策略,gcc 在 -O2 及以上使用。 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). 0xffffffffffffff80 在 64 位有符号整数中是 -128(我认为)。 RCX is a scratch register, probably being used from some sort of pointer in this case. RCX 是一个临时寄存器,在这种情况下可能是从某种指针中使用的。 As it's subtracting, the -128 becomes +128.当它减去时,-128 变为 +128。 The compiler issues a set of instructions decrementing the offset by jumps of 64-bits.编译器发出一组指令,通过 64 位跳转减少偏移量。 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.这表明编译器在 128 位块上使用循环展开,其中包含一组非常具体的操作,所有这些操作都涉及减法,这在您的特定处理器上可能更快。 It would be interesting to know your CPU type and the source code that produced this assembly.了解您的 CPU 类型和生成此程序集的源代码会很有趣。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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