I have a function for fp16 to fp32 conversion
static float fp16_to_fp32(const short in){
signed int t1, t2, t3;
float out = 0;
t1 = (in & 0x7fff) << 13 + 0x38000000;
t2 = (in & 0x8000) << 16;
t3 = in & 0x7c00;
t1 = (t3==0 ? 0 : t1);
t1 |= t2;
*((unsigned int*)&out) = t1;
return out;
}
error: dereferencing typed-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing] in ((unsigned int)&out) = t1;
How can I solve this? (can't change type of argument in
)
You can use
memcpy()
for copying data.Also note that
+
operator has higher precedence than<<
operator, so the linet1 = (in & 0x7fff) << 13 + 0x38000000;
won't work as expected.