A piece of code related to DSP

W

William Hughes

I would not say dealing with 16 bit signed quality, rather treat the
high part of a 32 bit value as a 16 bit signed value.  Anyway, the
operation is actually check the highest bit of the 32 bit value, if that
is not one, shift until it is, and increase the counter each time when
the value shifted.

The comparison uses what is stored in a pointer to int16_t.
This is a 16 byte signed int.

So you are shifting a 32 bit quantity, but checking
a 16 bit quantity.
I tested this piece of loop code, and I say, the result proves that I am
right, the MSB value ranges from 1 to 32.  What is the byte ordering in
your system? On my testing system as well as the target platform, it is
little endian.







Hum ... I now understand your concern.  Actually it is my fault, because
it's almost impossible to show the whole code in Usenet, I modified the
code to declear some global variable as local variable (with same data
type).  CorrValue is, in the original program, global value :)


Yes, for the moment, I don't have a document for the code. So I have to
get know from the code that what is the hell transform. And, I belive,
the result can also help me understand the problem domain itself.

Try to find out what needs to be done, ignore the question
of how (i.e. ignore all code and code documentation, look
for specifications and code design). The needed info may
be lost in the mists of time and never written down
to begin with, but given the crap code you have anything
is worth trying.

- William Hughes
 
N

narke

The comparison uses what is stored in a pointer to int16_t.
This is a 16 byte signed int.

So you are shifting a 32 bit quantity, but checking
a 16 bit quantity.

I can not agree with you. It was not checking a 16 bit quantity, it was
checking the higher 16 bits of a 32 bit quantity. The ideal is that
checking higher 16 bits is far more enough since what concerns in the
loop decision is merely the highest bit of the 32 bit quantity. Did you
see?
 
W

William Hughes

I can not agree with you.  It was not checking a 16 bit quantity, it was
checking the higher 16 bits of a 32 bit quantity. The ideal is that
checking higher 16 bits is far more enough since what concerns in the
loop decision is merely the highest bit of the 32 bit quantity.  Did you
see?

Yes, I see your point.
I would prefer to say that it is checking 16 bits which are the
third and fourth octets of a 32 bit quantity (whether these are the
high or low bits or something else is machine dependent).
Still, if these are the high bits and CorrValue has an initial
value of 1, then MSB is 32.

I am making the assumption that CorrValue is a 16 bit value
stored in the third and fourth octets of a 32 bit value
and this value cannot be 0. Under this assumption MSB is between
1 and 16. I suspect that the first and second octets of CorrValue
are always 0, If the third and forth octets are also zero the
program goes into an infinite loop.

If I understand you, the parameter CorrValue is passed in
as a global. When you track down the original
programmer make sure his death is slow and painful.

- William Hughes
 
N

narke

Yes, I see your point.
I would prefer to say that it is checking 16 bits which are the
third and fourth octets of a 32 bit quantity (whether these are the
high or low bits or something else is machine dependent).
Still, if these are the high bits and CorrValue has an initial
value of 1, then MSB is 32.

Yes, that's my point.
I am making the assumption that CorrValue is a 16 bit value
stored in the third and fourth octets of a 32 bit value
and this value cannot be 0. Under this assumption MSB is between
1 and 16. I suspect that the first and second octets of CorrValue
are always 0, If the third and forth octets are also zero the
program goes into an infinite loop.

It will never go into a dead loop, you see there is a condition check
near the beginning to ensure CorrValue is positive integer.
If I understand you, the parameter CorrValue is passed in
as a global. When you track down the original
programmer make sure his death is slow and painful.

Yes :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,093
Messages
2,570,611
Members
47,230
Latest member
RenaldoDut

Latest Threads

Top