Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Borland Delphi > Re: Skybuck pre...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 70 of 76 Topic 3707 of 3940
Post > Topic >>

Re: Skybuck presents Faster Div 7

by "rio" <a@[EMAIL PROTECTED] > Apr 28, 2008 at 05:03 PM

"Skybuck Flying" <BloodyShame@[EMAIL PROTECTED]
> ha scritto nel messaggio
news:fce6$4814e5fd$541983fa$29141@[EMAIL PROTECTED]
> Delphi uses a different calling convention then C by default.
>
> So your supplied assembler routine is not working in Delphi:
>
> I also tried specifieing the calling convention as stdcall, and cdecl,
but
> so far it's not working...
>
> // this code not working correctly because of different calling
> conventions (?)
> // I tried none, cdecl, and stdcall, which both result in access
violation
> ?!?
> function AsmDiv7v3( Value : longword ) : longword; cdecl;
> asm
>   mov ecx, dword[esp+4]
>   mov eax, $24924925
>   mov dword[esp+4], 0

in the little i know it is easy the access violation is for the above
instruction

if i see right the functions "uns32 div7(uns32 )" "uns32 div7m(uns32 )"
should be ok for the C calling convention (is it cdecl?).

the fast one (div7) is a rewrite in assembly of the algoritm that use
the gcc C compiler for divide for 7.

Saluti
-------------------------------------
$ ./cont
 2147483648 div7 is ok
 2147483648 div7m is ok
D(div7c)=43.000000
D(div7)=25.000000
D(div7cpu)=97.000000
 -----------------------

div7 seems to be fast as 2x div7c (the function of compiler here)
that seems to be 2x div7cpu (the one that use the div assembly
instruction)

----------------------------
section DATA

global div7
global div7m
global div7cpu

section TEXT

div7:
        mov ecx, [esp+4]
        mov eax, 613566757
        mul ecx
        sub ecx, edx
        shr ecx, 1
        lea eax, [edx+ecx]
        shr eax, 2
        ret

div7m:
          mov edx, dword[esp+4]
          xor ecx, ecx
          mov eax, 0x24924925
..0:
          cmp edx, 1431655764
          jbe .1
          sub edx, 1431655764
          add ecx, 204522252
          jmp short .0
..1:
          mul edx
          mov eax, edx
          add eax, ecx
          ret

div7cpu:
          mov ecx, 7
          xor edx, edx
          mov eax, [esp+4]
          div ecx
          ret

----------------------

#include <stdio.h>
#include <time.h>

unsigned div7(unsigned);
unsigned div7m(unsigned);
unsigned div7cpu(unsigned);
unsigned div7c(unsigned a) {return a/7;}

double tempo( unsigned (*f)(unsigned))
{double r;
  time_t i, e;
  unsigned a;

  i=time(0);
  for(a=1; a; ++a)
       {//if(a%0x40000000==0) {printf(" %u ", a); fflush(stdout);}
         (*f)(a);
        }
  e=time(0);
  r=difftime(e, i);
  return r;
}

int check(unsigned (*f)(unsigned))
{unsigned a=1, b, bb, i=0;

l0:;
  b = (*f)(a);
  bb=a/7;
  if(bb!=b)
          {++i;
           printf("%u/7=%u but it should be %u\n", a, b, bb);
           fflush(stdout);
         }
  if(a%0x80000000==0) {printf(" %u ", a); fflush(stdout);}
  if(i>=15) return 0;
  ++a;
  if(a) goto l0;
  return 1;
}

int main(void)
{double r;

 check(div7)==1 ?
           printf("div7 is ok\n"): printf("Error for div7 \n");

 check(div7m)==1?
           printf("div7m is ok\n"): printf("Error for div7m \n");

 r=tempo(div7c);    printf("D(div7c)=%f\n", r);
 r=tempo(div7);      printf("D(div7)=%f\n", r);
 r=tempo(div7cpu); printf("D(div7cpu)=%f\n", r);

 return 0;
}

----------------------------------
the assembly that i use, in above there are the nasm instructions
-------------------------------------
section  DATA
global   div7
global   div7m
global   div7cpu
section  TEXT

div7:
c=[s+4]; a=613566757; mul c; c-=r; c>>=1; a=&[r+c]; a>>=2; ret

div7m: r=D[s+4]; c^=c; a=0x24924925;
..0:   r<=1431655764#.1;  r-=1431655764; c+=204522252; #.0;
..1:   mul r; a=r; a+=c; ret

