This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Loop unrolling
- To: law at cygnus dot com
- Subject: Re: Loop unrolling
- From: Branko Cibej <branko dot cibej at hermes dot si>
- Date: Tue, 02 Jun 1998 17:10:38 +0200
- Cc: Lee Iverson <leei at ai dot sri dot com>, Stephen Williams <steve at icarus dot icarus dot com>, Gerald Pfeifer <pfeifer at dbai dot tuwien dot ac dot at>, egcs at cygnus dot com
- Organization: HERMES SoftLab
- References: <4456.896772748@hurl.cygnus.com>
Jeffrey A Law wrote:
> If you can provide source examples which show C++ & Java creating empty
> loops behind the programmer's back it would go a long way to convincing
> everyone that eliminating empty loops is a good idea.
I don't know about Java, but it's terribly easy to do in C++:
$ c++ -v
Reading specs from /opt/freeware/gnu/lib/gcc-lib/sparc-sun-solaris2.6/2.8.1/specs
gcc version 2.8.1
$ c++ -O2 -save-temps dead_loop.cc
If I read the gibberish in dead_loop.s correctly. there are two empty loops in
main, at .LL211 and .LL212.
--
Branko Cibej <branko.cibej@hermes.si>
HERMES SoftLab, Litijska 51, 1000 Ljubljana, Slovenia
phone: (++386 61) 186 53 49 fax: (++386 61) 186 52 70
/* container.h -*- C++ -*- */
template <typename T> class container {
public:
container (size_t s, T const& init)
: size (s),
objs (static_cast<T*>(malloc (size * sizeof (T))))
{
if (objs)
{
for (size_t i = 0; i < size; ++i)
new (&objs[i]) T(init);
}
}
~container ()
{
if (objs)
{
for (size_t i = 0; i < size; ++i)
objs[i].~T();
free (objs);
}
}
T* get (size_t i)
{
if (!objs || i >= size)
return 0;
return &objs[i];
}
private:
size_t size;
T* objs;
};
#include <cstdlib>
#include <new>
#include "container.h"
struct dummy {
dummy () {}
dummy (dummy const&) {}
~dummy () {}
};
int main ()
{
container<dummy> dumdum(13, dummy());
return 0;
}
.file "dead_loop.cc"
gcc2_compiled.:
.global __throw
.section ".rodata"
.align 8
.LLC0:
.asciz "bad_alloc"
.section ".text"
.align 4
.global main
.type main,#function
.proc 04
main:
.LLFB1:
!#PROLOGUE# 0
save %sp,-128,%sp
.LLCFI0:
!#PROLOGUE# 1
.LLEHB133:
mov 13,%o0
call malloc,0
st %o0,[%fp-24]
cmp %o0,0
be .LL162
st %o0,[%fp-20]
ld [%fp-24],%o0
mov 0,%o1
cmp %o1,%o0
bgeu .LL210
ld [%fp-20],%o0
ld [%fp-24],%o0
add %o1,1,%o1
.LL211:
cmp %o1,%o0
blu .LL211
add %o1,1,%o1
.LLEHE133:
b .LL210
ld [%fp-20],%o0
.LL132:
nop
.LL162:
.LLEHB168:
.LLEHB171:
ld [%fp-20],%o0
.LL210:
cmp %o0,0
be .LL182
ld [%fp-24],%o1
mov 0,%o0
cmp %o0,%o1
bgeu .LL181
add %o0,1,%o0
.LL212:
cmp %o0,%o1
blu .LL212
add %o0,1,%o0
.LL181:
call free,0
ld [%fp-20],%o0
.LL182:
.LLEHE171:
b .LL209
mov 0,%i0
.LLEHE168:
.LL167:
nop
.LLEHB207:
.LL133:
sethi %hi(__eh_pc),%o1
sethi %hi(.LL132),%o0
or %o0,%lo(.LL132),%o0
call __throw,0
st %o0,[%o1+%lo(__eh_pc)]
.LL168:
ld [%fp-20],%o0
cmp %o0,0
be .LL201
ld [%fp-24],%o1
mov 0,%o0
cmp %o0,%o1
bgeu .LL200
add %o0,1,%o0
.LL213:
cmp %o0,%o1
blu .LL213
add %o0,1,%o0
.LL200:
call free,0
ld [%fp-20],%o0
.LL201:
sethi %hi(__eh_pc),%o1
sethi %hi(.LL167),%o0
or %o0,%lo(.LL167),%o0
call __throw,0
st %o0,[%o1+%lo(__eh_pc)]
.LL171:
sethi %hi(__eh_pc),%o1
sethi %hi(.LL167),%o0
or %o0,%lo(.LL167),%o0
call __throw,0
st %o0,[%o1+%lo(__eh_pc)]
.LLEHE207:
.LL207:
call terminate__Fv,0
nop
.LL209:
ret
restore
.LLFE1:
.LLfe1:
.size main,.LLfe1-main
.section ".gcc_except_table",#alloc,#write
.align 4
__EXCEPTION_TABLE__:
.uaword .LLEHB133
.uaword .LLEHE133
.uaword .LL133
.uaword .LLEHB168
.uaword .LLEHE168
.uaword .LL168
.uaword .LLEHB171
.uaword .LLEHE171
.uaword .LL171
.uaword .LLEHB207
.uaword .LLEHE207
.uaword .LL207
__EXCEPTION_END__:
.uaword -1
.uaword -1
.uaword -1
.section ".eh_frame",#alloc,#write
__FRAME_BEGIN__:
.uaword .LLECIE1-.LLSCIE1
.LLSCIE1:
.uaword 0x0
.byte 0x1
.asciz "eh"
.uaword __EXCEPTION_TABLE__
.byte 0x1
.byte 0x7c
.byte 0x65
.byte 0xc
.byte 0xe
.byte 0x0
.byte 0x9
.byte 0x65
.byte 0xf
.align 4
.LLECIE1:
.uaword .LLEFDE1-.LLSFDE1
.LLSFDE1:
.uaword .LLSFDE1-__FRAME_BEGIN__
.uaword .LLFB1
.uaword .LLFE1-.LLFB1
.byte 0x4
.uaword .LLCFI0-.LLFB1
.byte 0xd
.byte 0x1e
.byte 0x2d
.byte 0x9
.byte 0x65
.byte 0x1f
.align 4
.LLEFDE1:
.ident "GCC: (GNU) 2.8.1"