This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[C66x] DSPINT instruction behavior

Hi,

My customer is using _dspint () intrinsic function and they has a question about its behavior.

It seems it handles data as below:
- For a single precision floating point value smaller than -(2^31), _dspint() converts it as -(2^31).
- For a single precision floating point value larger than 2^31-1, _dspint() converts it as 2^31-1

I suggested them to see the following manual:

4.140 DSPINT

But, it seems this does not elaborate its behavior about the above corner cases. 
I believe _dspint() handles the data correctly, but please let me confirm this is expected behavior. 
Also, do you have any other manuals to understand _dspint() behavior more deeply ?

Best Regards,
Naoki

  • The manual you reference is the authoritative source on C6600 CPU instructions.  I agree it does not address these particular questions.  Unfortunately, we compiler experts don't know either.  So the next step is for me to move this thread into a C6000 device forum.

    Thanks and regards,

    -George

  • Hi George,

    Ok, I'll wait for answers from your c6x experts.

    Best Regards,
    Naoki

  • My suggestion is to write a small program that will show the behavior of dspint (or even only spint, i think they two behave the same)
    1. Load a floating point value with 2**31 -1 minus some small value, convert it to integer and check the value
    2. Load a floating point value with 2**31 -1 and convert it to integer and check the value
    3. Do the same with negative values
    4. . Load a floating point value with 2**31 -1 plus some value, convert it to integer and check the value
    5. Do the same with negative values

    Please report what you see to this posting

    Ran
  • Hi Ran

    Here is my investigation with small code:

    #include <c6x.h>
    
    #define TEST_SAMPLE_COUNT 9
    
    float g_floatArray_pos[TEST_SAMPLE_COUNT] = {
    		2.14748365e+09 - 0.00000400e+09,
    		2.14748365e+09 - 0.00000300e+09,
    		2.14748365e+09 - 0.00000200e+09,
    		2.14748365e+09 - 0.00000100e+09,
    		2.14748365e+09, //...(float)((int)0x7FFFFFFF) : Max integer in int type
    		2.14748365e+09 + 0.00000100e+09,
    		2.14748365e+09 + 0.00000200e+09,
    		2.14748365e+09 + 0.00000300e+09,
    		2.14748365e+09 + 0.00000400e+09,
    };
    float g_floatArray_neg[TEST_SAMPLE_COUNT] = {
    		-2.14748365e+09 + 0.00000400e+09,
    		-2.14748365e+09 + 0.00000300e+09,
    		-2.14748365e+09 + 0.00000200e+09,
    		-2.14748365e+09 + 0.00000100e+09,
    		-2.14748365e+09, //...(float)((int)0x80000000) : Min integer in int type
    		-2.14748365e+09 - 0.00000100e+09,
    		-2.14748365e+09 - 0.00000200e+09,
    		-2.14748365e+09 - 0.00000300e+09,
    		-2.14748365e+09 - 0.00000400e+09,
    };
    
    int g_intArray_pos[TEST_SAMPLE_COUNT];
    int g_intArray_neg[TEST_SAMPLE_COUNT];
    
    /*
     * main.c
     */
    int main(void)
    {
    	int i;
    	__float2_t f2_temp;
    	long long i2_res;
    
    	for (i=0; i<TEST_SAMPLE_COUNT; i++) {
    		f2_temp = _ftof2(g_floatArray_pos[i], g_floatArray_neg[i]);
    		i2_res = _dspint(f2_temp);
    		g_intArray_pos[i] = (i2_res & 0xFFFFFFFF00000000)>> 32;
    		g_intArray_neg[i] = (i2_res & 0x00000000FFFFFFFF);
    	}
    
    	return 0;
    }

    After the completion, g_intArray_pos looks like:

    And the g_intArray_neg looks like:

    My customer wants to know this is expected behavior or not. For me, I think this should be expected, but this is not described in manual. So I'm asking.

    Best Regards,
    Naoki

  • Naoki

    I agree with you.  

    This is what I expect as well. 

    What is the other alternative? There are only 31 bits to express positive fixed point numbers. 

    If the customer does not agree, ask him or her what do they expect the results to be

    Best regards

    Ran

  • Hi Ran,

    Thanks for your comments. If this is expected behavior, it's ok for us.
    Lastly, this is just a feedback from my customer but please remember that such specifications should be explicitly described in manual. It would be so appreciated if you will consider his offer in the future document release.

    Best Regards,
    Naoki

  • dspint is specified as pair of spint conversions, and therefore it would be more natural to expect that only differences from spint are documented. As for per-value behaviour one can argue that it is documented implicitly by spint referencing dpint, which in turn [among other things] does describe what happens on overflow condition. After all, conversion overflow conditions are same for single- and double-precision values...