intrinsics.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /** BEGIN COPYRIGHT BLOCK
  2. * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
  3. * Copyright (C) 2005 Red Hat, Inc.
  4. * All rights reserved.
  5. *
  6. * License: GPL (version 3 or any later version).
  7. * See LICENSE for details.
  8. * END COPYRIGHT BLOCK **/
  9. #ifdef HAVE_CONFIG_H
  10. # include <config.h>
  11. #endif
  12. /* Header file used to declare functions which we beat on heavily as intrinsic */
  13. #if defined(HPUX)
  14. #define INLINE_DIRECTIVE __inline
  15. #elif defined(LINUX)
  16. #define INLINE_DIRECTIVE __inline__
  17. #else
  18. #define INLINE_DIRECTIVE
  19. #endif
  20. INLINE_DIRECTIVE static int strcmpi_fast(const char * dst, const char * src)
  21. {
  22. int f,l;
  23. do {
  24. if ( ((f = (unsigned char)(*(dst++))) >= 'A') && (f <= 'Z') )
  25. f -= ('A' - 'a');
  26. if ( ((l = (unsigned char)(*(src++))) >= 'A') && (l <= 'Z') )
  27. l -= ('A' - 'a');
  28. } while ( f && (f == l) );
  29. return(f - l);
  30. }
  31. #ifdef strcasecmp
  32. #undef strcasecmp
  33. #endif
  34. #define strcasecmp(x,y) strcmpi_fast(x,y)
  35. #ifdef strcmpi
  36. #undef strcmpi
  37. #endif
  38. #define strcmpi(x,y) strcmpi_fast(x,y)
  39. INLINE_DIRECTIVE static int tolower_fast(int c)
  40. {
  41. if ( (c >= 'A') && (c <= 'Z') )
  42. c = c + ('a' - 'A');
  43. return c;
  44. }
  45. #ifdef tolower
  46. #undef tolower
  47. #endif
  48. #define tolower(x) tolower_fast(x)
  49. INLINE_DIRECTIVE static int toupper_fast(int c)
  50. {
  51. if ( (c >= 'a') && (c <= 'z') )
  52. c = c - ('a' - 'A');
  53. return c;
  54. }
  55. #ifdef toupper
  56. #undef toupper
  57. #endif
  58. #define toupper(x) toupper_fast(x)
  59. INLINE_DIRECTIVE static int strncasecmp_fast(const char * dst, const char * src, int n)
  60. {
  61. int f,l,x=0;
  62. do {
  63. if ( ((f = (unsigned char)(*(dst++))) >= 'A') && (f <= 'Z') )
  64. f -= ('A' - 'a');
  65. if ( ((l = (unsigned char)(*(src++))) >= 'A') && (l <= 'Z') )
  66. l -= ('A' - 'a');
  67. } while ( f && (f == l) && ++x < n );
  68. return(f - l);
  69. }
  70. #ifdef strncasecmp
  71. #undef strncasecmp
  72. #endif
  73. #define strncasecmp(x,y,z) strncasecmp_fast(x,y,z)