MatchLib
All Classes Namespaces Files Functions Modules Pages
TypeToBits.h
1/*
2 * Copyright (c) 2018-2019, NVIDIA CORPORATION. All rights reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License")
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#ifndef __TYPETOBITS_H__
17#define __TYPETOBITS_H__
18
19#include <systemc.h>
20#include <nvhls_int.h>
21#include <nvhls_types.h>
22#include <nvhls_marshaller.h>
23
47template <typename T>
48sc_lv<Wrapped<T>::width> TypeToBits(T in)
49{
50 Marshaller<Wrapped<T>::width> marshaller;
51 Wrapped<T> wm(in);
52 wm.Marshall(marshaller);
53 sc_lv<Wrapped<T>::width> bits = marshaller.GetResult();
54 return bits;
55}
56
80template <typename T>
81T BitsToType(sc_lv<Wrapped<T>::width> mbits)
82{
83 Marshaller<Wrapped<T>::width> marshaller(mbits);
84 Wrapped<T> result;
85 result.Marshall(marshaller);
86 return result.val;
87}
88
114template <typename T>
115NVUINTW(Wrapped<T>::width) TypeToNVUINT(T in)
116{
117 return BitsToType<NVUINTW(Wrapped<T>::width)>(TypeToBits(in));
118}
119
143template <typename T>
144T NVUINTToType(const NVUINTW(Wrapped<T>::width) & uintbits)
145{
146 return BitsToType<T>(TypeToBits(uintbits));
147}
148
149#endif
T BitsToType(sc_lv< Wrapped< T >::width > mbits)
Convert logic vector to type.
Definition TypeToBits.h:81
sc_lv< Wrapped< T >::width > TypeToBits(T in)
Convert Type to logic vector.
Definition TypeToBits.h:48
T NVUINTToType(const NVUINTW(Wrapped< T >::width) &uintbits)
Convert NVUINT to type.
Definition TypeToBits.h:144
#define NVUINTW(width)
Definition nvhls_types.h:35