Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 2 of 2

Thread: All variables with ASM saturation function.

  1. #1

    All variables with ASM saturation function.

    I have used this ASM saturation function borrowed from the audio library.

    Code:
    inline int32_t clampU_rsh(int32_t val, int bits, int rshift)
    {
      int32_t out;
      asm volatile("usat %0, %1, %2, asr %3" : "=r" (out) : "I" (bits), "r" (val), "I" (rshift));
      return out;
    }
    It has been very useful, normally I use it like this example:

    Code:
    G_out = clampU_rsh(ms_glideCount[ms], 15 , 1);
    I would like to make the bits and shift variables like this:

    Code:
    G_out = clampU_rsh(ms_glideCount[ms], x , y);
    I have been using a few of these as "black box" functions, and do not know much about the syntax. I tried what seemed "obvious" to me which was changing the "I" to "r" like they are on other functions which do accept 3 variables, (like multiply-accumulate) but that makes it fail to compile.
    Is USAT just made to expect a constant number of bits and shift, or is there something else I can do to make it accept all 3 inputs as variables?

    I am using a teensy 3.6 for this and that part of the code is in an ISR.

  2. #2
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,855
    Is USAT just made to expect a constant number of bits and shift
    Yes, the saturation bit position and the optional number of bits to shift in a USAT instruction are hard-coded within the instruction itself. I don't see any way that you can make it a variable.

    Pete

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •