* Re: Integer overflow in operator new. Solved? Experimental i686 code.
@ 2007-04-09 22:17 J.C. Pizarro
0 siblings, 0 replies; 2+ messages in thread
From: J.C. Pizarro @ 2007-04-09 22:17 UTC (permalink / raw)
To: gcc
[-- Attachment #1: Type: text/plain, Size: 1747 bytes --]
#include <stddef.h> // by J.C. Pîzarro
...
// This function doesn't touch the ECX register that is touched by OptionC.
__volatile__ static const int minus_one = -1;
void *__allocate_array_OptionD(size_t num, size_t size) {
register unsigned int result;
__asm__ __volatile__
(
"imull %2" // See the flags OF, SF, CF, .. are affected or not.
"\n\t" "cmovol %3,%%eax" // i dude if it works or not. Not tested ...
// "\n\t" "cmovcl %3,%%eax"
:"=a"(result)
:"a"(num),"m"(size),"m"(minus_one)
:"%edx"/*???*/); // 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_OptionDjj:
subl $12, %esp # <- unneeded
movl 16(%esp), %eax
#APP
imull 20(%esp)
cmovol minus_one,%eax
#NO_APP
movl %eax, (%esp) # <- better movl %eax, 4(%esp)
call _Znaj # <- better jmp _Znaj
addl $12, %esp # <- unneeded
ret # <- unneeded
minus_one:
.long -1
-----------------------------------------------------------------------------
* hand-written
* 5 instructions of i686 !!! (cmovo came from i686)
* no conditional jump !!!
_Z24__allocate_array_OptionDjj:
movl 4(%esp), %eax
#APP
imull 8(%esp)
cmovol minus_one,%eax
#NO_APP
movl %eax, 4(%esp)
jmp _Znaj
minus_one:
.long -1
-----------------------------------------------------------------------------
Here has reached 5 instructions.
Anyone with 4 instructions?
J.C. Pizarro
[-- Attachment #2: allocate_array_20070409-2.tar.gz --]
[-- Type: application/x-gzip, Size: 1486 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Integer overflow in operator new. Solved? Experimental i686 code.
@ 2007-04-09 21:08 J.C. Pizarro
0 siblings, 0 replies; 2+ messages in thread
From: J.C. Pizarro @ 2007-04-09 21:08 UTC (permalink / raw)
To: gcc
[-- Attachment #1: Type: text/plain, Size: 1363 bytes --]
#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
[-- Attachment #2: allocate_array_20070409-1.tar.gz --]
[-- Type: application/x-gzip, Size: 1221 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2007-04-09 22:17 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-04-09 22:17 Integer overflow in operator new. Solved? Experimental i686 code J.C. Pizarro
-- strict thread matches above, loose matches on Subject: below --
2007-04-09 21:08 J.C. Pizarro
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).