• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* -*- mode: C; c-basic-offset: 3; -*- */
2 
3 /*
4    This file is part of MemCheck, a heavyweight Valgrind tool for
5    detecting memory errors.
6 
7    Copyright (C) 2012-2015  Florian Krohm
8 
9    This program is free software; you can redistribute it and/or
10    modify it under the terms of the GNU General Public License as
11    published by the Free Software Foundation; either version 2 of the
12    License, or (at your option) any later version.
13 
14    This program is distributed in the hope that it will be useful, but
15    WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17    General Public License for more details.
18 
19    You should have received a copy of the GNU General Public License
20    along with this program; if not, write to the Free Software
21    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
22    02111-1307, USA.
23 
24    The GNU General Public License is contained in the file COPYING.
25 */
26 
27 #ifndef VBITS_H
28 #define VBITS_H
29 
30 #include <stdint.h>
31 #include <stdio.h>
32 
33 typedef uint64_t uint128_t[2];
34 typedef uint64_t uint256_t[4];
35 
36 /* A type to represent V-bits */
37 typedef struct {
38    unsigned num_bits;
39    union {
40       uint8_t   u8;
41       uint16_t  u16;
42       uint32_t  u32;
43       uint64_t  u64;
44       uint128_t u128;
45       uint256_t u256;
46    } bits;
47 } vbits_t;
48 
49 
50 /* A type large enough to hold any IRtype'd value. At this point
51    we do not expect to test with specific floating point values.
52    So we don't need to represent them. */
53 typedef union {
54    uint8_t   u8;
55    uint16_t  u16;
56    uint32_t  u32;
57    uint64_t  u64;
58    uint128_t u128;
59    uint256_t u256;
60 } value_t;
61 
62 
63 void    print_vbits(FILE *, vbits_t);
64 vbits_t undefined_vbits(unsigned num_bits);
65 vbits_t defined_vbits(unsigned num_bits);
66 int     equal_vbits(vbits_t, vbits_t);
67 vbits_t truncate_vbits(vbits_t, unsigned num_bits);
68 vbits_t left_vbits(vbits_t, unsigned num_bits);
69 vbits_t or_vbits(vbits_t, vbits_t);
70 vbits_t and_vbits(vbits_t, vbits_t);
71 vbits_t concat_vbits(vbits_t, vbits_t);
72 vbits_t upper_vbits(vbits_t);
73 vbits_t sextend_vbits(vbits_t, unsigned num_bits);
74 vbits_t zextend_vbits(vbits_t, unsigned num_bits);
75 vbits_t onehot_vbits(unsigned bitno, unsigned num_bits);
76 vbits_t shl_vbits(vbits_t, unsigned amount);
77 vbits_t shr_vbits(vbits_t, unsigned amount);
78 vbits_t sar_vbits(vbits_t, unsigned amount);
79 int     completely_defined_vbits(vbits_t);
80 vbits_t cmpord_vbits(unsigned v1_num_bits, unsigned v2_num_bits);
81 
82 #endif // VBITS_H
83