ACT Library
Loading...
Searching...
No Matches
expr_width.h
Go to the documentation of this file.
1/*************************************************************************
2 *
3 * This file is part of the ACT library
4 *
5 * Copyright (c) 2021 Rajit Manohar
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (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., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
21 *
22 **************************************************************************
23 */
24#ifndef __ACT_EXPR_WIDTH_H__
25#define __ACT_EXPR_WIDTH_H__
26
27
46#define WIDTH_MAX 0
47#define WIDTH_MAX1 1
48#define WIDTH_SUM 2
49#define WIDTH_BOOL 3
50#define WIDTH_LEFT 4
51#define WIDTH_RIGHT 5
52#define WIDTH_LSHIFT 6
53
54#ifndef MAX
55#define MAX(a,b) ((a) < (b) ? (b) : (a))
56#endif
57
58#define WIDTH_UPDATE(mode) \
59 if (width) { \
60 if (mode == WIDTH_MAX) { \
61 *width = MAX(lw,rw); \
62 } \
63 else if (mode == WIDTH_MAX1) { \
64 *width = MAX(lw,rw)+1; \
65 } \
66 else if (mode == WIDTH_SUM) { \
67 *width = lw+rw; \
68 } \
69 else if (mode == WIDTH_BOOL) { \
70 *width = 1; \
71 } \
72 else if (mode == WIDTH_LEFT) { \
73 *width = lw; \
74 } \
75 else if (mode == WIDTH_RIGHT) { \
76 *width = rw; \
77 } \
78 else if (mode == WIDTH_LSHIFT) { \
79 *width = lw + ((1 << rw)-1); \
80 } \
81 }
82
83#endif /* __ACT_EXPR_WIDTH_H__ */