Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Hide a gcc attribute that drives doxygen nuts
[simgrid.git] / src / mc / mc_mmu.h
1 /* Copyright (c) 2014-2017. 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_H
7 #define SIMGRID_MC_MMU_H
8
9 #include <cstdint>
10 #include <cstddef>
11
12 #include <xbt/asserts.h>
13 #include <xbt/base.h> // xbt_pagesize...
14 #include <xbt/misc.h>
15
16 #include <simgrid_config.h>
17
18
19 namespace simgrid {
20 namespace mc {
21 // TODO, do not depend on xbt_pagesize/xbt_pagebits but our own chunk size
22 namespace mmu {
23
24 static int chunkSize()
25 {
26   return xbt_pagesize;
27 }
28
29 /** @brief How many memory pages are necessary to store size bytes?
30  *
31  *  @param size Byte size
32  *  @return Number of memory pages
33  */
34 static XBT_ALWAYS_INLINE std::size_t chunkCount(std::size_t size)
35 {
36   size_t page_count = size >> xbt_pagebits;
37   if (size & (xbt_pagesize-1))
38     page_count ++;
39   return page_count;
40 }
41
42 /** @brief Split into chunk number and remaining offset */
43 static XBT_ALWAYS_INLINE std::pair<std::size_t, std::uintptr_t> split(std::uintptr_t offset)
44 {
45   return {
46     offset >> xbt_pagebits,
47     offset & (xbt_pagesize-1)
48   };
49 }
50
51 /** Merge chunk number and remaining offset info a global offset */
52 static XBT_ALWAYS_INLINE std::uintptr_t join(std::size_t page, std::uintptr_t offset)
53 {
54   return ((std::uintptr_t) page << xbt_pagebits) + offset;
55 }
56
57 static XBT_ALWAYS_INLINE std::uintptr_t join(std::pair<std::size_t, std::uintptr_t> value)
58 {
59   return join(value.first, value.second);
60 }
61
62 static XBT_ALWAYS_INLINE bool sameChunk(std::uintptr_t a, std::uintptr_t b)
63 {
64   return (a >> xbt_pagebits) == (b >> xbt_pagebits);
65 }
66
67 }
68 }
69 }
70
71 #endif