Good to learn somthing new. However, except for some time critial functions, most project managers would prefer to use high level language.
@Asha, as you point out the feature of staurating arithmetic very importent to high
performance DSP applications, which C solution would severly impact, eg. sample
Coupled with inline C makes it easy to implement.
Interesting. Makes me wonder how much code space/speed could be saved/improved in replacement
var = ( var > 10 ) ? 10, var + 1; // type of constructs.
... not too much code. Since your given "10" from your example will not work (it is not a power of two) we have to rewite the above example to
var = (var > 127)?0:var+1; // Remember: C needs a colon to separate the two values
I've built an example project to see how many instructions will be needed to perform the wanted task. I had to add some hardware, so GCC did not optimize out all my code (wich really did happen!! No code left in main()).
Additionally it took me some time to understand the result in main.lst which does what I wrote but does not look like what I wrote.
Design01.cyprj.Archive01.zip 430.1 K
I did indeed mistype the test statement. You can see where I spend most of my
time in a design.....
As I was doing the post I wondered (but did not do my homework) if saturation
was limited to power of two, thanks for clarifiying that.
As an aside in posting a recent sine generator using IIR and positive fdbk I experimented
with seed values and got the middle example shown below because I did not use sat
Thanx for the link, hli. It reminded me of the take-off at Cape Caneveral of the mars-mission MAVEN.
Yes, the example given by you ( var = (var > 127)?0:var+1;) is right. However, the saturation limit is restricted to 2^n-1 where you can specify the value of n.
Though most of them prefer using high level C code, this operand might be useful for DSP operations.
Just adding one more point on the usage of saturation instruction based on the compiler- (GCC or MDK )
While using GCC compiler, as mentioned above, we need to use the registers. eg: asm(“USAT r3,8,r0");
So first we need to store the variables that will contain the unsaturated and saturated results using the syntax given in the first post.
However, for MDK compilers you can directly use the local variables along with this instruction and there is no need to specify the registers:
eg: __asm(“ssat data_sat,8,data_unsat");