Assembler Developer

Moderators: None (Apply to moderate this forum)
Number of threads: 1030
Number of posts: 1826

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Coprocessor hazards? Posted by vlad777 on 18 Oct 2010 at 6:16 AM
I wrote these float procedures and I found out that
they create problems:
My program is unpredictable and comp reboots.
Only after hours of debugging I conclude these functions
are the problem.

So what do I do to make them usable?

Thanks.


double mylog2(double nb){
double rez,y=1;
_asm{
fld [y]
fld [nb]
fyl2x
fstp [rez]
}
return rez;
}


double myexp2(double nb){
double rez,rez2,y=1,nbi,nbf;
short fcv,fcb;

_asm{
fstcw fcv
mov ax,fcv
mov fcb,ax
or fcv,0xC00
//------------
fld [nb]
fldcw fcv
frndint
fldcw fcb
fstp [nbi]
}
nbf=nb-nbi;
_asm{
fld [nbf]
f2xm1
fstp [rez2]
//-------------
fld [nbi]
fld [y]
fscale
fstp [rez]
}
rez*=(rez2+1);
return (rez);
}



Report
Re: Coprocessor hazards? Posted by vlad777 on 18 Oct 2010 at 2:59 PM
I added finit and fwait and now it seems to be OK.
Is there anything else I should do?

Thanks.
Report
Re: Coprocessor hazards? Posted by AsmGuru62 on 20 Oct 2010 at 4:29 PM

1st question would be why in some places you use brackets [] and in some you do not?

like:

fld [<some double value>]

but in other place:

fstcw fcv <-- why no brackets here?

Just curious.
I never used FPU in inline ASM - only in FASM.

In my experience FPU exceptions happens when FPU is not cleared of results and other calculation remains. For example if you push something into top of the stack (say with FLD instruction) and all 8 registers are busy - you get an exception.

That is maybe why FINIT helps - however, using it in every single case of FPU calculations - the performance suffers.

Also, some C/C++ run-time functions (or even some 3rd party functions) use MMX registers and they will damage FPU content too - because MMX registers are same physically as ST0 - ST7 in FPU. So, you can't mix FPU code with some library calls which use MMX.
Report
Re: Coprocessor hazards? Posted by vlad777 on 21 Oct 2010 at 8:50 AM
I suppose i should use brackets everywhere (in this case)
but MS VS6 does not make the difference so I got sloppy.
I use finit only at the beginning of the function.
Crossed my mind about MMX but wasn't sharing of registers
only true for earliest Pentium processors?
Report
Re: Coprocessor hazards? Posted by AsmGuru62 on 22 Oct 2010 at 3:57 AM

Yes, indeed - both reg sets occupy same room.
http://softpixel.com/~cwright/programming/simd/mmx.php



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.