1 /* Copyright (c) 2014-2017. The SimGrid Team. All rights reserved. */
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. */
6 #ifndef SIMGRID_MC_MMU_H
7 #define SIMGRID_MC_MMU_H
12 #include <xbt/asserts.h>
13 #include <xbt/base.h> // xbt_pagesize...
16 #include <simgrid_config.h>
21 // TODO, do not depend on xbt_pagesize/xbt_pagebits but our own chunk size
24 static int chunkSize()
29 /** @brief How many memory pages are necessary to store size bytes?
31 * @param size Byte size
32 * @return Number of memory pages
34 static XBT_ALWAYS_INLINE std::size_t chunkCount(std::size_t size)
36 size_t page_count = size >> xbt_pagebits;
37 if (size & (xbt_pagesize-1))
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)
46 offset >> xbt_pagebits,
47 offset & (xbt_pagesize-1)
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)
54 return ((std::uintptr_t) page << xbt_pagebits) + offset;
57 static XBT_ALWAYS_INLINE std::uintptr_t join(std::pair<std::size_t, std::uintptr_t> value)
59 return join(value.first, value.second);
62 static XBT_ALWAYS_INLINE bool sameChunk(std::uintptr_t a, std::uintptr_t b)
64 return (a >> xbt_pagebits) == (b >> xbt_pagebits);