Home » Eclipse Projects » DSDP  RealTime Software Components (RTSC) » Math functions for c28_float target

Re: Math functions for c28_float target [message #720672 is a reply to message #720576] 
Wed, 31 August 2011 04:06 
Sasha Slijepcevic Messages: 115 Registered: July 2009 
Senior Member 


First, you'll need a config parameter in your module that can be used in a config script to specify the path to the FPU fastRTS library. Let's call the parameter fastRtsPath. A config script would set it as follows:
var Mod = xdc.useModule('pkg.YourMod');
Mod.fastRtsPath = "c:\tidcs\c28\C28x_FPU_fastRTS\v100";
Then, you can add the function getSects() to the file package.xs, which is located in your package that contains the module. The function getSects() returns the name of the template file, which will be evaluated and the result of the evaluation will be added to the generated linker command file. The generated linker command line comes before the standard runtime library, so by adding the fast RTS library to the linker command file, you'll achieve the required effect.
Since package.xs is a package level file, its functions will be invoked whenever the package is loaded. Therefore, you need to invoke the template only if the module that needs fast RTS is actually used:
function getSects()
{
if (this.YourMod.$used) {
return ("link.xdt");
}
return (null);
}
The next step is to add the actual template file file link.xdt to the package (you can choose some other name, but it's important that the name of the file and the reference to it in getSects() match). The content of link.xdt is:
%var lib = xdc.module("pkg.YourMod").fastRtsPath + "/<library name>";
l"`lib`"
Notice backquotes on the second line.
There are some other ways to include fastRTS, so if there are some issues with this approach, please let me know, and depending on these issues, we can come up with a different solution.


    
Re: Math functions for c28_float target [message #721438 is a reply to message #721114] 
Thu, 01 September 2011 18:57 
linkinsebas Messages: 22 Registered: April 2011 
Junior Member 


I have been digging some more into the problem.
If I use the following client application:
#include <xdc/std.h>
#include <xdc/runtime/Types.h>
#include <sch/math/Math.h>
#include <math.h>
#define mf_abs(x) (x>0?x:x)
float fast_sqrt(float number)
{
return sqrt(number);
}
// ======== main ========
Void main()
{
int i;
float x_abs=2.75;
float y_abs_mf, y_abs_Math;
float x_sqrt=0.5;
float y_sqrt_fast, y_sqrt_Math;
y_abs_mf=mf_abs(x_abs);
y_abs_Math=Math_abs(x_abs);
y_sqrt_fast=fast_sqrt(x_sqrt);
y_sqrt_Math=Math_mySqrt(x_sqrt);
return 0;
}
I get y_sqrt_fast=0.707107 as expected but y_sqrt_Math=0. If I use the assembly step into feature of ccsv4, I see that fast_sqrt is compiled into:
.text, __text, fast_sqrt:
0x009000: FE02 ADDB SP, #2
0x009001: E2030042 MOV32 *SP[2], R0H
0x009003: 7640BF5E LCR $C:/ti/controlSUITE/libs/math/FPUfastRTS/V100/source/sqrt_f32.asm:47:68$
0x009005: FE82 SUBB SP, #2
0x009006: 0006 LRETR
whereas Math_mySqrt is compiled into:
sch_math_Math_mySqrt, sch_math_Math_mySqrt__F:
0x00C389: 7640BF5E LCR $C:/ti/controlSUITE/libs/math/FPUfastRTS/V100/source/sqrt_f32.asm:47:68$
0x00C38B: 3B01 SETC SXM
0x00C38C: 85A9 MOV ACC, @AL
0x00C38D: BDA90F12 MOV32 *(0:0x0f12), @ACC
0x00C38F: 7700 NOP
0x00C390: 7700 NOP
0x00C391: 7700 NOP
0x00C392: 7700 NOP
0x00C393: E689 .word 0xe689
0x00C394: 0000 ITRAP0
0x00C395: 0006 LRETR
which is a significantly longer code. Despite the fact that both call the same optimized sqrt function, it seems that line 0x00C38D clears the content of register R0H which is supposed to hold the result. I do not know much about C28's assembly so I cannot really tell what is going on, except for some basic stuff.
Also, I found that the "function declared implicitly" warning means that a function doesn't have a prototype and the compiler has to make some assumptions about the values that are being passed/returned. Isn't math.h supposed to define a prototype for sqrt()? I found that if I remove #include <math.h> from Math.c the result is exactly the same.
Any help would be appreciated. Thanks.
[Updated on: Thu, 01 September 2011 22:42] Report message to a moderator



Re: Math functions for c28_float target [message #721495 is a reply to message #721438] 
Thu, 01 September 2011 22:42 
linkinsebas Messages: 22 Registered: April 2011 
Junior Member 


Sasha:
I was able to overcome the problem by adding the following line to Math.c (notice that math.h is not included anymore)
//#include <math.h>
float sqrt(float number);
However, I don't think this is a definitive solution, but at least I can keep working now. If anyone can come with a better solution, it will be appreciated.
By the way, the file link.xdt you mentioned has to be located in the repository's root directory. What should I do if I want to have many modules from many packages that use the fastRTS library?
UPDATE: For this last issue, I realized that file link.xdc should be referenced inside package.xs using a fullyqualified name
/*
* ======== sch/math/package.xs ========
*/
function getSects()
{
if (this.Math.$used) {
return ("sch/Math/link.xdt");
}
return (null);
}
Thanks for your help.
[Updated on: Fri, 02 September 2011 21:17] Report message to a moderator


  
Goto Forum:
Current Time: Tue Jan 25 00:10:25 GMT 2022
Powered by FUDForum. Page generated in 0.02003 seconds
