1 /* Copyright (c) 2014-2015. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
7 #ifndef SIMGRID_MC_MMU_H
8 #define SIMGRID_MC_MMU_H
13 #include <xbt/asserts.h>
14 #include <xbt/base.h> // xbt_pagesize...
17 #include <simgrid_config.h>
22 // TODO, do not depend on xbt_pagesize/xbt_pagebits but our own chunk size
25 static int chunkSize()
30 /** @brief How many memory pages are necessary to store size bytes?
32 * @param size Byte size
33 * @return Number of memory pages
35 static inline __attribute__ ((always_inline))
36 std::size_t chunkCount(std::size_t size)
38 size_t page_count = size >> xbt_pagebits;
39 if (size & (xbt_pagesize-1))
44 /** @brief Split into chunk number and remaining offset */
45 static inline __attribute__ ((always_inline))
46 std::pair<std::size_t, std::uintptr_t> split(std::uintptr_t offset)
49 offset >> xbt_pagebits,
50 offset & (xbt_pagesize-1)
54 /** Merge chunk number and remaining offset info a global offset */
55 static inline __attribute__ ((always_inline))
56 std::uintptr_t join(std::size_t page, std::uintptr_t offset)
58 return ((std::uintptr_t) page << xbt_pagebits) + offset;
61 static inline __attribute__ ((always_inline))
62 std::uintptr_t join(std::pair<std::size_t,std::uintptr_t> value)
64 return join(value.first, value.second);
67 static inline __attribute__ ((always_inline))
68 bool sameChunk(std::uintptr_t a, std::uintptr_t b)
70 return (a >> xbt_pagebits) == (b >> xbt_pagebits);