We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now


c code optimization

Medium Priority
Last Modified: 2012-05-11
i have attached a C code for the  which will  run on  DSP.
I need to optimise it for speed (less number of cycles). please suggest some ways..

WIDTHX is the width of the image, HEIGHTY is its height. the frame_1 is a 1-D array
pixels are stored sequentially. i have attached the original and the modified code.
original was taking around 111million. I modified it to take 55. furthur modifications are necessary
i need to bring it below 10million.. modified.c
Watch Question

You could build a 255 by 255 table that says which combinations of gradientX and gradientY pass the edge test.  Rather than doing _mpyu twice, just look up the edgemap value (0 or 255) in the table.  If you used 1 byte per combination the table is 64k.  Though you only need half of it and theoretically only 1 bit per combination, so 4k as a minimum.
Will locality of reference make a difference on the DSP?  If the image is very wide, will it miss a cache when referring to the line below?  If so you might consider dividing the image into smaller sub images, if that helps the caching.
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview
Most Valuable Expert 2014
Top Expert 2015

If you are multiplying gradientX and gradientY by itself, there is no need for the abs operation
But getting from 55 to 10million would probably require better use of parallelism in the DSP
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview


suggestions was helpful indeed, but are not one shot answers which saved my time. so GRADE B
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.