This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Bug in gcc-20011231
>I modified the code to look like:
#include <stdio.h>
typedef unsigned char ufix8;
typedef unsigned short ufix16;
ufix8 c_val = 1;
ufix8 c_expected = 1;
ufix16 s_val = 1;
ufix16 s_expected = 1;
#define CHECK(val,i,result, expected) \
result = val % i; \
if (result != expected) { \
fprintf(stderr,"Huh? %s %d %% %d = %d\n", (sizeof(val) == 1 ? \
"char" : \
"short"), val, i, result); \
}
main(int argc, char *argv[])
{
ufix8 c_result;
ufix16 s_result;
ufix8 i;
CHECK(c_val, 3, c_result, c_expected);
CHECK(s_val, 3, s_result, s_expected);
}
And the result is:
[pbarada: /tmp] > /tmp/crap8/bin/i686-linux-gcc -v
Reading specs from /tmp/crap8/bin/../lib/gcc-lib/i686-linux/3.1/specs
Configured with: /home/pbarada/work/cvs-wavemark/cross-linux-tools/gcc-20011231/configure --target=i686-linux --prefix=/tmp/crap8/ --enable-languages=c --with-local-prefix=/tmp/crap/i686-linux
Thread model: single
gcc version 3.1 20011231 (experimental)
[pbarada: /tmp] > /tmp/crap8/bin/i686-linux-gcc -O test2.c
[pbarada: /tmp] > ./a.out
Huh? char 1 % 3 = 132
The assembler for the char modulus is:
.LM2:
movzbl c_val, %edx
movzbw %dl, %ax
imull $-85, %eax, %eax <---------- 0xffffffab
shrl $8, %eax
movb %al, %cl
shrb %cl
movb %cl, %al
addb %al, %al
addb %cl, %al
movb %dl, %cl
subb %al, %cl
cmpb c_expected, %cl
je .L2
And for the short is:
.LM3:
movzwl s_val, %ecx
movl $-1431655765, %edx <---------- 0xaaaaaaab
movl %ecx, %eax
mull %edx
shrl %edx
leal (%edx,%edx,2), %edx
movl %ecx, %eax
subl %edx, %eax
movzwl %ax, %edx
cmpw %dx, s_expected
je .L3
notice that the value calculated for the multiplier is 8 bit accurate
in the char case, and 32 bit accurate in the short case. This is
because compute_mode in expand_dvmod is QImode in the char case, and
SImode in the short case.
Any ideas???
--
Peter Barada Peter.Barada@motorola.com
Wizard 781-852-2768 (direct)
WaveMark Solutions(wholly owned by Motorola) 781-270-0193 (fax)