Newsgroups: comp.sys.amiga.programmer
Path: utzoo!utgpu!bhgs
From: bhgs@gpu.utcs.utoronto.ca (R. Holdom)
Subject: Re: Need help accessing MathTrans library from Task
Message-ID: <1991Mar13.173441.13795@gpu.utcs.utoronto.ca>
Summary:  possible solution.
Organization: UTCS Public Access
References: <5778@awdprime.UUCP> <29024.27db9dce@kuhub.cc.ukans.edu> <5847@awdprime.UUCP> <29036.27dcecfb@kuhub.cc.ukans.edu>
Distribution: na
Date: Wed, 13 Mar 1991 17:34:41 GMT

In article <29036.27dcecfb@kuhub.cc.ukans.edu> markv@kuhub.cc.ukans.edu writes:
>In article <5847@awdprime.UUCP>, jason@longhorn.austin.ibm.com (Jason Lowdermilk) writes:
>> In article <29024.27db9dce@kuhub.cc.ukans.edu> markv@kuhub.cc.ukans.edu writes:
>>>> I'm having a problem accessing the transcendental math library from a 
>>>> "child task" created with CreateTask, in particular the sqrt function.
>>>
>>>A task can call MathTrans library.  It cannot always call
>>>OpenLibrary("mathtrans.library",34L); because if the library is not in
>>>memory, then Exec will call LoadSeg() to get the library in memory,
>>>which is guarenteed to be a one way trip to la-la land if it isn't a process.
>>>
>>>So, the parent of the child needs to OpenLibrary() so that the library
>>>is in memory.  Then the child can get the base from the parent
>>>(easy to do if child is a function in the parent and they share global
>>>data), otherwise the child can call OpenLibrary() as long as the
>>>parent holds mathtrans.library open to keep it in memory.
>>>
>> 
>> The parent process opens the mathtrans library prior to creating the child.
>> The parent also calls sqrt() several times before creating the child. Sqrt 
>> is the the only transcendental function I am using, although I can
>> duplicate the problem by calling some other function such as sin().
>
>Hmm.  Let's try a simpler answer.  Are you using a function as the
>child task?  If so, and you want the child to use the parents library
>base, the child needs to be able access global data.  If the program
>is 32 bit abs addressing (-b0) then nothing needs to be done.  If the
>program is base-relative (-b1) then the child task function needs to
>establish the base register, either by declaring the function
>__saveds, compiling with -Y, or calling geta4() early in the function.
>
>If, you have a debugger, run the parent until MathTransBase is valid
>and note its value.  Then set a breakpoint in the child on a call to
>the math function and go.  When you trap the break point step through
>the code until you get to the actual JSR instruction for the function.
>With inline functions (which I assume your using), A5 should (*must*)
>contain the value of MathTransBase.  If not, the library base somehow
>isn't valid.  If so then you have other problems.
>
>> I have worked around this problem by writing my own sqrt routine as a 
>> function (in fact it is several times faster than the system sqrt,
>> albeit less accurate).
>
>As a side note, 2.0 has a single precision IEEE lib that will use the
>FPU if available and gives performance close the the FFP routines of
>1.3 even w/o the FPU.
>
>>but I am still curious why this doesn't work. I can 
>>put together a minimal code example that illustrates this and post it tomorrow
>
>Yeah, this might work better than trying to guess what your doing...
>

  I recall reading in the libraries/devices book that the library
pointer to the math libraries should NOT be shared between processes.
This may well be the root of your problems.  The reason is that if
you have an FPU installed, the state of the FPU is saved in the
data area, offset from the library pointer, during a task switch.
Some useful information may be saved there even if you don't have
an FPU installed.  This, of coarse, is only the answer if you take
the library pointer directly from your parent process.  If you do,
then instead you should open the library from your parent process,
to make sure it is in ram, and then open it again in your task, which
should be OK 'cause now its in memory.
                   Just my 2 bits worth.
                              Jon Spencer.

