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-2017  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#include <stdbool.h>
33
34typedef uint64_t uint128_t[2];
35typedef uint64_t uint256_t[4];
36
37/* A type to represent V-bits */
38typedef struct {
39   unsigned num_bits;
40   union {
41      uint8_t   u8;
42      uint16_t  u16;
43      uint32_t  u32;
44      uint64_t  u64;
45      uint128_t u128;
46      uint256_t u256;
47   } bits;
48} vbits_t;
49
50
51/* A type large enough to hold any IRtype'd value. At this point
52   we do not expect to test with specific floating point values.
53   So we don't need to represent them. */
54typedef union {
55   uint8_t   u8;
56   uint16_t  u16;
57   uint32_t  u32;
58   uint64_t  u64;
59   uint128_t u128;
60   uint256_t u256;
61} value_t;
62
63
64void    print_vbits(FILE *, vbits_t);
65vbits_t undefined_vbits(unsigned num_bits);
66vbits_t undefined_vbits_BxE(unsigned int bits, unsigned int elements,
67                            vbits_t v);
68vbits_t undefined_vbits_BxE_rotate(unsigned int bits, unsigned int elements,
69                                   vbits_t vbits,
70                                   value_t value);
71vbits_t undefined_vbits_128_even_element(unsigned int bits,
72                                         unsigned int elements, vbits_t v);
73vbits_t undefined_vbits_64x2_transpose(vbits_t v);
74vbits_t undefined_vbits_Narrow256_AtoB(unsigned int src_num_bits,
75                                       unsigned int result_num_bits,
76                                       vbits_t src1_v, value_t src1_value,
77                                       vbits_t src2_v, value_t src2_value,
78                                       bool sataurate);
79vbits_t defined_vbits(unsigned num_bits);
80int     equal_vbits(vbits_t, vbits_t);
81vbits_t truncate_vbits(vbits_t, unsigned num_bits);
82vbits_t left_vbits(vbits_t, unsigned num_bits);
83vbits_t or_vbits(vbits_t, vbits_t);
84vbits_t and_vbits(vbits_t, vbits_t);
85vbits_t concat_vbits(vbits_t, vbits_t);
86vbits_t upper_vbits(vbits_t);
87vbits_t sextend_vbits(vbits_t, unsigned num_bits);
88vbits_t zextend_vbits(vbits_t, unsigned num_bits);
89vbits_t onehot_vbits(unsigned bitno, unsigned num_bits);
90vbits_t shl_vbits(vbits_t, unsigned amount);
91vbits_t shr_vbits(vbits_t, unsigned amount);
92vbits_t sar_vbits(vbits_t, unsigned amount);
93int     completely_defined_vbits(vbits_t);
94vbits_t cmpord_vbits(unsigned v1_num_bits, unsigned v2_num_bits);
95
96#endif // VBITS_H
97