ocintrin.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /* SPDX-License-Identifier: LGPL-2.1 OR BSD-3-Clause */
  2. /********************************************************************
  3. * *
  4. * THIS FILE IS PART OF THE OggTheora SOFTWARE CODEC SOURCE CODE. *
  5. * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
  6. * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
  7. * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
  8. * *
  9. * THE Theora SOURCE CODE IS COPYRIGHT (C) 2002-2009 *
  10. * by the Xiph.Org Foundation and contributors http://www.xiph.org/ *
  11. * *
  12. ********************************************************************
  13. function:
  14. last mod: $Id: ocintrin.h 16503 2009-08-22 18:14:02Z giles $
  15. ********************************************************************/
  16. /*Some common macros for potential platform-specific optimization.*/
  17. #include <math.h>
  18. #if !defined(_ocintrin_H)
  19. # define _ocintrin_H (1)
  20. /*Some specific platforms may have optimized intrinsic or inline assembly
  21. versions of these functions which can substantially improve performance.
  22. We define macros for them to allow easy incorporation of these non-ANSI
  23. features.*/
  24. /*Note that we do not provide a macro for abs(), because it is provided as a
  25. library function, which we assume is translated into an intrinsic to avoid
  26. the function call overhead and then implemented in the smartest way for the
  27. target platform.
  28. With modern gcc (4.x), this is true: it uses cmov instructions if the
  29. architecture supports it and branchless bit-twiddling if it does not (the
  30. speed difference between the two approaches is not measurable).
  31. Interestingly, the bit-twiddling method was patented in 2000 (US 6,073,150)
  32. by Sun Microsystems, despite prior art dating back to at least 1996:
  33. http://web.archive.org/web/19961201174141/www.x86.org/ftp/articles/pentopt/PENTOPT.TXT
  34. On gcc 3.x, however, our assumption is not true, as abs() is translated to a
  35. conditional jump, which is horrible on deeply piplined architectures (e.g.,
  36. all consumer architectures for the past decade or more).
  37. Also be warned that -C*abs(x) where C is a constant is mis-optimized as
  38. abs(C*x) on every gcc release before 4.2.3.
  39. See bug http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34130 */
  40. #endif