Author |
Message |
Cyan~Fire I'll count you!

Age:37 Gender: Joined: Jul 14 2003 Posts: 4608 Location: A Dream Offline
|
Posted: Tue Mar 22, 2005 5:03 pm Post maybe stupid Post subject: Asm |
 |
|
|
|
Trying to read the ASM Ekted posted here. And I'll have a few questions which I'll post them here.
First: I see xor with the same register as both operands a lot. My best guess is that this is some more efficient way of doing mov eax,0. Am I right? _________________ This help is informational only. No representation is made or warranty given as to its content. User assumes all risk of use. Cyan~Fire assumes no responsibility for any loss or delay resulting from such use.
Wise men STILL seek Him. |
|
Back to top |
|
 |
Bak ?ls -s 0 in

Age:26 Gender: Joined: Jun 11 2004 Posts: 1826 Location: USA Offline
|
|
Back to top |
|
 |
Cyan~Fire I'll count you!

Age:37 Gender: Joined: Jul 14 2003 Posts: 4608 Location: A Dream Offline
|
Posted: Tue Mar 22, 2005 5:32 pm Post maybe stupid Post subject: |
 |
|
|
|
Then why do it? It's a little easier to read the other way... |
|
Back to top |
|
 |
Dr Brain Flip-flopping like a wind surfer

Age:39 Gender: Joined: Dec 01 2002 Posts: 3502 Location: Hyperspace Offline
|
Posted: Tue Mar 22, 2005 5:35 pm Post maybe stupid Post subject: |
 |
|
|
|
Job security  _________________ Hyperspace Owner
Smong> so long as 99% deaths feel lame it will always be hyperspace to me |
|
Back to top |
|
 |
Mr Ekted Movie Geek

Gender: Joined: Feb 09 2004 Posts: 1379 Offline
|
Posted: Tue Mar 22, 2005 5:55 pm Post maybe stupid Post subject: |
 |
|
|
|
On the Pentium, MOV EAX, 0 and XOR EAX,EAX are 0.5 clocks latency and 0.5 clocks throughput. However, the former is 6 bytes long, and the latter is 2. Job security. _________________ 4,691 irradiated haggis! |
|
Back to top |
|
 |
Cyan~Fire I'll count you!

Age:37 Gender: Joined: Jul 14 2003 Posts: 4608 Location: A Dream Offline
|
|
Back to top |
|
 |
Bak ?ls -s 0 in

Age:26 Gender: Joined: Jun 11 2004 Posts: 1826 Location: USA Offline
|
|
Back to top |
|
 |
Cyan~Fire I'll count you!

Age:37 Gender: Joined: Jul 14 2003 Posts: 4608 Location: A Dream Offline
|
Posted: Tue Mar 22, 2005 7:18 pm Post maybe stupid Post subject: |
 |
|
|
|
So you're saying it's basically just the equivalent of imul 25? |
|
Back to top |
|
 |
Mr Ekted Movie Geek

Gender: Joined: Feb 09 2004 Posts: 1379 Offline
|
Posted: Tue Mar 22, 2005 7:23 pm Post maybe stupid Post subject: |
 |
|
|
|
Ya you can do all sorts of multiplies using chains of LEA ops. The throughput of MUL is 5 cycles since it must function on arbitrary data. The throughput of LEA is 0.5 cycles since it works in very constrained ways. |
|
Back to top |
|
 |
CypherJF I gargle nitroglycerin

Gender: Joined: Aug 14 2003 Posts: 2582 Location: USA Offline
|
Posted: Tue Mar 22, 2005 8:00 pm Post maybe stupid Post subject: |
 |
|
|
|
ya okay i feel dumb lol... i haven't learned ASM :/ _________________ Performance is often the art of cheating carefully. - James Gosling |
|
Back to top |
|
 |
Cyan~Fire I'll count you!

Age:37 Gender: Joined: Jul 14 2003 Posts: 4608 Location: A Dream Offline
|
|
Back to top |
|
 |
Mr Ekted Movie Geek

Gender: Joined: Feb 09 2004 Posts: 1379 Offline
|
Posted: Tue Mar 22, 2005 10:05 pm Post maybe stupid Post subject: |
 |
|
|
|
IDIV uses the 2 registers EDX:EAX as the source. |
|
Back to top |
|
 |
Cyan~Fire I'll count you!

Age:37 Gender: Joined: Jul 14 2003 Posts: 4608 Location: A Dream Offline
|
Posted: Tue Mar 22, 2005 10:19 pm Post maybe stupid Post subject: |
 |
|
|
|
Oh, haha, didn't see that in the docs. Maybe it would help if I had 32-bit docs instead of 16-bit ones. Does anybody have a good opcode list for 32-bit ASM? |
|
Back to top |
|
 |
Mr Ekted Movie Geek

Gender: Joined: Feb 09 2004 Posts: 1379 Offline
|
|
Back to top |
|
 |
Cyan~Fire I'll count you!

Age:37 Gender: Joined: Jul 14 2003 Posts: 4608 Location: A Dream Offline
|
|
Back to top |
|
 |
Bak ?ls -s 0 in

