This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to generate BFI & BFC instruction in C

Hi friends,
I am using TI LM3s6965 micro controller.

I read the thumb-2 instruction set. Some instructions are interesting but as 'C' programmer I don't know how to write code to generate these instruction BFI, BFC.. etc

Is keil C compiler have special macro/function/syntax to generate these instruction??
Or some coding tricks??

Please suggest any application notes which demonstrate "How to write efficient C code for cortex-M3".

Thanks & Regards,
Kishore.

  • There are many problems with this approach - trying to get the compiler to emit specific instructions by hand-crafting C source code.
    What's your goal? If the goal is to complete a project and meet specific performance requirements, then you should identify performance bottlenecks (through profiling) first and eliminate them by applying appropriate optimization techniques. As you probably have heard, 'Premature optimization is the root of all evil.'
    If you are simply trying to learn the tools, then just say so and you'll save yourself from a lot of lecturing from me and others in this forum :-)

  • Hi Mike,
    Thanks for quick reply.

    Yes I am simply trying to learn the tool.

    I agree you. I can't compromise the reliability for extra performance.

    As most of the embedded projects are done in 'C'. And if 'C' can't support these 'special instructions', What's the use of these features??

  • " if 'C' can't support these 'special instructions'"

    No, you're missing the point!

    The point is not that 'C' can't support these instructions!

    The point is that you, the programmer, have no control over the choice of instructions when you write in a HLL. The choice of instructions is down to the compiler - not you.

  • armcc will generate BFI etc. when it's a good thing to use, for example C constructs like these:

    struct S { int a:3; int b:3 };
    
    void f1(struct S* s, int x) { s->b = x; } // BFI
    int f2(int x, int y) { return (x & ~0x38) | ((y & 7) << 3); } // BFI
    

    but which instruction/s is/are used is not guaranteed.