LWN.net Logo

Cracks in the Foundation (PHP Advent)

Cracks in the Foundation (PHP Advent)

Posted Jan 3, 2012 12:41 UTC (Tue) by etienne (subscriber, #25256)
In reply to: Cracks in the Foundation (PHP Advent) by jezuch
Parent article: Cracks in the Foundation (PHP Advent)

>> returning flags from functions
> You mean like the errno variable?

Not really, errno is a global variable - I was thinking of something very fast at the asssembly level, for the million of use case.
Something like (doesn't really work in C):

unsigned mybitfield, bitindex;
ifzeroset(bitno = ffs(mybitfield)) // ffs = find first bit set
error("none bit are set");
else
bitindex = bitno;

Translated in ia32 assembler by:
ffs eax,edx
jz call_error
mov edx,bitindex

You can replace ffs by strchr or any basic function which may not be inlined.
Maybe it could also be implemented in GCC by:
register struct flags {
unsigned zero : 1;
unsigned carry : 1;
...
} flags asm ("cc");
but the modification of flags by so many assembly instruction is probably a problem (reordering instructions optimisations).


(Log in to post comments)

Copyright © 2013, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds