About the problem of selecting O3 for DSP program compilation and Optimization

Source: Internet
Author: User
Today I am optimizing the code. An error occurred. As follows:
// ---------------- Periph. c ---------------------
/* Read register, parameter address returned content */
Unsigned int readcmd (unsigned char ADDR)
{
Unsigned int temp;
Xcs_l ();
Writebyte (0x03 );
Writebyte (ADDR );
Temp = readbyte ();
Temp <= 8;
Temp + = readbyte ();
Xcs_h ();
Return temp;
}

// ------------------ Main. c -----------------
# Define readhdat0 () readcmd (spi_hdat0)

Hdat0 = readhdat0 (); // read object frame header information

If I do not use the O3 optimization item. The data I read is correct. However, the data read every time is incorrect. And they are all different (the difference between the value and the correct value is not big, so it can be said that the value fluctuates under the correct value ).
Then I checked the corresponding O3 data. The book contains the following section:
"-O3: indicates the maximum possible optimization level. Various loop optimizations are executed, and various file-level properties are also used to improve performance. "

Excuse me:
1. If I want to use O3 optimization, what should I do to avoid errors?
2. In the description of O3, "various cyclic optimizations have been executed". How can we optimize various cyclic optimizations? Under what conditions? What have been optimized?
3. "various file-level properties are also used to improve performance". What does a file-level nature mean? Why does it improve performance?

O3 is the largest optimization level, especially for loop attempts to carry out software flow. After optimization, some infrequently used intermediate variables will be released. before optimization, the intermediate variables will be defined in the L2 cache. After optimization, they will be directly allocated in the internal CPU registers, therefore, these variables cannot be seen. I suggest you buy a book on DSP optimization, which is generally clear.

Very normal, after using O3 optimization, less code will not be normal, I also met several times, change the C code method, and then use the FULLL-DEBUG mode back to see (mix mode) confirm the assembly.

I am running a video collection and compression program, which uses the JPEG compression algorithm. The program does not select-O2
Or when the-O3 option is optimized, it works normally and is relatively stable. However, if the-O2 or-O3 option is used, the program is unstable and errors may occur. In addition, after the-O2 or-O3 option is used, many variables are optimized, and the order of some statements is adjusted, which is not very convenient for debugging. Further research is required.

The CSL support library is also used in the program.
Dat_copy is used to move data from external SRAM to internal l2ram. If the-O2 or-O3 option is not used, dat_copy works normally,
After the-O2 or-O3 option is used, the dat_copy function is not working properly and the integer has to be continued.

You must use-O3. Otherwise, you must use manual optimization.
As for the cause of the error, you can only say that the program is not rigorous!
03 errors: Sometimes a pointer is used to read and write memory errors. You can divide the program into small files, one file, one file, and one file-O3 at a time to narrow down the error range.
Engineers who do not use-O3, not qualified DSP engineers.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.