From: Vladimir Vassilevsky on


Tim Wescott wrote:
> On 06/08/2010 09:15 PM, robert bristow-johnson wrote:

>> i dunno where you'll get 16-bit words nowadaze in C. maybe the type
>> "short", is that usually 16 bit or is even short 32 bits?

typedef int16_t s16;


> C was not designed to do DSP -- it was designed to do system
> programming.

#include <libetsi.h>



Vladimir Vassilevsky
DSP and Mixed Signal Design Consultant
http://www.abvolt.com
From: Tim Wescott on
On 06/09/2010 07:49 AM, Vladimir Vassilevsky wrote:
>
>
> Tim Wescott wrote:
>> On 06/08/2010 09:15 PM, robert bristow-johnson wrote:
>
>>> i dunno where you'll get 16-bit words nowadaze in C. maybe the type
>>> "short", is that usually 16 bit or is even short 32 bits?
>
> typedef int16_t s16;

Which works great until you do that for a 24-bit processor, or one
that's 32-bit only. There's a typedef that means "at least 16 bits"
under that system (C99?) -- but that's just an int or a short, so why
not use the original paradigm?

>> C was not designed to do DSP -- it was designed to do system programming.
>
> #include <libetsi.h>
>
>
>
> Vladimir Vassilevsky
> DSP and Mixed Signal Design Consultant
> http://www.abvolt.com


--
Tim Wescott
Control system and signal processing consulting
www.wescottdesign.com
From: glen herrmannsfeldt on
Tim Wescott <tim(a)seemywebsite.now> wrote:
(snip)

> On just about any processor whose native word length is 8- or 16 bits an
> 'int' is 16 bits. The ANSI spec says that a short is guaranteed to be
> at least 16 bits with no upper bound, an int is guaranteed to be the
> same size or bigger than a short, and a long is guaranteed to be at
> least 32 bits, again with no upper bound. I can't remember if a long
> long is guaranteed to be 64 bits, or even if it's guaranteed to be there
> by the standard (it's not guaranteed to be there by the marketplace).

When the DEC Alpha first came out the C compilers for it used 64 bits
for long. Much of the usual TCP/IP code uses long for 32 bits
(because int could be 16), and broke on the Alpha compilers.
As I understand it, long long was added to solve that problem,
though not standard until C99. (and I don't know specifically
what the standard says about it.)

> So generally on an 8- or 16-bit machine the tools will set short and int
> to 16 bits, and long to 32. On a 64-bit machine, everything will be 64
> bits.

I believe that there are 64 bit word addressed machines where
char, short, int, and long are all 64 bits. Rare, though.

(snip)

> C was not designed to do DSP -- it was designed to do system
> programming. Generally this deficiency doesn't show up too badly, but
> it does when you want to do fixed-point arithmetic that's anything other
> than integer.

-- glen
From: Walter Banks on
As several have pointed out generic fixed point math written in C
runs into several implementation specific issues. The most obvious
one is multiply.

I have done several fixed point implementations either as a C library
or as an extended data type in C compiler. At some point processor
specific issues become a factor in the implementation. The main ones
natural word length and accessibility to most significant part of the
product.

There are others that play a role. 24 bit processors are used in some
embedded applications because it provides the amount of resolution
needed to support the problem and the remaining 8 bits of the memory
implementation can be used for error corrections in bad environments.

The core embedded routines are not very hard to implement and porting
code after the core is done can be quite easy.

ISO/IEC 18037 has been implemented in some compilers to address
fixed point and DSP needs in C.

Regards,


w..
--
Walter Banks
Byte Craft Limited
http://www.bytecraft.com







From: Raymond Toy on
On 6/9/10 10:33 AM, Tim Wescott wrote:
>
> So generally on an 8- or 16-bit machine the tools will set short and int
> to 16 bits, and long to 32. On a 64-bit machine, everything will be 64
> bits.

Did you really mean a 64-bit machine uses 64 bits for short and int and
long? That's not true for every 64-bit machine. Don't most C compilers
for 64-bit machines have 16-bit shorts, 32-bit ints, and 64-bit longs?

>
> Assuming that something is so on an AVR or a fixed-point DSP chip just
> because it is so on your desktop is a deadly way to do embedded
> programming.

Definitely agree with that!

Ray