gem5  v22.1.0.0
fifo_resize.hh
Go to the documentation of this file.
1 /*****************************************************************************
2 
3  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
4  more contributor license agreements. See the NOTICE file distributed
5  with this work for additional information regarding copyright ownership.
6  Accellera licenses this file to you under the Apache License, Version 2.0
7  (the "License"); you may not use this file except in compliance with the
8  License. You may obtain a copy of the License at
9 
10  http://www.apache.org/licenses/LICENSE-2.0
11 
12  Unless required by applicable law or agreed to in writing, software
13  distributed under the License is distributed on an "AS IS" BASIS,
14  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15  implied. See the License for the specific language governing
16  permissions and limitations under the License.
17 
18  *****************************************************************************/
19 
20 #ifndef __TLM_CORE_1_REQ_RSP_CHANNELS_FIFO_FIFO_RESIZE_HH__
21 #define __TLM_CORE_1_REQ_RSP_CHANNELS_FIFO_FIFO_RESIZE_HH__
22 
23 // Resize interface.
24 namespace tlm
25 {
26 
27 template <typename T>
28 inline void
30 {
31  if (m_size >= 0) {
32  m_expand = true;
33  m_size += n;
34  request_update();
35  }
36 }
37 
38 template <typename T>
39 inline void
41 {
42  m_expand = true;
43  m_size = -n;
44 
45  if (buffer.size() < static_cast<int>(n)) {
46  buffer.resize(n);
47  }
48 
49  request_update();
50 }
51 
52 template <typename T>
53 inline bool
55 {
56  if (m_size < 0) {
57  return false;
58  }
59 
60  return nb_bound(size() - n);
61 }
62 
63 template <typename T>
64 inline bool
65 tlm_fifo<T>::nb_bound(unsigned int new_size)
66 {
67  bool ret = true;
68 
69  if (static_cast<int>(new_size) < used()) {
70  new_size = used();
71  ret = false;
72  }
73 
74  m_size = new_size;
75  return ret;
76 }
77 
78 } // namespace tlm
79 
80 #endif /* __TLM_CORE_1_REQ_RSP_CHANNELS_FIFO_FIFO_RESIZE_HH__ */
void nb_unbound(unsigned int n=16)
Definition: fifo_resize.hh:40
bool nb_reduce(unsigned int n=1)
Definition: fifo_resize.hh:54
bool nb_bound(unsigned int n)
Definition: fifo_resize.hh:65
void nb_expand(unsigned int n=1)
Definition: fifo_resize.hh:29
Bitfield< 31 > n
Definition: misc_types.hh:462

Generated on Wed Dec 21 2022 10:22:42 for gem5 by doxygen 1.9.1