div7cpu: c=7; r^=r; a=[s+4]; div c; ret
------------------------------------------
 




 76 Posts in Topic:
Skybuck presents Faster Div 7
"Skybuck Flying"  2008-04-23 13:52:52 
Re: Skybuck presents Faster Div 7
"Skybuck Flying"  2008-04-23 15:09:13 
Re: Skybuck presents alternative division method, to be benchmar
"Skybuck Flying"  2008-04-24 16:01:10 
Re: Skybuck presents alternative division method, to be benchmar
"Skybuck Flying"  2008-04-24 16:13:18 
Re: Skybuck presents alternative division method, to be benchmar
"Skybuck Flying"  2008-04-24 16:29:27 
Re: Skybuck presents alternative division method, to be benchmar
"Skybuck Flying"  2008-04-24 16:38:18 
Re: Skybuck presents alternative division method, to be benchmar
"Skybuck Flying"  2008-04-24 16:51:19 
Re: Skybuck presents alternative division method, to be benchmar
"Skybuck Flying"  2008-04-24 17:09:28 
Re: Skybuck presents alternative division method, to be benchmar
Locke <jlocke@[EMAIL P  2008-04-24 16:09:04 
Re: Skybuck presents alternative division method, to be benchmar
"Skybuck Flying"  2008-04-24 17:27:06 
Re: Skybuck presents alternative division method, to be benchmar
Locke <jlocke@[EMAIL P  2008-04-24 16:34:45 
Re: Skybuck presents alternative division method, to be benchmar
"Skybuck Flying"  2008-04-24 17:49:19 
Re: Skybuck presents alternative division method, to be benchmar
Zathras <webnewsgroup@  2008-04-24 17:30:08 
Re: Skybuck presents alternative division method, to be benchmar
spam2you <spam2you@[EM  2008-05-29 22:13:09 
Re: Skybuck presents alternative division method, to be benchmar
"Fritz Franz" &  2008-05-29 22:43:38 
Re: Skybuck presents alternative division method, to be benchmar
"Skybuck Flying"  2008-04-24 17:14:38 
Re: Skybuck presents alternative division method, to be benchmar
"Skybuck Flying"  2008-04-24 17:20:14 
Re: Skybuck presents alternative division method, to be benchmar
"Skybuck Flying"  2008-04-24 17:26:48 
Re: Skybuck presents Faster Div 7
Locke <jlocke@[EMAIL P  2008-04-23 16:12:07 
Re: Skybuck presents Faster Div 7
"Skybuck Flying"  2008-04-23 19:27:30 
Re: Skybuck presents Faster Div 7
Locke <jlocke@[EMAIL P  2008-04-23 18:31:32 
Re: Skybuck presents Faster Div 7
"Skybuck Flying"  2008-04-24 04:27:50 
Re: Skybuck presents Faster Div 7
Locke <jlocke@[EMAIL P  2008-04-24 15:58:03 
Re: Skybuck presents Faster Div 7
"Skybuck Flying"  2008-04-24 17:19:29 
Re: Skybuck presents Faster Div 7
Locke <jlocke@[EMAIL P  2008-04-24 16:26:15 
Re: Skybuck presents Faster Div 7
"Skybuck Flying"  2008-04-24 17:47:58 
Re: Skybuck presents Faster Div 7
Locke <jlocke@[EMAIL P  2008-04-24 16:56:04 
Re: Skybuck presents Faster Div 7
"Skybuck Flying"  2008-04-24 18:07:57 
Re: Skybuck presents Faster Div 7
Locke <jlocke@[EMAIL P  2008-04-24 17:13:12 
Re: Skybuck presents Faster Div 7
"Skybuck Flying"  2008-04-24 18:24:40 
Re: Skybuck presents Faster Div 7
"Skybuck Flying"  2008-04-24 18:32:42 
Re: Skybuck presents Faster Div 7
"Skybuck Flying"  2008-04-24 18:38:19 
Re: Skybuck presents Faster Div 7
"Skybuck Flying"  2008-04-24 18:45:22 
Re: Skybuck presents Faster Div 7
"Skybuck Flying"  2008-04-24 18:46:58 
Re: Skybuck presents Faster Div 7
"Skybuck Flying"  2008-04-24 18:50:34 
Re: Skybuck presents Faster Div 7
Locke <jlocke@[EMAIL P  2008-04-24 18:42:15 
Re: Skybuck presents Faster Div 7
"Skybuck Flying"  2008-04-24 19:51:14 
Re: Skybuck presents Faster Div 7
Locke <jlocke@[EMAIL P  2008-04-24 18:46:57 
Re: Skybuck presents Faster Div 7
"Wolfgang Kern"  2008-04-24 21:00:06 
Re: Skybuck presents Faster Div 7
"Skybuck Flying"  2008-04-25 08:14:52 
Re: Skybuck presents Faster Div 7
"Skybuck Flying"  2008-04-25 10:06:43 
Re: Skybuck presents Faster Div 7
"Skybuck Flying"  2008-04-25 10:23:26 
Re: Skybuck presents Faster Div 7
Locke <jlocke@[EMAIL P  2008-04-25 12:48:07 
Re: Skybuck presents Faster Div 7
"Skybuck Flying"  2008-04-26 13:06:28 
Re: Skybuck presents Faster Div 7
Locke <jlocke@[EMAIL P  2008-04-26 13:16:38 
Re: Skybuck presents Faster Div 7
"Skybuck Flying"  2008-04-26 17:53:54 
Re: Skybuck presents Faster Div 7
Locke <jlocke@[EMAIL P  2008-04-26 17:21:05 
Re: Skybuck presents Faster Div 7
"Skybuck Flying"  2008-04-25 09:19:40 
Re: Skybuck presents Faster Div 7
Locke <jlocke@[EMAIL P  2008-04-25 12:56:12 
Re: Skybuck presents Faster Div 7
"Skybuck Flying"  2008-04-26 09:13:05 
Re: Skybuck presents Faster Div 7
Locke <jlocke@[EMAIL P  2008-04-24 18:45:37 
Re: Skybuck presents Faster Div 7
"Skybuck Flying"  2008-04-24 18:33:57 
Re: Skybuck presents Faster Div 7
Robert Redelmeier <red  2008-04-24 15:41:25 
Re: Skybuck presents Faster Div 7
"Skybuck Flying"  2008-04-24 17:58:48 
Re: Skybuck presents Faster Div 7
Chuck Crayne <ccrayne@  2008-04-23 20:59:04 
Re: Skybuck presents Faster Div 7
"Skybuck Flying"  2008-04-24 06:54:54 
Re: Skybuck presents Faster Div 7
"Wolfgang Kern"  2008-04-24 11:45:40 
Re: Skybuck presents Faster Div 7
Robert Redelmeier <red  2008-04-24 12:23:15 
Re: Skybuck presents Faster Div 7
"Wolfgang Kern"  2008-04-24 20:53:17 
Re: Skybuck presents Faster Div 7
"Skybuck Flying"  2008-04-25 08:17:20 
Re: Skybuck presents Faster Div 7
Robert Redelmeier <red  2008-04-25 13:38:45 
Re: Skybuck presents Faster Div 7
"rio" <a@[EM  2008-04-25 22:40:49 
Re: Skybuck presents Faster Div 7
"Skybuck Flying"  2008-04-26 09:11:45 
Re: Skybuck presents Faster Div 7
"Wolfgang Kern"  2008-04-26 12:58:17 
Re: Skybuck presents Faster Div 7
"Skybuck Flying"  2008-04-26 17:48:37 
Re: Skybuck presents Faster Div 7
"rio" <a@[EM  2008-04-27 07:43:48 
Re: Skybuck presents Faster Div 7
"Skybuck Flying"  2008-04-27 09:50:19 
Re: Skybuck presents Faster Div 7
"rio" <a@[EM  2008-04-27 22:01:40 
Re: Skybuck presents Faster Div 7
"Skybuck Flying"  2008-04-27 22:51:40 
Re: Skybuck presents Faster Div 7
"rio" <a@[EM  2008-04-28 17:03:57 
Re: Skybuck presents Faster Div 7
"rio" <a@[EM  2008-04-28 17:22:36 
Re: Skybuck presents Faster Div 7
"Skybuck Flying"  2008-05-02 06:59:08 
Re: Skybuck presents Faster Div 7
"Wolfgang Kern"  2008-04-27 10:13:24 
Re: Skybuck presents Faster Div 7
"Skybuck Flying"  2008-04-24 14:43:09 
Re: Skybuck presents BitLength
"Skybuck Flying"  2008-04-26 07:00:39 
Re: Skybuck presents BitLength
"Skybuck Flying"  2008-04-26 07:13:22 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Mon Oct 6 15:52:09 CDT 2008.