Skip to main content
GameDev.net gamedev.net
🔒 Locked

Inline and Inline assembly with libs

Started by Filami Oct 20, 2003 at 11:05 AM 5 replies 400+ views
Original Post
Filami
Filami
Hello people. I know that is inpossible to take advance of inline routines in a DLL if they are to be exproted. But what about static libraries? Will they take advance with inlines functions? Another question: I want to make several inline functions using the FPU....but not every one have one of this. The solution? Test. If there is support for that kind of instructions, use them, otherwise use the math lib. To avoid allways cheking if there is suport or not (some kind of if(FPUsupport){}else{}) I was thinking on doing this some kind of thing: (this code was writed right here)
void FPUFunction(); //FPU featured
void NormalFunction(); //no FPU featured

typedef void(*function)();
function table[1];

void Inicialize(){
 checkForFPU();
 if(FPU)
  table[0] = FPUFunction;
 else
  table[0] = NormalFunction;

void Function(){
  table[0]();
}
 
Now, when I whant to use the Function, it knows what instructions to use without the comparing. BUT, this means 2 functions calls and no inline! Does anybody have an ideia how to do the same but using inline? Thanks in advance
Techno Grooves
cnstrnd
cnstrnd
?

// In your lib header file
inline void Function()
{
Table[0]();
}
Enigma
Enigma
Don't know about inlining from a static lib. I suspect the same will apply as with DLLs and that the exposed inline functions will be linked using a normal function call.

As for the code you wrote, it looks like a good solution, although there's no point in using an array if there is only one function. There is literally no way that you can combine inlining (a compile-time feature) with dynamic FPU detection (a run-time feature). (**Having said that, I assume it's technically possible to rewrite the machine code during startup, but unless the two functions result in approximately the same number of machine instrucions you're probably not going to gain anything that way anyway).

I think your best bet is to either stick with the function pointer or (assuming C++) use classes.

Having said all this, who on Earth doesn't have an FPU? (Unless you're programming for a microcontroller or similar).

Enigma

EDIT: clarification
EDIT2: spelling

[edited by - Enigma on October 20, 2003 1:35:10 PM]

[edited by - Enigma on October 20, 2003 1:35:47 PM]
Fruny
Fruny
quote:
Original post by Filami
But what about static libraries? Will they take advance with inlines functions?



That''s entirely dependent on your compiler and linker.
MSVC 7.1 allows it when you use the /LTCG linker option.



[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
cnstrnd
cnstrnd
inlining xxxFunction is impossible (which function to use is determined at runtime).
inlining Function is possible with inline (__forceinline with VC++ just to be sure).

[edited by - cnstrnd on October 20, 2003 6:55:29 PM]
Filami
Filami
Ok, thanck you ppl!! It seems I don''t have much choice than assume that de CPU has the FPU. And, maybe I just cannot put such functions in DLL but in the headers.

Just another question: do you know any site that has all the opcodes from FPU? I know there is the fsiccos, the fcos, the fsin, fsqrt....what about acos, asin and such? How can I do such functions?
Techno Grooves

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.