Age:26 Gender: Joined: Jun 11 2004 Posts: 1826 Location: USA Offline
|
|
Back to top |
|
 |
Cyan~Fire I'll count you!

Age:37 Gender: Joined: Jul 14 2003 Posts: 4608 Location: A Dream Offline
|
|
Back to top |
|
 |
Mr Ekted Movie Geek

Gender: Joined: Feb 09 2004 Posts: 1379 Offline
|
Posted: Wed Mar 23, 2005 3:41 pm Post maybe stupid Post subject: |
 |
|
|
|
Powerbot's implementation uses <= 0. |
|
Back to top |
|
 |
Cyan~Fire I'll count you!

Age:37 Gender: Joined: Jul 14 2003 Posts: 4608 Location: A Dream Offline
|
Posted: Wed Mar 23, 2005 4:42 pm Post maybe stupid Post subject: |
 |
|
|
|
Oh, alright, cool. I'll talk to Catid about that sometime.
Sixth:
// :0041BF40
a = seed;
/*
cdq
xor eax, edx
sub eax, edx
and eax, 00000003
xor eax, edx
*/
d = (a < 0) ? 0xFFFFFFFF : 0; //cdq
a ^= d;
a -= d;
a &= 1;
a ^= d;
/*
mov ebx,eax
...
sub ebx,edx
neg ebx
...
sbb ebx,ebx
*/
b = (a - d == 0) ? -1 : 0;
b &= 17; //get 000X000X |
Now edx is either -1 or 0, depending on whether eax is negative. But now in the above PRNG code, the seed was always return positive. Am I missing something? Is most of the above code actually useless? |
|
Back to top |
|
 |
Mr Ekted Movie Geek

Gender: Joined: Feb 09 2004 Posts: 1379 Offline
|
|
Back to top |
|
 |
Cyan~Fire I'll count you!

Age:37 Gender: Joined: Jul 14 2003 Posts: 4608 Location: A Dream Offline
|
Posted: Wed Mar 23, 2005 8:48 pm Post maybe stupid Post subject: |
 |
|
|
|
Well this is what I had (and still have):
inline int SS_prng(int seed)
{
int nseed, temp;
/*
mov eax, esi ; esi = seed
mov ecx, 0001F31D
cdq
idiv ecx ; }
mov eax, edx ; } modulus
shl eax, 03
sub eax, edx
lea eax, dword[eax+4*eax]
lea eax, dword[eax+4*eax]
shl eax, 04
add eax, edx
lea eax, dword[eax+2*eax]
lea ecx, dword[edx+2*eax]
*/
nseed = (seed % DIV_C) * 16807;
/*
mov eax, 834E0B5F
imul esi
add edx, esi
sar edx, 10
mov eax, edx
shr eax, 1F
add edx, eax
lea eax, dword[edx+8*edx]
shl eax, 03
sub eax, edx
lea eax, dword[eax+4*eax]
shl eax, 1
sub eax, edx
shl eax, 02
sub ecx, eax
*/
temp = IMULHIDWORD(MULT_C, seed) + seed;
temp = (temp >> 16) + (temp >> 31); //aka the sign bit
nseed -= (temp * 2836);
nseed += 123;
/*
cmp ecx, ebp ;above, ebp = 0
mov esi, ecx
jg 0041BF40
lea esi, dword[ecx+7FFFFFFF]
*/
seed = nseed;
if (nseed <= 0)
seed += 0x7FFFFFFF;
return seed;
} |
Looks basically the same, except uses asm's imul instead of __int64. But that's actually kinda irrelevant.
What I was trying to ask is that if the left-most bit is always 0, then the return is always positive, right? Thus, cdq'ing the seed and then xor'ing it by edx is never going to modify it. edx will always be 0. Am I right? I'm trying to make something to test it right now... |
|
Back to top |
|
 |
Cyan~Fire I'll count you!

Age:37 Gender: Joined: Jul 14 2003 Posts: 4608 Location: A Dream Offline
|
Posted: Wed Mar 23, 2005 8:58 pm Post maybe stupid Post subject: |
 |
|
|
|
Here's my test prog, using the same SS_prng func I pasted earlier. Only output was "Done.". |
|
Back to top |
|
 |
Mr Ekted Movie Geek

Gender: Joined: Feb 09 2004 Posts: 1379 Offline
|
Posted: Wed Mar 23, 2005 9:26 pm Post maybe stupid Post subject: |
 |
|
|
|
Using signed type for seed instead of unsigned can affect the results of operations. Are you sure it matches the output of the origional ASM for a large number of different seeds?? |
|
Back to top |
|
 |
Cyan~Fire I'll count you!

Age:37 Gender: Joined: Jul 14 2003 Posts: 4608 Location: A Dream Offline
|
Posted: Wed Mar 23, 2005 9:49 pm Post maybe stupid Post subject: |
 |
|
|
|
This didn't show anything wrong. I couldn't use the original ASM because MSVC++ didn't like it. |
|
Back to top |
|
 |
Cyan~Fire I'll count you!

Age:37 Gender: Joined: Jul 14 2003 Posts: 4608 Location: A Dream Offline
|
|
Back to top |
|
 |
|