clip_mode.m4 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. dnl @synopsis MN_C_CLIP_MODE
  2. dnl
  3. dnl Determine the clipping mode when converting float to int.
  4. dnl @version 1.0 May 17 2003
  5. dnl @author Erik de Castro Lopo <erikd AT mega-nerd DOT com>
  6. dnl
  7. dnl Permission to use, copy, modify, distribute, and sell this file for any
  8. dnl purpose is hereby granted without fee, provided that the above copyright
  9. dnl and this permission notice appear in all copies. No representations are
  10. dnl made about the suitability of this software for any purpose. It is
  11. dnl provided "as is" without express or implied warranty.
  12. dnl Find the clipping mode in the following way:
  13. dnl 1) If we are not cross compiling test it.
  14. dnl 2) IF we are cross compiling, assume that clipping isn't done correctly.
  15. AC_DEFUN([MN_C_CLIP_MODE],
  16. [AC_CACHE_CHECK(processor clipping capabilities,
  17. ac_cv_c_clip_type,
  18. # Initialize to unknown
  19. ac_cv_c_clip_positive=unknown
  20. ac_cv_c_clip_negative=unknown
  21. if test $ac_cv_c_clip_positive = unknown ; then
  22. AC_TRY_RUN(
  23. [[
  24. #define _ISOC9X_SOURCE 1
  25. #define _ISOC99_SOURCE 1
  26. #define __USE_ISOC99 1
  27. #define __USE_ISOC9X 1
  28. #include <math.h>
  29. int main (void)
  30. { double fval ;
  31. int k, ival ;
  32. fval = 1.0 * 0x7FFFFFFF ;
  33. for (k = 0 ; k < 100 ; k++)
  34. { ival = (lrint (fval)) >> 24 ;
  35. if (ival != 127)
  36. return 1 ;
  37. fval *= 1.2499999 ;
  38. } ;
  39. return 0 ;
  40. }
  41. ]],
  42. ac_cv_c_clip_positive=yes,
  43. ac_cv_c_clip_positive=no,
  44. ac_cv_c_clip_positive=unknown
  45. )
  46. AC_TRY_RUN(
  47. [[
  48. #define _ISOC9X_SOURCE 1
  49. #define _ISOC99_SOURCE 1
  50. #define __USE_ISOC99 1
  51. #define __USE_ISOC9X 1
  52. #include <math.h>
  53. int main (void)
  54. { double fval ;
  55. int k, ival ;
  56. fval = -8.0 * 0x10000000 ;
  57. for (k = 0 ; k < 100 ; k++)
  58. { ival = (lrint (fval)) >> 24 ;
  59. if (ival != -128)
  60. return 1 ;
  61. fval *= 1.2499999 ;
  62. } ;
  63. return 0 ;
  64. }
  65. ]],
  66. ac_cv_c_clip_negative=yes,
  67. ac_cv_c_clip_negative=no,
  68. ac_cv_c_clip_negative=unknown
  69. )
  70. fi
  71. if test $ac_cv_c_clip_positive = yes ; then
  72. ac_cv_c_clip_positive=1
  73. else
  74. ac_cv_c_clip_positive=0
  75. fi
  76. if test $ac_cv_c_clip_negative = yes ; then
  77. ac_cv_c_clip_negative=1
  78. else
  79. ac_cv_c_clip_negative=0
  80. fi
  81. [[
  82. case "$ac_cv_c_clip_positive$ac_cv_c_clip_negative" in
  83. "00")
  84. ac_cv_c_clip_type="none"
  85. ;;
  86. "10")
  87. ac_cv_c_clip_type="positive"
  88. ;;
  89. "01")
  90. ac_cv_c_clip_type="negative"
  91. ;;
  92. "11")
  93. ac_cv_c_clip_type="both"
  94. ;;
  95. esac
  96. ]]
  97. )
  98. ]
  99. )# MN_C_CLIP_MODE