DSP Platform optimization example: If you can add const, restrict and other types of modifiers as much as possible

Source: Internet
Author: User

If a function is frequently called many times, we should start with the details. Sometimes we have no idea about the logic of the Code itself. These details can often bring us unexpected results. A type modifier is one of them.

constKeywords do not need to be said, but we can often ignore them, so try to develop a habit: when designing a function parameter or declaring a variable (either local or global, subconsciously consider whether we can design this variable as unchangeable.

NOTE: If it is a pointer, we should also consider that the content pointed to by the pointer cannot be changed (it should be declaredconst int *p), Or the pointer itself cannot be modified (should be declaredint * const p), Or neither of them can be modified (should be declaredconst int * const p).

restrictKeywords: I have never touched on DSP Platform optimization before, but it has brought me unexpected results several times in recent learning and optimization processes.

Restrict, a type qualifiers in C language, used to tell the compiler that the object has been referenced by the pointer, you cannot modify the content of this object in any other way, either directly or indirectly, except for the pointer. -- Baidu encyclopedia

The Type modifier is used to tell the compiler more information about variables, so that the compiler can be more relaxed and boldly optimized during optimization, because the compiler always chooses the safest optimization solution. However, sometimes we can see that even if these type modifiers are added, the effect is not obvious. In fact, the compiler has done this for us.

DSP Platform optimization example: If you can add const, restrict and other types of modifiers as much as possible

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.