DSPRelated.com
Forums

VisualDSP++ streams simulation / C floats

Started by Jaime Andres Aranguren Cardona October 5, 2004

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 f0f12;
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 Aranguren Cardona
__________________________________





Hi Jaime,

I bet that the pRX0_A has been declared in a header file as

volatile int *pRX0_A;

or something like that. That is, a pointer to an integer variable
location. That is why the C compiler makes an implicit type cast to
a float. The compiler is simply unaware what data is being read from
the SPORT, a byte, an int or a float; moreover it does know nothing
about SPOR itself!

You might want to declare a union type with an int and float members
and read the value from *pRX0_A into the int member. Thus a correct
value would pop up in the float member.

Alternatively you'd need to declare a pointer

volatile float *FLT_SPORT0 = (volatile float *)pPRX0_A;

and read samples stored at this pointer:

float sampleFlt;
sampleFlt = *FLT_SPORT0;

or type cast on the fly

sampleFlt = * (volatile float *) pPRX0_A;

Hopefully you have already resolved the problem on your own!

Rgds,

Andrew

> Date: Mon, 4 Oct 2004 21:07:00 -0700 (PDT)
> From: Jaime Andres Aranguren Cardona <>
> Subject: VisualDSP++ streams simulation / C floats
>
> 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 f0f12;
> 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 Aranguren Cardona >
>




Hi Andrew,

Fortunately I got a smiliar reply from someone at
comp.dsp, and that certaily was the reason why I had
problems, now it's solved.

I mention comp.dsp at and
at comp.dsp, not meaning that the
people from the other group are faster, but to point
out that there are good resources where to ask for
support when working on ADI's DSPs.

Regards, and thank you very much.

JaaC --- Andrew Nesterov <>
wrote:

>
> Hi Jaime,
>
> I bet that the pRX0_A has been declared in a header
> file as
>
> volatile int *pRX0_A;
>
> or something like that. That is, a pointer to an
> integer variable
> location. That is why the C compiler makes an
> implicit type cast to
> a float. The compiler is simply unaware what data is
> being read from
> the SPORT, a byte, an int or a float; moreover it
> does know nothing
> about SPOR itself!
>
> You might want to declare a union type with an int
> and float members
> and read the value from *pRX0_A into the int member.
> Thus a correct
> value would pop up in the float member.
>
> Alternatively you'd need to declare a pointer
>
> volatile float *FLT_SPORT0 = (volatile float
> *)pPRX0_A;
>
> and read samples stored at this pointer:
>
> float sampleFlt;
> sampleFlt = *FLT_SPORT0;
>
> or type cast on the fly
>
> sampleFlt = * (volatile float *) pPRX0_A;
>
> Hopefully you have already resolved the problem on
> your own!
>
> Rgds,
>
> Andrew
>
> > Date: Mon, 4 Oct 2004 21:07:00 -0700 (PDT)
> > From: Jaime Andres Aranguren Cardona
> <>
> > Subject: VisualDSP++ streams simulation / C floats
> >
> > 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 f0f12;
> > 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 Aranguren Cardona
> >
> >
> >
> >


=====

Jaime Andr Aranguren Cardona
__________________________________