Codemod asserts to assertxs in the runtime
[hiphop-php.git] / hphp / runtime / vm / jit / align-arm.cpp
blobad70c756b9bb5b0a165c789118f50e4284ce75be
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
17 #include "hphp/runtime/vm/jit/align-arm.h"
19 #include "hphp/runtime/vm/jit/align-internal.h"
20 #include "hphp/runtime/vm/jit/smashable-instr-arm.h"
22 #include "hphp/util/data-block.h"
23 #include "hphp/vixl/a64/macro-assembler-a64.h"
25 #include <folly/Bits.h>
27 #include <utility>
29 namespace HPHP { namespace jit { namespace arm {
31 ///////////////////////////////////////////////////////////////////////////////
33 namespace {
36 * Targets of jmps on arm must be aligned to instruction size
38 constexpr size_t kJmpTargetAlign = vixl::kInstructionSize;
40 struct AlignImpl {
41 static DECLARE_ALIGN_TABLE(s_table);
43 static void pad(CodeBlock& cb, AlignContext context, size_t bytes) {
44 vixl::MacroAssembler a { cb };
45 auto const begin = cb.frontier();
47 switch (context) {
48 case AlignContext::Live: {
49 assertx(((bytes & 3) == 0) && "alignment must be multiple of 4");
50 for (; bytes > 0; bytes -= 4) {
51 a.Nop();
53 cb.sync(begin);
54 return;
56 case AlignContext::Dead: {
57 if (bytes > 4) {
58 a.Brk();
59 bytes -= 4;
61 cb.sync(begin);
62 if (bytes > 0) pad(cb, AlignContext::Live, bytes);
63 return;
66 not_reached();
70 DEFINE_ALIGN_TABLE(AlignImpl::s_table);
74 ///////////////////////////////////////////////////////////////////////////////
76 bool is_aligned(TCA frontier, Alignment alignment) {
77 return jit::is_aligned<AlignImpl>(frontier, alignment);
80 void align(CodeBlock& cb, CGMeta* meta,
81 Alignment alignment, AlignContext context) {
82 return jit::align<AlignImpl>(cb, meta, alignment, context);
85 ///////////////////////////////////////////////////////////////////////////////
87 }}}