gem5  v22.0.0.1
helpers.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 __SYSTEMC_EXT_TLM_CORE_2_GENERIC_PAYLOAD_HELPERS_HH__
21 #define __SYSTEMC_EXT_TLM_CORE_2_GENERIC_PAYLOAD_HELPERS_HH__
22 
23 namespace tlm
24 {
25 
27 
28 inline tlm_endianness
30 {
31  static tlm_endianness host_endianness = TLM_UNKNOWN_ENDIAN;
32 
33  if (host_endianness == TLM_UNKNOWN_ENDIAN) {
34  unsigned int number = 1;
35  unsigned char *p_msb_or_lsb = (unsigned char *)&number;
36  host_endianness = (p_msb_or_lsb[0] == 0) ?
38  }
39  return host_endianness;
40 }
41 
42 inline bool
44 {
45  static tlm_endianness host_endianness = TLM_UNKNOWN_ENDIAN;
46  static bool host_little_endian = false;
47 
48  if (host_endianness == TLM_UNKNOWN_ENDIAN) {
49  unsigned int number = 1;
50  unsigned char *p_msb_or_lsb = (unsigned char *)&number;
51 
52  host_little_endian = (p_msb_or_lsb[0] == 0) ? false : true;
53  }
54 
55  return host_little_endian;
56 }
57 
58 inline bool
60 {
62  return endianness == TLM_LITTLE_ENDIAN;
63  } else {
64  return endianness == TLM_BIG_ENDIAN;
65  }
66 }
67 
68 } // namespace tlm
69 
70 #endif /* __SYSTEMC_EXT_TLM_CORE_2_GENERIC_PAYLOAD_HELPERS_HH__ */
tlm::TLM_LITTLE_ENDIAN
@ TLM_LITTLE_ENDIAN
Definition: helpers.hh:60
tlm::has_host_endianness
bool has_host_endianness(tlm_endianness endianness)
Definition: helpers.hh:76
tlm::tlm_endianness
tlm_endianness
Definition: helpers.hh:43
tlm::get_host_endianness
tlm_endianness get_host_endianness()
Definition: helpers.hh:46
tlm
Definition: analysis_fifo.hh:27
tlm::TLM_UNKNOWN_ENDIAN
@ TLM_UNKNOWN_ENDIAN
Definition: helpers.hh:60
tlm::TLM_BIG_ENDIAN
@ TLM_BIG_ENDIAN
Definition: helpers.hh:60
tlm::host_has_little_endianness
bool host_has_little_endianness()
Definition: helpers.hh:60

Generated on Sat Jun 18 2022 08:12:27 for gem5 by doxygen 1.8.17