• Join
  • Sign In with my.TI Login
Texas Instruments
  • Products
  • Applications
  • Tools & Software
  • Support & Community
  • Sample & Buy
  • About TI
Sample & Purchase Cart Sample & Purchase Cart
  • Search
  • Advanced
TI E2E™ Community
  • Support Forums
  • Blogs
  • Groups
  • Videos
  • 简体中文
  • More ...
TI Home » TI E2E Community » Support Forums » Digital Signal Processors (DSP) » C6000 Single Core DSP » C64x Single Core DSP Forum » DSP library function - DSP_maxidx()
Share
C6000 Single Core DSP
  • Forums
  • Announcements
Options
  • Subscribe via RSS

Forums

DSP library function - DSP_maxidx()

This question is answered
nemis
Posted by nemis
on May 07 2012 06:56 AM
Prodigy40 points

To find the max index of an array fast I have been using the below function from the DSP library. 

int DSP_maxidx(const short *x, int nx)

However, recently I discovered some odd results from it. For example, if my array has 128 elements and the max value is placed between index 16 and 31 the output is wrong. Placing the max value at index 16 gives a result of 112. The results are the same for larger arrays as well, but I seem to get correct result if the array is smaller, e.g. 64 elements. See the below test code for details. Am I using the function incorrect? The C64xDSPLIB version is 1.04b, but I cannot find any newer versions.

extern "C"
{
  int DSP_maxidx(const short *x, int nx);
}
static const int SIZE = 128;

#pragma DATA_ALIGN(8)
const short values[SIZE] = 
{
   1, 1, 1, 1, 1, 1, 1, 1,
   1, 1, 1, 1, 1, 1, 1, 1,
   9, 1, 1, 1, 1, 1, 1, 1,
   1, 1, 1, 1, 1, 1, 1, 1,
   1, 1, 1, 1, 1, 1, 1, 1,
   1, 1, 1, 1, 1, 1, 1, 1,
   1, 1, 1, 1, 1, 1, 1, 1,
   1, 1, 1, 1, 1, 1, 1, 1,
   1, 1, 1, 1, 1, 1, 1, 1,
   1, 1, 1, 1, 1, 1, 1, 1,
   1, 1, 1, 1, 1, 1, 1, 1,
   1, 1, 1, 1, 1, 1, 1, 1,
   1, 1, 1, 1, 1, 1, 1, 1,
   1, 1, 1, 1, 1, 1, 1, 1,
   1, 1, 1, 1, 1, 1, 1, 1,
   1, 1, 1, 1, 1, 1, 1, 1,
};

Int main(Void)
{
   int maxIdx = DSP_maxidx(values, SIZE);
   printf("Max=%d\n", maxIdx);

   return 0;
}
Report Abuse
  • Reply
