[PATCH 1/7] bb_ioctl implementation - improved
Denis Vlasenko
vda.linux at googlemail.com
Sat Jul 14 19:42:34 UTC 2007
On Wednesday 11 July 2007 23:13, Bernhard Fischer wrote:
> >I know but i'm pretty sure that in all places in busybox where this test was used
> >[ !=0 ] it errored out, i double checked it, but nonetheless maybe its a good idea
> >to change it to [ < 0 ] to be more coherent with the original ioctl call.
> >So attached is a fixed patch.
>
> checking for != 0 is imho not a good idea as opposed to <0. The idea is
> sound in my POV, i didn't have a chance to review it, though
This was quite puzzling for me. Try to guess which is smallest (on i386)?
* if (f() != 0)
* if (f() < 0)
* if (f() == -1)
Third one is smallest! gcc just does "inc eax; j[n]z label"; which is just 3 bytes:
# cat t.c
int f();
void g();
void t1() { if (f()) g(); }
void t2() { if (f() < 0) g(); }
void t3() { if (f() == -1) g(); }
# gcc -Os -fomit-frame-pointer -S t.c
# cat t.s [ ABRIDGED]
t3:
subl $12, %esp
call f
incl %eax
jne .L4
addl $12, %esp
jmp g
.L4:
addl $12, %esp
ret
t2:
subl $12, %esp
call f
testl %eax, %eax
jns .L8
addl $12, %esp
jmp g
.L8:
addl $12, %esp
ret
t1:
subl $12, %esp
call f
testl %eax, %eax
je .L12
addl $12, %esp
jmp g
.L12:
addl $12, %esp
ret
[Wow, apparently my gcc (4.1.2) has a "I like to masturbate with %esp" habit :((
How to beat it into sanity?]
Overall, bb_ioctl patch idea looks great, will review it in a few seconds!
Big thanks Tito!
--
vda
More information about the busybox
mailing list