News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

overloading x87 instructions?

Started by DC, November 11, 2005, 11:12:00 PM

Previous topic - Next topic

DC

helo again,
I seached hi and low in intel's web site and can't find this:
Quoteyou may be able to somehow define the FPU opcodes as illegal and then catch them with an illegal opcode exception handler. I think Intel had some samples on their website on how to do this.
anyone know how or where to get the docs?
thanx,
DC
this isn't daja vu, I'm just learning it for the 37th time
http://www.bmath.net

raymond

For clarification purposes, illegal opcodes could not be generated by any decent assembler. You are probably referring to invalid operations such as trying to extract the square root of a negative number, or trying to load some value into the an FPU register when the next available one is not free.

Unlike some CPU errors (such as trying to divide by 0) which would cause your program to crash, none of the FPU instructions resulting in an invalid operation would crash the program. They would simply raise a flag which can be examined by your program and, if properly designed, your program can take appropriate action. Another option instead of examine the flags after each operation is to include in your program error handling code which would be called when specific flag(s) (which you define in the Control Word) would get raised.

You may try searching the Intel documents for error handlers instead of illegal opcodes.

Although I don't cover error handlers in the following tutorial, you may still learn a few things about the FPU if you are not entirely familiar with its function.

http://www.ray.masmcode.com/fpu.html

Raymond
When you assume something, you risk being wrong half the time
http://www.ray.masmcode.com

DC

I'm trying to cause the thread to use a proc instead of an fpu instruction:
say your app calls a directx fn that uses fcos - I want the fpu to let/make my proc proccess the data in the fpu instead of fcos doing it.
I have a macro 'bcos' that I want used instead.
is there a way to hijack or redefine a hard-wired instruction?
this isn't daja vu, I'm just learning it for the 37th time
http://www.bmath.net

Eóin

Bitians eh? I don't really think what you want will be possible unless you are able to overwrite the code for the FPU instructions with calls to your functions. That would all depend on instructions sizes which I have no experience with.

roticv

Each fpu opcode is roughly 2 or 3 bytes....

Eóin

DC, I take it you are Dennis Crombie from bMath.net. You may or may not remember me but I engaged in a couple of anti-creationisim emails with you a couple of years back :U , Anyway regardless of that have you considered adapting your functions to SSE, in particular SSE2, I think some scalar and packed trig. functions would be very helpful for SSE2 programming.

MichaelW

#6
DC,
Would something like this do the job?


; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    include \masm32\include\masm32rt.inc

    bcos MACRO
      print "running fcos from bcos",13,10
      fcos equ fcos
      fcos
      fcos equ bcos
    ENDM
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    .data
        double REAL8 0.0
    .code
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
start:
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    option nokeyword:<fcos>
    fcos equ bcos

    fldpi
    fcos
    fstp  double
    invoke crt_printf, chr$("result for fcos(pi) = %f%c"), double, 10

    fldpi
    fld8  4.0
    fdiv
    fcos
    fstp  double
    invoke crt_printf, chr$("result for fcos(pi/4) = %f%c"), double, 10

    mov   eax, input(13,10,"Press enter to exit...")
    exit
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
end start


Rereading your description I see now that this would not work, because the fcos instruction being redirected would need to be in your source.

eschew obfuscation

tenkey

Quote from: DC on November 12, 2005, 06:34:21 PM
is there a way to hijack or redefine a hard-wired instruction?

You cannot redefine a "hard-wired" instruction. You would need to alter the silicon to do that.

Frankly, I don't know why you want to tamper with other people's code. Is there some purpose behind it? What effect are you trying to create?
A programming language is low level when its programs require attention to the irrelevant.
Alan Perlis, Epigram #8

zooba

Looks like he's trying to improve the performance of other peoples programs by changing how they calculate sin/cos values.

Try reading through the Exceptions chapter in Intel's IA32 Software Developer's Manual 1 - Basic Architecture (sorry, don't have a direct link). You may be able to convince the computer that the FPU does not really exist, in which case it should throw an exception on each FPU command. Whether or not you can figure out which one it was may be harder, but it could be possible.

DC

thanx guys,
hey Eóin, I remember some pretty good discussion going a while back, I think I won didn't I?  :wink
I guess I'm in way over my head, I was hoping that adding LoadLib() to an app could do miricles.
thanx MichaelW too, but that code wouldn't go deep enough into the api's or what-ever they're called.
take care all, I'm dropping this craziness and will think of a new one,
DC
this isn't daja vu, I'm just learning it for the 37th time
http://www.bmath.net

Eóin

Well I didn't win thats for sure, but I'm not propared to say I lost either :U

Seriously though have you ever considered trying to adapt your bMath code for SSE2, I really do think it would be an excellent thing to have.

DC

my system is so old I had to look up sse2 to know what it was :lol
wow! 128 bit asm, what do I need to code with that?
or will masm do it?
and do I need a P4 to build with it?
I'm interested,
DC
this isn't daja vu, I'm just learning it for the 37th time
http://www.bmath.net

Eóin

DC, SSE is basically mmx for floating point values. SSE1 was available on PIII and could operate on four packed 32bit floats. SSE2 available on PIV could work with 2 packed 64bit floats. I'm not sure which AMDS support what though.