os.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #ifndef _OS_H
  2. #define _OS_H
  3. /********************************************************************
  4. * *
  5. * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
  6. * USE, DISTRIBUTION AND REPRODUCTION OF THIS SOURCE IS GOVERNED BY *
  7. * THE GNU LESSER/LIBRARY PUBLIC LICENSE, WHICH IS INCLUDED WITH *
  8. * THIS SOURCE. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
  9. * *
  10. * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2000 *
  11. * by Monty <monty@xiph.org> and the XIPHOPHORUS Company *
  12. * http://www.xiph.org/ *
  13. * *
  14. ********************************************************************
  15. function: #ifdef jail to whip a few platforms into the UNIX ideal.
  16. last mod: $Id: os.h,v 1.10.2.5 2000/11/04 06:58:38 xiphmont Exp $
  17. ********************************************************************/
  18. #include <math.h>
  19. #include <ogg/os_types.h>
  20. #ifndef _V_IFDEFJAIL_H_
  21. #define _V_IFDEFJAIL_H_
  22. #ifndef M_PI
  23. #define M_PI (3.1415926539)
  24. #endif
  25. #ifndef __GNUC__
  26. #ifdef _WIN32
  27. # include <malloc.h>
  28. # define rint(x) (floor((x)+0.5))
  29. #endif
  30. #endif
  31. #ifdef _WIN32
  32. # define FAST_HYPOT(a, b) sqrt((a)*(a) + (b)*(b))
  33. #else /* if not _WIN32 */
  34. # define FAST_HYPOT hypot
  35. #endif
  36. #endif
  37. #ifdef HAVE_ALLOCA_H
  38. #include <alloca.h>
  39. #endif
  40. #ifdef USE_MEMORY_H
  41. #include <memory.h>
  42. #endif
  43. #ifndef min
  44. # define min(x,y) ((x)>(y)?(y):(x))
  45. #endif
  46. #ifndef max
  47. # define max(x,y) ((x)<(y)?(y):(x))
  48. #endif
  49. #if defined(__i386__) && defined(__GNUC__)
  50. /* both GCC and MSVC are kinda stupid about rounding/casting to int.
  51. Because of encapsulation constraints (GCC can't see inside the asm
  52. block and so we end up doing stupid things like a store/load that
  53. is collectively a noop), we do it this way */
  54. /* we must set up the fpu before this works!! */
  55. typedef ogg_int16_t vorbis_fpu_control;
  56. static inline void vorbis_fpu_setround(vorbis_fpu_control *fpu){
  57. ogg_int16_t ret;
  58. ogg_int16_t temp;
  59. __asm__ __volatile__("fnstcw %0\n\t"
  60. "movw %0,%%dx\n\t"
  61. "orw $62463,%%dx\n\t"
  62. "movw %%dx,%1\n\t"
  63. "fldcw %1\n\t":"=m"(ret):"m"(temp): "dx");
  64. *fpu=ret;
  65. }
  66. static inline void vorbis_fpu_restore(vorbis_fpu_control fpu){
  67. __asm__ __volatile__("fldcw %0":: "m"(fpu));
  68. }
  69. /* assumes the FPU is in round mode! */
  70. static inline int vorbis_ftoi(double f){ /* yes, double! Otherwise,
  71. we get extra fst/fld to
  72. truncate precision */
  73. int i;
  74. __asm__("fistl %0": "=m"(i) : "t"(f));
  75. return(i);
  76. }
  77. #else
  78. static int vorbis_ftoi(double f){
  79. return (int)(f+.5);
  80. }
  81. typedef int vorbis_fpu_control;
  82. static inline void vorbis_fpu_setround(vorbis_fpu_control *fpu){
  83. }
  84. static inline void vorbis_fpu_restore(vorbis_fpu_control fpu){
  85. }
  86. #endif
  87. #endif /* _OS_H */