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

Subversion Repositories thor

[/] [thor/] [trunk/] [FT64v5/] [software/] [CC64/] [source/] [Utility.cpp] - Blame information for rev 48

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 48 robfinch
// ============================================================================
2
//        __
3
//   \\__/ o\    (C) 2012-2018  Robert Finch, Waterloo
4
//    \  __ /    All rights reserved.
5
//     \/_//     robfinch<remove>@finitron.ca
6
//       ||
7
//
8
// CC64 - 'C' derived language compiler
9
//  - 64 bit CPU
10
//
11
// This source file is free software: you can redistribute it and/or modify 
12
// it under the terms of the GNU Lesser General Public License as published 
13
// by the Free Software Foundation, either version 3 of the License, or     
14
// (at your option) any later version.                                      
15
//                                                                          
16
// This source file is distributed in the hope that it will be useful,      
17
// but WITHOUT ANY WARRANTY; without even the implied warranty of           
18
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            
19
// GNU General Public License for more details.                             
20
//                                                                          
21
// You should have received a copy of the GNU General Public License        
22
// along with this program.  If not, see <http://www.gnu.org/licenses/>.    
23
//                                                                          
24
// ============================================================================
25
//
26
#include "stdafx.h"
27
 
28
int round2(int n)
29
{
30
        while (n & 1) n++;
31
        return (n);
32
}
33
 
34
int round8(int n)
35
{
36
        while (n & 7) n++;
37
        return (n);
38
}
39
 
40
int popcnt(int64_t m)
41
{
42
        int n;
43
        int cnt;
44
 
45
        cnt = 0;
46
        for (n = 0; n < 64; n = n + 1)
47
                if (m & (1LL << n)) cnt = cnt + 1;
48
        return (cnt);
49
}
50
 
51
std::string TraceName(SYM *sp)
52
{
53
        std::string namebuf;
54
        SYM *vector[64];
55
        int deep = 0;
56
 
57
        do {
58
                vector[deep] = sp;
59
                sp = sp->GetParentPtr();
60
                deep++;
61
                if (deep > 63) {
62
                        break; // should be an error
63
                }
64
        } while (sp);
65
        deep--;
66
        namebuf = "";
67
        while (deep > 0) {
68
                namebuf += *vector[deep]->name;
69
                namebuf += "_";
70
                deep--;
71
        }
72
        namebuf += *vector[deep]->name;
73
        return namebuf;
74
}
75
 

powered by: WebSVN 2.1.0

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