summaryrefslogtreecommitdiff
path: root/src/support/utilities.h
diff options
context:
space:
mode:
authorDerek Schuff <dschuff@chromium.org>2016-04-06 11:58:55 -0700
committerAlon Zakai <alonzakai@gmail.com>2016-04-06 11:58:55 -0700
commit62c07b549d14dfb974f73554026f0b9fff365968 (patch)
tree93eedaee3158cbb44748041c50f466641bc42a48 /src/support/utilities.h
parentc885ca69d19e7bd2c58b44eef242de334ac8c9dd (diff)
downloadbinaryen-62c07b549d14dfb974f73554026f0b9fff365968.tar.gz
binaryen-62c07b549d14dfb974f73554026f0b9fff365968.tar.bz2
binaryen-62c07b549d14dfb974f73554026f0b9fff365968.zip
Properly align the stack pointer
* Properly align the stack pointer By default (if no global base is given) the global base is 1, which seems wrong. In this case the stack pointer gets an address of 1, which is unaligned and definitely wrong. So, start the global base at 0 instead of 1 by default and align the stack pointer. Also factor allocation of statics into a function. * unconditionally allocate stack pointer; explicitly reserve address 0
Diffstat (limited to 'src/support/utilities.h')
-rw-r--r--src/support/utilities.h13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/support/utilities.h b/src/support/utilities.h
index 77263a78e..d35b2b34a 100644
--- a/src/support/utilities.h
+++ b/src/support/utilities.h
@@ -35,6 +35,19 @@ inline Destination bit_cast(const Source& source) {
return destination;
}
+inline bool isPowerOf2(uint32_t v) {
+ return v && !(v & (v - 1));
+}
+
+inline size_t alignAddr(size_t address, size_t alignment) {
+ assert(alignment && isPowerOf2((uint32_t)alignment) &&
+ "Alignment is not a power of two!");
+
+ assert(address + alignment - 1 >= address);
+
+ return ((address + alignment - 1) & ~(alignment - 1));
+}
+
} // namespace wasm
#endif // wasm_support_utilities_h