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

Subversion Repositories zipcpu

[/] [zipcpu/] [trunk/] [sim/] [cpp/] [twoc.cpp] - Blame information for rev 209

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 209 dgisselq
////////////////////////////////////////////////////////////////////////////////
2 204 dgisselq
//
3
// Filename:    twoc.cpp
4
//
5 209 dgisselq
// Project:     Zip CPU -- a small, lightweight, RISC CPU soft core
6 204 dgisselq
//
7
// Purpose:     Some various two's complement related C++ helper routines.
8
//              Specifically, these help extract signed numbers from
9 209 dgisselq
//      packed bitfields, while guaranteeing that the upper bits are properly
10
//      sign extended (or not) as desired.
11 204 dgisselq
//
12
// Creator:     Dan Gisselquist, Ph.D.
13
//              Gisselquist Technology, LLC
14
//
15 209 dgisselq
////////////////////////////////////////////////////////////////////////////////
16 204 dgisselq
//
17 209 dgisselq
// Copyright (C) 2015,2017, Gisselquist Technology, LLC
18 204 dgisselq
//
19
// This program is free software (firmware): you can redistribute it and/or
20
// modify it under the terms of  the GNU General Public License as published
21
// by the Free Software Foundation, either version 3 of the License, or (at
22
// your option) any later version.
23
//
24
// This program is distributed in the hope that it will be useful, but WITHOUT
25
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
26
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
27
// for more details.
28
//
29
// You should have received a copy of the GNU General Public License along
30 209 dgisselq
// with this program.  (It's in the $(ROOT)/doc directory.  Run make with no
31 204 dgisselq
// target there if the PDF file isn't present.)  If not, see
32
// <http://www.gnu.org/licenses/> for a copy.
33
//
34
// License:     GPL, v3, as defined and found on www.gnu.org,
35
//              http://www.gnu.org/licenses/gpl.html
36
//
37
//
38 209 dgisselq
////////////////////////////////////////////////////////////////////////////////
39
//
40
//
41 204 dgisselq
#include "twoc.h"
42
 
43
long    sbits(const long val, const int bits) {
44
        long    r;
45
 
46
        r = val & ((1l<<bits)-1);
47
        if (r & (1l << (bits-1)))
48
                r |= (-1l << bits);
49
        return r;
50
}
51
 
52
unsigned long   ubits(const long val, const int bits) {
53
        unsigned long r = val & ((1l<<bits)-1);
54
        return r;
55
}
56
 
57
 

powered by: WebSVN 2.1.0

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