From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26034 invoked by alias); 29 Jul 2003 13:28:15 -0000 Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org Received: (qmail 26025 invoked from network); 29 Jul 2003 13:28:12 -0000 Received: from unknown (HELO mx01.uni-tuebingen.de) (134.2.3.11) by sources.redhat.com with SMTP; 29 Jul 2003 13:28:12 -0000 Received: from bellatrix.tat.physik.uni-tuebingen.de (bellatrix.tat.physik.uni-tuebingen.de [134.2.170.113]) by mx01.uni-tuebingen.de (8.12.3/8.12.3) with ESMTP id h6TDS70w007035; Tue, 29 Jul 2003 15:28:07 +0200 Received: from bellatrix.tat.physik.uni-tuebingen.de (localhost [127.0.0.1]) by bellatrix.tat.physik.uni-tuebingen.de (8.12.3/8.12.2/SuSE Linux 0.6) with ESMTP id h6TDS7KA005217; Tue, 29 Jul 2003 15:28:07 +0200 Received: from localhost (rguenth@localhost) by bellatrix.tat.physik.uni-tuebingen.de (8.12.3/8.12.3/Submit) with ESMTP id h6TDS7wM005214; Tue, 29 Jul 2003 15:28:07 +0200 X-Authentication-Warning: bellatrix.tat.physik.uni-tuebingen.de: rguenth owned process doing -bs Date: Tue, 29 Jul 2003 14:22:00 -0000 From: Richard Guenther To: Steven Bosscher cc: gcc@gcc.gnu.org Subject: Re: std::pow implementation In-Reply-To: <1059483713.3650.148.camel@steven.lr-s.tudelft.nl> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-AntiVirus: checked by AntiVir Milter 1.0.2; AVE 6.20.0.1; VDF 6.20.0.50 X-SW-Source: 2003-07/txt/msg01988.txt.bz2 On 29 Jul 2003, Steven Bosscher wrote: > Op di 29-07-2003, om 14:55 schreef Richard Guenther: > > double foo2(double x) > > { > > pow(x, 2); > > } > > Not that it didn't even unroll the loop at all. > > I have no idea if it makes any difference, I'm just curious: What > happens if you replace > > while (__n >>= 1) > > with > while (__n = __n / 2) > ? > > Maybe the loop stuff can't handle shifts... I get it to unroll with template inline _Tp __cmath_power(_Tp __x, unsigned int __n) { _Tp __y = __n & 1 ? __x : 1; const int ni = __n == 0 ? 0 : sizeof(unsigned int)*8 - __builtin_clz(__n); for (int i=0; i>= 1; __x = __x * __x; if (__n & 1) __y = __y * __x; } return __y; } But neither the __n >>= 1; (or __n /= 2), not the following bit test is constant folded and we end up with _Z4foo2d: .LFB12: pushl %ebp # .LCFI4: movl %esp, %ebp #, .LCFI5: fldl 8(%ebp) # x movl $2, %eax #, __n fld1 fxch %st(1) # shrl %eax # tmp91 movb %al, %dl #, tmp93 fmul %st(0), %st #, andb $1, %dl #, tmp93 testb %dl, %dl # tmp93 je .L92 #, fmul %st, %st(1) #, .L92: shrl %eax # __n movb %al, %dl #, tmp93 fmul %st(0), %st #, andb $1, %dl #, tmp93 testb %dl, %dl # tmp93 je .L97 #, fmulp %st, %st(1) #, jmp .L80 # .p2align 4,,7 .L97: fstp %st(0) # .L80: popl %ebp # ret It seems this fact is worth another PR. Richard. -- Richard Guenther WWW: http://www.tat.physik.uni-tuebingen.de/~rguenth/