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.

_nassert info

I was wondering about the type of information I could tell the compiler with _nassert that will likely improve the optimizations available.

The one I have seen most often is to use it to describe alignment behavior that you know to be true, using either the & or % syntax, e.g.:

_nassert(((int)(x) & 0x3) == 0)

_nassert((int) x % 8 == 0)

In the restrict white paper, it was briefly mentioned that other pieces of information might be useful, e.g.

_nassert(m>0)

Is there a guide to using _nassert (beyond alignment)?

C6000, C6655, C6435, CGT 7.4.12, CCS 5.5.0.00077

  • I have only seen _nassert used to indicate that pointers are aligned on a power of 2 boundary.  But I will ask other experts to comment.

    Thanks and regards,

    -George

  • I've seen _nassert used to indicate that a loop's trip count is always divisible by some factor; that can make it more likely to unroll, since there are no excess iterations to worry about.

    I've also seen it used to assert that a particular integer variable -- often but not always a trip count -- has a known single value or set of values, or that it's greater than or less than some constant. That can indicate that it's profitable to unroll a loop, or to avoid checks that might slow it down.