c/9475: Wrong ffs results
Falk Hueffner
falk.hueffner@student.uni-tuebingen.de
Tue Jan 28 13:46:00 GMT 2003
>Number: 9475
>Category: c
>Synopsis: Wrong ffs results
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: wrong-code
>Submitter-Id: net
>Arrival-Date: Tue Jan 28 12:56:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator: Falk Hueffner
>Release: 3.4 20030128 (experimental)
>Organization:
>Environment:
System: Linux juist 2.5.59 #4 Sat Jan 18 12:46:41 CET 2003 alpha unknown unknown GNU/Linux
Architecture: alpha
host: alphaev68-unknown-linux-gnu
build: alphaev68-unknown-linux-gnu
target: alphaev68-unknown-linux-gnu
configured with: ../configure --enable-languages=c++ --disable-nls
>Description:
In certain contexts, the ffs builtin gives wrong results. It does not
happen when special purpose instructions are used instead of a libcall
(-mcpu=ev67). The problem is also not present in gcc 3.2, or in gcc
3.4 20030116 (so it looks like it has been introduced very recently).
>How-To-Repeat:
% cat ffs.c
int printf(const char *format, ...);
int main(void) {
int i;
for (i = 0; i < 8; i++) {
unsigned j = 1u << i;
printf("%2d %10u %2d\n", i, j, __builtin_ffs(j));
}
return 0;
}
% gcc -O1 -W -Wall -mcpu=ev4 ffs.c && ./a.out
0 1 1
1 2 0
2 4 0
3 8 0
4 16 0
5 32 0
6 64 0
7 128 0
The correct output would be:
0 1 1
1 2 2
2 4 3
3 8 4
4 16 5
5 32 6
6 64 7
7 128 8
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the Gcc-bugs
mailing list