From: Denis V. <vd...@il...> - 2006-02-03 12:39:58
|
On Friday 03 February 2006 12:58, Andreas Mohr wrote: > -=A0=A0=A0=A0=A0=A0=A0adev->tx_head =3D (head + 1) % TX_CNT; > +=A0=A0=A0=A0=A0=A0=A0/* slower: adev->tx_head =3D (head + 1) % TX_CNT; */ > +=A0=A0=A0=A0=A0=A0=A0adev->tx_head =3D head + 1; > +=A0=A0=A0=A0=A0=A0=A0if (adev->tx_head >=3D TX_CNT) > +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0adev->tx_head =3D 0; struct a { int tx_head; }; #define TX_CNT 16 void f(struct a *adev, int head) { adev->tx_head =3D (head + 1) % TX_CNT; } void g(struct a *adev, int head) { adev->tx_head =3D head + 1; if (adev->tx_head >=3D TX_CNT) adev->tx_head =3D 0; } gcc -Os -S t.c -fomit-frame-pointer -falign-functions=3D1 -falign-labels=3D= 1 -falign-loops=3D1 -falign-jumps=3D1 -mtune=3Di386 -march=3Di386 produces: f: movl 8(%esp), %eax incl %eax movl $16, %edx movl %edx, %ecx cltd idivl %ecx movl 4(%esp), %eax movl %edx, (%eax) ret .size f, .-f =2Eglobl g .type g, @function g: movl 4(%esp), %edx movl 8(%esp), %eax incl %eax movl %eax, (%edx) cmpl $15, %eax jle .L6 movl $0, (%edx) =2EL6: ret .size g, .-g .ident "GCC: (GNU) 4.0.0" Well, gcc obviously failed to realize that "% 16" =3D=3D "& 15". I'll file a bug. Meanwhile, with & 15 f() is better: f: movl 8(%esp), %eax incl %eax andl $15, %eax movl 4(%esp), %edx movl %eax, (%edx) ret .size f, .-f =2Eglobl g .type g, @function g: movl 4(%esp), %edx movl 8(%esp), %eax incl %eax movl %eax, (%edx) cmpl $15, %eax jle .L6 movl $0, (%edx) =2EL6: ret .size g, .-g .ident "GCC: (GNU) 4.0.0" =2D- vda |