#include <stddef.h> // by J.C. Pîzarro ...
// See http://www.cs.sjsu.edu/~kirchher/CS047/multDiv.html // One-operand imul: & Unsigned mul: // warning: 32 bit, i686, possible risk of -x * -y = valid x * y, ... // warning: it's made quick & dirty, possible to give clobbered situations. // warning: it is not ready for x86-64, ppc, ppc64, etc. // NO WARRANTY!!! IT'S VERY EXPERIMENTAL!!! NOT TESTED YET!!! void *__allocate_array_OptionC(size_t num, size_t size) { unsigned int result; __asm__ __volatile__ ( "orl $-1,%%ecx" "\n\t" "imull %2" // See the flags OF, SF, CF, .. are affected or not. "\n\t" "cmovol %%ecx,%%eax" // i dude if it works or not. Not tested ... // "\n\t" "cmovcl %%ecx,%%eax" :"=a"(result) :"a"(num),"g"(size) :/*???*/); // There are 0 conditional jumps!!! hehehehe! return operator new[](result); } ----------------------------------------------------------------------------- * gcc version 4.1.3 20070326 (prerelease) * 6 instructions of i686 !!! (cmovo came from i686) * no conditional jump !!! _Z24__allocate_array_OptionCjj: movl 4(%esp), %eax #APP orl $-1,%ecx imull 8(%esp) cmovol %ecx,%eax #NO_APP movl %eax, 4(%esp) jmp _Znaj ----------------------------------------------------------------------------- J.C. Pizarro
allocate_array_20070409-1.tar.gz
Description: GNU Zip compressed data