1 |
2 |
dgisselq |
////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
//
|
3 |
|
|
// Filename: twoc.h
|
4 |
|
|
//
|
5 |
|
|
// Project: Zip CPU -- a small, lightweight, RISC CPU soft core
|
6 |
|
|
//
|
7 |
|
|
// Purpose: Some various two's complement related C++ helper routines.
|
8 |
|
|
// Specifically, these help extract signed numbers from
|
9 |
|
|
// packed bitfields, while guaranteeing that the upper bits
|
10 |
|
|
// are properly sign extended (or not) as desired.
|
11 |
|
|
//
|
12 |
|
|
// Creator: Dan Gisselquist, Ph.D.
|
13 |
|
|
// Gisselquist Tecnology, LLC
|
14 |
|
|
//
|
15 |
|
|
///////////////////////////////////////////////////////////////////////////
|
16 |
|
|
//
|
17 |
|
|
// Copyright (C) 2015, Gisselquist Technology, LLC
|
18 |
|
|
//
|
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 |
|
|
// with this program. (It's in the $(ROOT)/doc directory, run make with no
|
31 |
|
|
// 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 |
|
|
///////////////////////////////////////////////////////////////////////////
|
39 |
|
|
#ifndef TWOC_H
|
40 |
|
|
#define TWOC_H
|
41 |
|
|
|
42 |
|
|
extern long sbits(const long val, const int bits);
|
43 |
|
|
extern bool sfits(const long val, const int bits);
|
44 |
|
|
extern unsigned long ubits(const long val, const int bits);
|
45 |
|
|
extern unsigned long rndbits(const long val, const int bi, const int bo);
|
46 |
|
|
|
47 |
|
|
#endif
|
48 |
|
|
|