Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22456

GCC ARM Os Template function optimization

$
0
0
class GpioF7xx : public Gpio {
public:
    template <uint32_t PIN>
    static GpioF7xx create(GPIO_TypeDef* base) {
        static_assert(PIN >= 0 && PIN =< 15, "Gpio pins are only available from 0 to 15");

        return GpioF7xx(base, PIN);
    }

I have a pretty simple Gpio class which abstracts register allocation. In this class I have the pin argument at compile time, so why not check if the pin is a valid one with static_assert.

I assume it is easier to get a compiler warning, then being stuck in some handler.

 .text._ZN8GpioF7xx6createILm6EEES_P12GPIO_TypeDef
            0x0000000008000a84       0x1c cmake-build-debug/main.o
            0x0000000008000a84                GpioF7xx GpioF7xx::create<6ul>(GPIO_TypeDef*)
 .text._ZN8GpioF7xx6createILm7EEES_P12GPIO_TypeDef
            0x0000000008000aa0       0x1c cmake-build-debug/main.o
            0x0000000008000aa0                GpioF7xx GpioF7xx::create<7ul>(GPIO_TypeDef*)
 ...

Using (-O0) gcc-none-eabi toolchain the linker generated the linker map above (So far so good).

Using -Os the linker file doesn't contain the symbols anymore.

My Question: How far can this be optimized ? Does anyone know where I can find documentation about this. Because then I would directly put the template at the GpioF7xx class.

I actually created a static factory method as I didn't wanted a separate class for each pin in my binary.

Furthermore: I appreciate any comment how this could be more idiomatic as I'm coming from web. And don't have professional embedded / Cpp experience.


Viewing all articles
Browse latest Browse all 22456

Trending Articles