X-Git-Url: https://git.sesse.net/?p=movit;a=blobdiff_plain;f=fp16.h;fp=fp16.h;h=9f7eff926fca594d54198b14b3ec30d834124508;hp=0000000000000000000000000000000000000000;hb=1f4a7aefd4a149e93a1dc41f85958e827670c98b;hpb=7d7149ef94571b83e4cbd8e3359e3c3c9aea85c2 diff --git a/fp16.h b/fp16.h new file mode 100644 index 0000000..9f7eff9 --- /dev/null +++ b/fp16.h @@ -0,0 +1,27 @@ +#ifndef _MOVIT_FP16_H +#define _MOVIT_FP16_H 1 + +// Code for converting to and from fp16 (from fp64), without any particular +// machine support, with proper IEEE round-to-even behavior (and correct +// handling of NaNs and infinities). This is needed because some OpenGL +// drivers don't properly round off when asked to convert data themselves. +// +// These routines are not particularly fast. + +namespace movit { + +typedef unsigned int fp32_int_t; +typedef unsigned short fp16_int_t; + +double fp16_to_fp64(fp16_int_t x); +fp16_int_t fp64_to_fp16(double x); + +// These are not very useful by themselves, but are implemented using the same +// code as the fp16 ones (just with different constants), so they are useful +// for verifying against the FPU in unit tests. +double fp32_to_fp64(fp32_int_t x); +fp32_int_t fp64_to_fp32(double x); + +} // namespace movit + +#endif // _MOVIT_FP16_H