MatchLib
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 
47 template <typename T>
48 sc_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 
80 template <typename T>
81 T 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 
114 template <typename T>
115 NVUINTW(Wrapped<T>::width) TypeToNVUINT(T in)
116 {
117  return BitsToType<NVUINTW(Wrapped<T>::width)>(TypeToBits(in));
118 }
119 
143 template <typename T>
144 T 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
NVUINTW(Wrapped< T >::width) TypeToNVUINT(T in)
Convert Type to NVUINT.
Definition: TypeToBits.h:115
T NVUINTToType(const NVUINTW(Wrapped< T >::width) &uintbits)
Convert NVUINT to type.
Definition: TypeToBits.h:144