summaryrefslogtreecommitdiff
path: root/libviengoos/viengoos/math.h
blob: 5ab54c8733eb0a27755180ea975f9c306220c086 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/* l4/math.h - Public interface to Hurd mathematical support functions.
   Copyright (C) 2003, 2004, 2007, 2008 Free Software Foundation, Inc.
   Written by Marcus Brinkmann <marcus@gnu.org>.

   This file is part of the GNU Hurd.
 
   The GNU Hurd is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public License
   as published by the Free Software Foundation; either version 2.1 of
   the License, or (at your option) any later version.
 
   The GNU Hurd is distributed in the hope that it will be
   useful, but WITHOUT ANY WARRANTY; without even the implied warranty
   of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU Lesser General Public License for more details.
 
   You should have received a copy of the GNU Lesser General Public
   License along with the GNU L4 library; if not, write to the Free
   Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
   02111-1307, USA.  */

#ifndef _HURD_MATH_H
#define _HURD_MATH_H

#include <stdint.h>
#include <bits/wordsize.h>

/* Return 0 if DATA is 0, or the bit number of the most significant
   bit set in DATA.  The least significant bit is 1, the most
   significant bit 32 resp. 64.  */
static inline uintptr_t
vg_msb (uintptr_t data)
{
  if (! data)
    return 0;

#if __WORDSIZE == 64
  return 8 * sizeof (data)  - __builtin_clzll (data);
#else
  return 8 * sizeof (data)  - __builtin_clz (data);
#endif
}

static inline uintptr_t
vg_msb64 (uint64_t data)
{
  if (! data)
    return 0;

  return 8 * sizeof (data)  - __builtin_clzll (data);
}

/* Return 0 if DATA is 0, or the bit number of the least significant
   bit set in DATA.  The least significant bit is 1, the most
   significant bit 32 resp. 64.  */
static inline uintptr_t
vg_lsb (uintptr_t data)
{
#if __WORDSIZE == 64
  return __builtin_ffsll (data);
#else
  return __builtin_ffs (data);
#endif
}

static inline uintptr_t
vg_lsb64 (uint64_t data)
{
  return __builtin_ffsll (data);
}

#endif