Reply by Bhaskar Thiagarajan October 5, 20042004-10-05
"Jaime Andr&#4294967295;s Aranguren Cardona" <jaac@nospam.sanjaac.com> wrote in message
news:1097003497.WrfzoQJJe0yqcHqDh6n9vA@teranews...
> "Jim Thomas" <jthomas@bittware.com> escribi&#4294967295; en el mensaje > news:10m5rdmitcpl2fb@corp.supernews.com... > > Jaime Andr&#4294967295;s Aranguren Cardona wrote: > > > Hello, > > > > > > > > > The strange thing is that the value that I get for sampeFlt in
sampleFlt
> = > > > myFun(sampleFlt) is not the same value that should be returned
(output),
> but > > > that value converted into float again with f2=float r0;, which is the > > > instruction generated inmediately after returning from myFun, as I
could
> see > > > from the disassembly window. And of course, that value makes
absolutely
> no > > > sense! > > > > > > Why does it happen? How to get rid of it? > > > > > > > Methinks you need to prototype the function. IIRC, if a function lacks
a
> > prototype, C assumes all the args (and the return value) are ints. > > Absolutely right Jim, thanks a lot. > > The strange thing is this: the function was already prototyped in a header > (.h) file. The header file was included in the project, and in the path
for
> header files. However I forgot the respective #include in the .c file. But > the compiler didn't complain about not finding the prototype!!!!!
You can set the compiler options to warn you about everything under the sky to catch these sorts of problems. However, you'll be seeing a lot of warnings generated. So there is a trade-off.
> > That's the explanation of why did I overlook at something that simple, but > that important, too. > > TIA. > > -- > Jaime Andr&#4294967295;s Aranguren Cardona > jaac@nospam.sanjaac.com > SanJaaC Electronics > Soluciones en DSP > www.sanjaac.com > > (Remove "nospam" from e-mail address) > >
Reply by Jim Thomas October 5, 20042004-10-05
Jaime Andr&#4294967295;s Aranguren Cardona wrote:
> Hello, > > I'm not sure if this is relaed to the same problem as the original topic > (better said, to its solution), maybe it is. > > I have a function which takes a float parameter, does some calculations and > returns a float. > > Something like: > > float myFun (float input) > { > float output; > > output = input*input; // Just a simple example > > return output; > } > > And it's called from another C file, like this: > > void spr0_asserted( int sig_num ) > { > float sampleFlt; > > sampleFlt = (*pRX0_A); > > sampleFlt = myFun(sampleFlt); > } > > The strange thing is that the value that I get for sampeFlt in sampleFlt = > myFun(sampleFlt) is not the same value that should be returned (output), but > that value converted into float again with f2=float r0;, which is the > instruction generated inmediately after returning from myFun, as I could see > from the disassembly window. And of course, that value makes absolutely no > sense! > > Why does it happen? How to get rid of it? >
Methinks you need to prototype the function. IIRC, if a function lacks a prototype, C assumes all the args (and the return value) are ints. -- Jim Thomas Principal Applications Engineer Bittware, Inc jthomas@bittware.com http://www.bittware.com (603) 226-0404 x536 When you have a new hammer, the whole world looks like a nail.
Reply by October 5, 20042004-10-05
"Jim Thomas" <jthomas@bittware.com> escribi&#4294967295; en el mensaje
news:10m5rdmitcpl2fb@corp.supernews.com...
> Jaime Andr&#4294967295;s Aranguren Cardona wrote: > > Hello, > > > > > > The strange thing is that the value that I get for sampeFlt in sampleFlt
=
> > myFun(sampleFlt) is not the same value that should be returned (output),
but
> > that value converted into float again with f2=float r0;, which is the > > instruction generated inmediately after returning from myFun, as I could
see
> > from the disassembly window. And of course, that value makes absolutely
no
> > sense! > > > > Why does it happen? How to get rid of it? > > > > Methinks you need to prototype the function. IIRC, if a function lacks a > prototype, C assumes all the args (and the return value) are ints.
Absolutely right Jim, thanks a lot. The strange thing is this: the function was already prototyped in a header (.h) file. The header file was included in the project, and in the path for header files. However I forgot the respective #include in the .c file. But the compiler didn't complain about not finding the prototype!!!!! That's the explanation of why did I overlook at something that simple, but that important, too. TIA. -- Jaime Andr&#4294967295;s Aranguren Cardona jaac@nospam.sanjaac.com SanJaaC Electronics Soluciones en DSP www.sanjaac.com (Remove "nospam" from e-mail address)
Reply by October 5, 20042004-10-05
Hello,

I'm not sure if this is relaed to the same problem as the original topic
(better said, to its solution), maybe it is.

I have a function which takes a float parameter, does some calculations and
returns a float.

Something like:

float myFun (float input)
{
 float output;

 output = input*input;    // Just a simple example

 return output;
}

And it's called from another C file, like this:

void spr0_asserted( int sig_num )
{
 float sampleFlt;

 sampleFlt = (*pRX0_A);

 sampleFlt = myFun(sampleFlt);
}

The strange thing is that the value that I get for sampeFlt in sampleFlt =
myFun(sampleFlt) is not the same value that should be returned (output), but
that value converted into float again with f2=float r0;, which is the
instruction generated inmediately after returning from myFun, as I could see
from the disassembly window. And of course, that value makes absolutely no
sense!

Why does it happen? How to get rid of it?

Regards,

--
Jaime Andr&#4294967295;s Aranguren Cardona
jaac@nospam.sanjaac.com
SanJaaC Electronics
Soluciones en DSP
www.sanjaac.com

