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 1594

Go to most recent revision | 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
   Copyright (C) 1999 Damjan Lampret, lampret@opencores.org
3
   Copyright (C) 2002 Marko Mlinar, markom@opencores.org
4
 
5
This file is part of OpenRISC 1000 Architectural Simulator.
6
 
7
This program is free software; you can redistribute it and/or modify
8
it under the terms of the GNU General Public License as published by
9
the Free Software Foundation; either version 2 of the License, or
10
(at your option) any later version.
11
 
12
This program is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
GNU General Public License for more details.
16
 
17
You should have received a copy of the GNU General Public License
18
along with this program; if not, write to the Free Software
19
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
20
 
21
/* returns log2(x) */
22
/* Call this log2_int, because there is a library function named log2 */
23
int log2_int (unsigned long x)
24
{
25
  int c = 0;
26
  if (!x) return 0; /* not by the book, but practical */
27
  while (x != 1) x >>= 1, c++;
28
  return c;
29
}
30
 
31
int is_power2 (int x)
32
{
33 1594 nogj
  if(!x)
34
    return 0;
35 1555 nogj
  while (!(x & 1))
36
    x >>= 1;
37
  return x == 1;
38
}
39
 

powered by: WebSVN 2.1.0

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