Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Make sure that the dtor of CheckerSide actually kills the application and waits for it
[simgrid.git] / src / mc / mc_mmu.hpp
1 /* Copyright (c) 2014-2023. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #ifndef SIMGRID_MC_MMU_HPP
7 #define SIMGRID_MC_MMU_HPP
8
9 #include "xbt/misc.h"
10 #include <cstdint>
11 #include <utility>
12
13 namespace simgrid::mc::mmu {
14 // TODO, do not depend on xbt_pagesize/xbt_pagebits but our own chunk size
15
16 /** @brief How many memory pages are necessary to store size bytes?
17  *
18  *  @param size Byte size
19  *  @return Number of memory pages
20  */
21 static XBT_ALWAYS_INLINE std::size_t chunk_count(std::size_t size)
22 {
23   std::size_t page_count = size >> xbt_pagebits;
24   if (size & (xbt_pagesize - 1))
25     page_count++;
26   return page_count;
27 }
28
29 /** @brief Split into chunk number and remaining offset */
30 static XBT_ALWAYS_INLINE std::pair<std::size_t, std::uintptr_t> split(std::uintptr_t offset)
31 {
32   return {offset >> xbt_pagebits, offset & (xbt_pagesize - 1)};
33 }
34
35 /** Merge chunk number and remaining offset into a global offset */
36 static XBT_ALWAYS_INLINE std::uintptr_t join(std::size_t page, std::uintptr_t offset)
37 {
38   return ((std::uintptr_t)page << xbt_pagebits) + offset;
39 }
40
41 static XBT_ALWAYS_INLINE std::uintptr_t join(std::pair<std::size_t, std::uintptr_t> value)
42 {
43   return join(value.first, value.second);
44 }
45
46 static XBT_ALWAYS_INLINE bool same_chunk(std::uintptr_t a, std::uintptr_t b)
47 {
48   return (a >> xbt_pagebits) == (b >> xbt_pagebits);
49 }
50 } // namespace simgrid::mc::mmu
51
52 #endif