1 /* lzo_func.ch -- functions
3 This file is part of the LZO real-time data compression library.
5 Copyright (C) 2011 Markus Franz Xaver Johannes Oberhumer
6 Copyright (C) 2010 Markus Franz Xaver Johannes Oberhumer
7 Copyright (C) 2009 Markus Franz Xaver Johannes Oberhumer
8 Copyright (C) 2008 Markus Franz Xaver Johannes Oberhumer
9 Copyright (C) 2007 Markus Franz Xaver Johannes Oberhumer
10 Copyright (C) 2006 Markus Franz Xaver Johannes Oberhumer
11 Copyright (C) 2005 Markus Franz Xaver Johannes Oberhumer
12 Copyright (C) 2004 Markus Franz Xaver Johannes Oberhumer
13 Copyright (C) 2003 Markus Franz Xaver Johannes Oberhumer
14 Copyright (C) 2002 Markus Franz Xaver Johannes Oberhumer
15 Copyright (C) 2001 Markus Franz Xaver Johannes Oberhumer
16 Copyright (C) 2000 Markus Franz Xaver Johannes Oberhumer
17 Copyright (C) 1999 Markus Franz Xaver Johannes Oberhumer
18 Copyright (C) 1998 Markus Franz Xaver Johannes Oberhumer
19 Copyright (C) 1997 Markus Franz Xaver Johannes Oberhumer
20 Copyright (C) 1996 Markus Franz Xaver Johannes Oberhumer
23 The LZO library is free software; you can redistribute it and/or
24 modify it under the terms of the GNU General Public License as
25 published by the Free Software Foundation; either version 2 of
26 the License, or (at your option) any later version.
28 The LZO library is distributed in the hope that it will be useful,
29 but WITHOUT ANY WARRANTY; without even the implied warranty of
30 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 GNU General Public License for more details.
33 You should have received a copy of the GNU General Public License
34 along with the LZO library; see the file COPYING.
35 If not, write to the Free Software Foundation, Inc.,
36 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
38 Markus F.X.J. Oberhumer
39 <markus@oberhumer.com>
40 http://www.oberhumer.com/opensource/lzo/
44 /* WARNING: this file should *not* be used by applications. It is
45 part of the implementation of the library and is subject
50 /***********************************************************************
52 ************************************************************************/
54 #if (defined(_WIN32) || defined(_WIN64)) && ((LZO_CC_INTELC && (__INTEL_COMPILER >= 1000)) || (LZO_CC_MSC && (_MSC_VER >= 1400)))
56 #if !defined(lzo_bitops_clz32) && defined(WANT_lzo_bitops_clz32) && 0
57 #pragma intrinsic(_BitScanReverse)
58 static __lzo_inline unsigned lzo_bitops_clz32(lzo_uint32 v)
61 (void) _BitScanReverse(&r, v);
64 #define lzo_bitops_clz32 lzo_bitops_clz32
66 #if !defined(lzo_bitops_clz64) && defined(WANT_lzo_bitops_clz64) && defined(LZO_UINT64_MAX) && 0
67 #pragma intrinsic(_BitScanReverse64)
68 static __lzo_inline unsigned lzo_bitops_clz64(lzo_uint64 v)
71 (void) _BitScanReverse64(&r, v);
74 #define lzo_bitops_clz64 lzo_bitops_clz64
76 #if !defined(lzo_bitops_ctz32) && defined(WANT_lzo_bitops_ctz32)
77 #pragma intrinsic(_BitScanForward)
78 static __lzo_inline unsigned lzo_bitops_ctz32(lzo_uint32 v)
81 (void) _BitScanForward(&r, v);
84 #define lzo_bitops_ctz32 lzo_bitops_ctz32
86 #if !defined(lzo_bitops_ctz64) && defined(WANT_lzo_bitops_ctz64) && defined(LZO_UINT64_MAX)
87 #pragma intrinsic(_BitScanForward64)
88 static __lzo_inline unsigned lzo_bitops_ctz64(lzo_uint64 v)
91 (void) _BitScanForward64(&r, v);
94 #define lzo_bitops_ctz64 lzo_bitops_ctz64
97 #elif (LZO_CC_CLANG || (LZO_CC_GNUC >= 0x030400ul) || (LZO_CC_INTELC && (__INTEL_COMPILER >= 1000)) || (LZO_CC_LLVM && (!defined(__llvm_tools_version__) || (__llvm_tools_version__+0 >= 0x010500ul))))
98 #if !defined(lzo_bitops_clz32) && defined(WANT_lzo_bitops_clz32)
99 #define lzo_bitops_clz32(v) ((unsigned) __builtin_clz(v))
101 #if !defined(lzo_bitops_clz64) && defined(WANT_lzo_bitops_clz64) && defined(LZO_UINT64_MAX)
102 #define lzo_bitops_clz64(v) ((unsigned) __builtin_clzll(v))
104 #if !defined(lzo_bitops_ctz32) && defined(WANT_lzo_bitops_ctz32)
105 #define lzo_bitops_ctz32(v) ((unsigned) __builtin_ctz(v))
107 #if !defined(lzo_bitops_ctz64) && defined(WANT_lzo_bitops_ctz64) && defined(LZO_UINT64_MAX)
108 #define lzo_bitops_ctz64(v) ((unsigned) __builtin_ctzll(v))
110 #if !defined(lzo_bitops_popcount32) && defined(WANT_lzo_bitops_popcount32)
111 #define lzo_bitops_popcount32(v) ((unsigned) __builtin_popcount(v))
113 #if !defined(lzo_bitops_popcount32) && defined(WANT_lzo_bitops_popcount64) && defined(LZO_UINT64_MAX)
114 #define lzo_bitops_popcount64(v) ((unsigned) __builtin_popcountll(v))