compiler_opt.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * $Id$
  3. *
  4. * Copyright (C) 2007 iptelorg GmbH
  5. *
  6. * Permission to use, copy, modify, and distribute this software for any
  7. * purpose with or without fee is hereby granted, provided that the above
  8. * copyright notice and this permission notice appear in all copies.
  9. *
  10. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  11. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  12. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  13. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  14. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  15. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  16. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  17. */
  18. /*!
  19. * \file
  20. * \brief SIP-router core :: Compiler specific optimizations
  21. * \see \ref CompilerOptions
  22. *
  23. * \ingroup core
  24. * Module: \ref core
  25. *
  26. * \page CompilerOptions compiler specific optimizations:
  27. *
  28. \verbatim
  29. * - likely(expr) - branch predicition optimization - is more likely
  30. * that expr value will be 1 so optimize for this
  31. * case.
  32. * Example: if (likely(p!=NULL)) {... }
  33. * - unlikely(expr) - branch prediction optimization - is unlikely that
  34. * expr will be true, so optimize for this case
  35. * - prefetch(addr) - will prefetch addr. for reading
  36. * - prefetch_w(addr) - will prefetch addr. for writing
  37. * - prefetch_loc_r(addr, loc) - prefetch for reading, data at addr has
  38. * no temporal locality (loc==0), a short
  39. * degree of temporal locality (loc==1),
  40. * moderate (loc==2) or high (loc==3).
  41. * prefetch(addr) is equiv. to
  42. * prefetch_loc_r(addr, 3).
  43. * prefetch_loc_w(addr, loc) - like above but for writing.
  44. \endverbatim
  45. */
  46. /*
  47. * History:
  48. * --------
  49. * 2007-05-14 created by andrei
  50. */
  51. #ifndef __compiler_opt_h
  52. #define __compiler_opt_h
  53. /* likely/unlikely */
  54. #if __GNUC__ >= 3
  55. #define likely(expr) __builtin_expect(!!(expr), 1)
  56. #define unlikely(expr) __builtin_expect(!!(expr), 0)
  57. #else /* __GNUC__ */
  58. /* #warning "No compiler optimizations supported try gcc 4.x" */
  59. #define likely(expr) (expr)
  60. #define unlikely(expr) (expr)
  61. #endif /* __GNUC__ */
  62. /* prefetch* */
  63. #if ( __GNUC__ > 3 ) || ( __GNUC__ == 3 && __GNUC_MINOR__ >= 1 )
  64. #define prefetch(addr) __builtin_prefetch((addr))
  65. #define prefetch_w(addr) __builtin_prefetch((addr), 1)
  66. #define prefetch_loc_r(addr, loc) __builtin_prefetch((addr), 0, (loc))
  67. #define prefetch_loc_w(addr, loc) __builtin_prefetch((addr), 1, (loc))
  68. #else
  69. #define prefetch(addr)
  70. #define prefetch_w(addr)
  71. #define prefetch_loc_r(addr, loc)
  72. #define prefetch_loc_w(addr, loc)
  73. #endif /* __GNUC__ > 3 || ( __GNUC__ == 3 && __GNUC_MINOR__ >= 1 ) */
  74. #endif