TI DSP: C ++ Interoperability and Build

I sent this question to the Q-TI 28xx DSP forum , but did not hear the answer and realized maybe someone here might know.


I know how to write functions in an assembly so that they are C-callable; if the C-called name is foo() , then the build function is called _foo() .

What if I want to use C ++ and optimize the class method in the assembly? How should I do it? I assume that the only serious problems are:

  • naming
  • access to the "this" pointer
  • access to class members somehow knowing biases

and if I donโ€™t want to worry about the last two, then perhaps I would write a static member function and do the following:

 class MyClass { int x; static int _doSomething(int u); // implement this in assembly public: inline void doSomething() { x = _doSomething(x); } // lightweight C++ wrapper to handle the class member / "this" pointer stuff }; 
+4
source share
3 answers

The this pointer is passed as an optional argument to the function using the standard convention on your platform. On all platforms that I'm familiar with, it is passed as the first argument, but I don't do a lot of C ++ code, so I'm not sure if this is guaranteed by the standard. You can always parse C ++ code on your platform for confirmation.

C ++ naming is more painful than in C, and varies from compiler to compiler. I suppose you could find the correct character name to use by looking at the compiled function definition, just make sure: the function is a member of the right class and has the correct number and type of arguments.

If you really do not need to reproduce the C ++ function in situ, I would most likely just execute the standard C function and make the usual extern "C" { ... } around its declaration.

+5
source

Does your compiler have built-in assembly syntax? If you have one, this might be the easiest option, and you can let the compiler handle the naming functions and call the syntax fragments.

Alternatively, Stephenโ€™s suggestion to write a C ++ method as an inline wrapper around a โ€œsimpleโ€ C function call is a good one. (You probably want to make it a simple function, not a static member function, as in your post, to get a simple C interface.)

+1
source

I would find a compiler dependent flag and write the assembly in C ++. Typically, there are ways to reference local variables from an assembly section.

0
source

All Articles