You have posted to a forum that requires a moderator to approve posts before they are publicly available.
All Replies
  • Johannes
    Posted by Johannes
    on May 07 2012 09:43 AM
    Genius3190 points

    Hi nemis

    I got the same error it looks like as if it was using a signed 8 bit value, so we would go from -128 to 127. But the function uses an int parameter, so we shouldn't have this problem.

    Looking at the dsplib documentation SPRUEB8B http://www.ti.com/lit/ug/sprueb8b/sprueb8b.pdf page 4-61 I found the code that defines the maxidx function:

    int DSP_maxidx(const short *x, int nx)
    {
    	int max, index, i;
    	max = 0-32768;
    	for (i = 0; i < nx; i++)
    		if (x[i] > max) {
    			max = x[i];
    			index = i;
    		}
    	return index;
    }
      

    So I added this function definition to the code and commented ou the:

    extern"C"{int DSP_maxidx(const short *x, short nx);}

    With the new code it worked alright.

    Maybe there's some problem with the compiler when it does the extern part.

    Regards

     
    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • nemis
    Posted by nemis
    on May 09 2012 01:14 AM
    Prodigy40 points

    joh 123456

    Hi nemis

    I got the same error it looks like as if it was using a signed 8 bit value, so we would go from -128 to 127. But the function uses an int parameter, so we shouldn't have this problem.

    Looking at the dsplib documentation SPRUEB8B http://www.ti.com/lit/ug/sprueb8b/sprueb8b.pdf page 4-61 I found the code that defines the maxidx function:

    int DSP_maxidx(const short *x, int nx)
    {
        int max, index, i;
        max = 0-32768;
        for (i = 0; i < nx; i++)
            if (x[i] > max) {
                max = x[i];
                index = i;
            }
        return index;
    }
       

    So I added this function definition to the code and commented ou the:

    extern"C"{int DSP_maxidx(const short *x, short nx);}

    With the new code it worked alright.

    Maybe there's some problem with the compiler when it does the extern part.

    Regards

    Maybe, but I'm using the latest code generation tools.

    It seems like the DSPLIB version is from 2003, hence pretty old. I would expect new bug fixes from time to time. Could there be a bug in the assembly for the function?

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Rahul Prabhu
    Posted by Rahul Prabhu
    on May 09 2012 12:34 PM
    Genius15605 points

    Could you specify, what device you are using. I just want to make sure you are using the correct version of the library.

    Regards,

    Rahul

    ---------------------------------------------------------------------------------
    Please click the
    Verify Answer button on this post if it answers your question.
    ---------------------------------------------------------------------------------

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • nemis
    Posted by nemis
    on May 10 2012 01:27 AM
    Prodigy40 points

    TMS320C6455

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Rahul Prabhu
    Posted by Rahul Prabhu
    on May 10 2012 13:47 PM
    Verified Answer
    Verified by nemis
    Genius15605 points

    You are using a very old version of the DSPLIB that is meant for legacy C64x DSP devices(C641x and C642x). Please use the C64xplus DSPLIB, from the following link

    http://software-dl.ti.com/sdoemb/sdoemb_public_sw/dsplib/latest/index_FDS.html

    This is the correct version of the library that is meant for your device.

    Regards,

    Rahul 

    ---------------------------------------------------------------------------------
    Please click the
    Verify Answer button on this post if it answers your question.
    ---------------------------------------------------------------------------------

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • nemis
    Posted by nemis
    on May 11 2012 05:37 AM
    Prodigy40 points

    Thanks! The new DSBLIB version solved the issue.

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
TI E2E™ Community
  • Support Forums
  • Blogs
  • Videos
  • Groups
  • Site Support & Feedback
  • Settings
TI E2E™ Community Groups
  • TI University Program
  • Make the Switch
  • Microcontroller Projects
  • Motor Drive & Control
Other Communities
  • Deyisupport
  • Designsomething.org
  • beagleboard.org
  • TI on Element 14
  • TI on TechXchangeSM
Other Technical & Support Resources
  • WEBENCH® Design Center
  • Product Information Centers
  • Technical Documents
  • TI Design Network
  • TI Technical Articles
  • TI Training

All content and materials on this site are provided "as is". TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with regard to these materials, including but not limited to all implied warranties and conditions of merchantability, fitness for a particular purpose, title and non-infringement of any third party intellectual property right. TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with respect to these materials. No license, either express or implied, by estoppel or otherwise, is granted by TI. Use of the information on this site may require a license from a third party, or a license from TI.

Content on this site may contain or be subject to specific guidelines or limitations on use. All postings and use of the content on this site are subject to the Terms of Use of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Terms of Use of this site. TI, its suppliers and providers of content reserve the right to make corrections, deletions, modifications, enhancements, improvements and other changes to the content and materials, its products, programs and services at any time or to move or discontinue any content, products, programs, or services without notice.

Follow Us Texas Instruments on Facebook Texas Instruments on Twitter Texas Instruments on LinkedIn Texas Instruments on Google+
TI Worldwide | Contact Us | my.TI Login | Site Map | Corporate Citizenship | mobile m.ti.com (Mobile Version)

TI is a global semiconductor design and manufacturing company. Innovate with 100,000+ analog ICs and
embedded processors, along with software, tools and the industry’s largest sales/support staff.

© Copyright 1995-2013 Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy Policy | Terms of Use