you can freely move values from integer registers into floating point variables in memory, as long as they are the same size as the variable you are writing to. here is an example from some "fast squareroot" code that i picked up a while back:
Code:
#define ASM_SQRT(float_num, float_answer)\
__asm mov eax, float_num \
__asm sub eax, 0x3f800000 \
__asm sar eax, 1 \
__asm add eax, 0x3f800000\
__asm mov float_answer, eax
(compiles in visual studio)
But you've still got the one copy operation to get from an int to a float: __asm mov float_answer, eax. Won't the C code result in much the same thing?
Code:
int fake_float = 0x40000000;
// Use fake_float as a float using your #define BITSTOF(f) (*(float*)&f) macro
As I mentioned in my edit, if you wanted to pass 0x40000000 directly to a function you may be able to avoid a temp variable by using assembler.
[edit]
I compiled this with GCC:
Code:
#include <stdio.h>
#define BITSTOF(f) (*(float*)&f)
void printfloat(float f)
{
printf("%.2f\n", f);
}
int main(void)
{
int fake_float = 0x40000000;
printfloat(BITSTOF(fake_float));
getchar();
}
and got this (the interesting bit):
Code:
subl $12, %esp
pushl $0x40000000
call _printfloat
So it appears the compiler is smart enough not to use a temporary variable.
[/edit]
This sort of stuff is likely to defeat the optimiser, so I'd want to be sure that there is an actual performance improvement that is worth the bother.