OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [tags/] [rel-0-3-0-rc2/] [or1ksim/] [support/] [misc.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1555 nogj
/* misc.c -- Misc. routines that just don't fit anywhere else
2 1748 jeremybenn
 
3 1555 nogj
   Copyright (C) 1999 Damjan Lampret, lampret@opencores.org
4
   Copyright (C) 2002 Marko Mlinar, markom@opencores.org
5 1748 jeremybenn
   Copyright (C) 2008 Embecosm Limited
6 1555 nogj
 
7 1748 jeremybenn
   Contributor Jeremy Bennett <jeremy.bennett@embecosm.com>
8 1555 nogj
 
9 1748 jeremybenn
   This file is part of Or1ksim, the OpenRISC 1000 Architectural Simulator.
10 1555 nogj
 
11 1748 jeremybenn
   This program is free software; you can redistribute it and/or modify it
12
   under the terms of the GNU General Public License as published by the Free
13
   Software Foundation; either version 3 of the License, or (at your option)
14
   any later version.
15 1555 nogj
 
16 1748 jeremybenn
   This program is distributed in the hope that it will be useful, but WITHOUT
17
   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18
   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
19
   more details.
20 1555 nogj
 
21 1748 jeremybenn
   You should have received a copy of the GNU General Public License along
22
   with this program.  If not, see <http://www.gnu.org/licenses/>.  */
23
 
24
/* This program is commented throughout in a fashion suitable for processing
25
   with Doxygen. */
26
 
27
 
28
/* Autoconf and/or portability configuration */
29
#include "config.h"
30
 
31
 
32 1555 nogj
/* returns log2(x) */
33
/* Call this log2_int, because there is a library function named log2 */
34 1748 jeremybenn
int
35
log2_int (unsigned long x)
36 1555 nogj
{
37
  int c = 0;
38 1748 jeremybenn
  if (!x)
39
    return 0;                    /* not by the book, but practical */
40
  while (x != 1)
41
    x >>= 1, c++;
42 1555 nogj
  return c;
43
}
44
 
45 1748 jeremybenn
int
46
is_power2 (int x)
47 1555 nogj
{
48 1748 jeremybenn
  if (!x)
49 1594 nogj
    return 0;
50 1555 nogj
  while (!(x & 1))
51
    x >>= 1;
52
  return x == 1;
53
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.