(Remove "nospam" from e-mail address)

"Bernhard Holzmayer" <holzmayer.bernhard@deadspam.com> escribi&#4294967295; en el
mensaje news:1681010.GegqNFYozU@holzmayer.ifr.rt...
> Jaime Andr&#4294967295;s Aranguren Cardona wrote: > > > void spr0_asserted( int sig_num ) > > { > > float sampleFlt; > > > > sampleFlt = (*pRX0_A); > > } > > > > I guess that your memory pointer pRX0_A is of type: > extern int * pRX0_A; > > Therefore the compiler assumes that it holds an integer value. > The type propagation rules of C require that it is converted to > float, if it is assigned to a float variable. > > That's what bothers you. > > Obviously, you have to tell the compiler that the variable is > already of type float. You have (at least) two proper ways to solve > this issue: > > 1) you change the definition of your external pointer to: > extern float * pRX0_A; > > 2) you do an explicit type cast during the assignment: > sampleFlt = *(float *)(pRX0_A); > > With both solutions, you'll achieve the same effect. > If accesses to *pRX0_A are always to be treated as float, > I'd modify the declaration (1), > if you have different accesses with different types, the second > choice would be preferable. > > Bernhard >
Reply by Jaime Andres Aranguren Cardona October 5, 20042004-10-05
Hello,

Bernhard Holzmayer <holzmayer.bernhard@deadspam.com> wrote in message 

> I guess that your memory pointer pRX0_A is of type: > extern int * pRX0_A;
Your'r right Bernhard, it's defined in \21k\include\Cdef21065l.h(298) this way: #define pRX0_A ((volatile unsigned int *) 0xe3)
> Therefore the compiler assumes that it holds an integer value. > The type propagation rules of C require that it is converted to > float, if it is assigned to a float variable. > > That's what bothers you. > > Obviously, you have to tell the compiler that the variable is > already of type float. You have (at least) two proper ways to solve > this issue: > > 1) you change the definition of your external pointer to: > extern float * pRX0_A; > > 2) you do an explicit type cast during the assignment: > sampleFlt = *(float *)(pRX0_A); > > With both solutions, you'll achieve the same effect. > If accesses to *pRX0_A are always to be treated as float, > I'd modify the declaration (1), > if you have different accesses with different types, the second > choice would be preferable.
Since it's a "pre-defined" header file, I didn't want to change it, so I prefered the second solution, which worked flawlessly. It usually happens... When you are working alone, you often times overlook some information (I had already seeen the declaration as #define pRX0_A ((volatile unsigned int *) 0xe3) in \21k\include\Cdef21065l.h(298), just didn't pay attention to it!). There is when you need some comments from comp.dsp Thank you very much, JaaC
Reply by Bernhard Holzmayer October 5, 20042004-10-05
Jaime Andr&#4294967295;s Aranguren Cardona wrote:

> void spr0_asserted( int sig_num ) > { > float sampleFlt; > > sampleFlt = (*pRX0_A); > } >
I guess that your memory pointer pRX0_A is of type: extern int * pRX0_A; Therefore the compiler assumes that it holds an integer value. The type propagation rules of C require that it is converted to float, if it is assigned to a float variable. That's what bothers you. Obviously, you have to tell the compiler that the variable is already of type float. You have (at least) two proper ways to solve this issue: 1) you change the definition of your external pointer to: extern float * pRX0_A; 2) you do an explicit type cast during the assignment: sampleFlt = *(float *)(pRX0_A); With both solutions, you'll achieve the same effect. If accesses to *pRX0_A are always to be treated as float, I'd modify the declaration (1), if you have different accesses with different types, the second choice would be preferable. Bernhard
Reply by October 5, 20042004-10-05
Hello,

Maybe my question is too dumb, but I can't find an explanation after a whole
day working over and over on SHARCs. I think I need some rest!

For algorithm validation I've created a .dat file which holds my input data.
It's written in floating point format (single precision). I configured the
SPORT0 on my ADSP-2165L Simulation session on VisualDSP++ (3.5 for 32 bit
processors). I also configured the streams for simulating getting my data
from captured via SPORT0.

I have this small piece of code for getting my data from the SPORT stream:

void spr0_asserted( int sig_num )
{
 float sampleFlt;

 sampleFlt = (*pRX0_A);
}

In the disassembly window I have this piece of code (generated by the
compiler):

modify (i7,0xfffffffe);
dm(0xfffffffe,i6)=r4;
r2=0xe3;
i4=r2;
r1=dm(m5,i4);
f0=float r1;
r12=0x4f800000;
if lt f0=f0+f12;
dm(0xfffffffd,i6)=r0;
jump (pc, 0x1);
i12=dm(m7,i6);
jump (m14,i12) (db);
rframe;
nop;

My problem is this: for example one of the data samples in the input .dat
file is 1.408542565987979
Looking at the registers window I can see that the value for R1 is actually
1.4085425, so the value read from the stream was OK. But the typecasting
makes the value in R0 to become 1.0687803E+009, and this one is the value
which I can see for the sampleFlt variable in the locals window. So, the
"float" instruction is what changed the value on the variable. I think that
comes from declaring sampleFlt as float. But I NEED it to be a float because
all of the further processing is done with that datatype.

So, the question is: how can I keep the value in C as it was generated in
the test (.dat) file?

I know it worked just fine in asseembly, but in C...

Thanks a lot in advance,

--
Jaime Andr&#4294967295;s Aranguren Cardona
jaac@sanjaac.com
SanJaaC Electronics
Soluciones en DSP
www.sanjaac.com