summaryrefslogtreecommitdiffstats
path: root/js/src/jit/arm64/Architecture-arm64.cpp
blob: eb3dd67b1a9b81165dcb8e37a202ae9dd47d9e94 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
 * vim: set ts=8 sts=2 et sw=2 tw=80:
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "jit/arm64/Architecture-arm64.h"

#include <cstring>

#include "jit/arm64/vixl/Cpu-vixl.h"
#include "jit/FlushICache.h"  // js::jit::FlushICache
#include "jit/RegisterSets.h"

namespace js {
namespace jit {

Registers::Code Registers::FromName(const char* name) {
  // Check for some register aliases first.
  if (strcmp(name, "ip0") == 0) {
    return ip0;
  }
  if (strcmp(name, "ip1") == 0) {
    return ip1;
  }
  if (strcmp(name, "fp") == 0) {
    return fp;
  }

  for (uint32_t i = 0; i < Total; i++) {
    if (strcmp(GetName(i), name) == 0) {
      return Code(i);
    }
  }

  return Invalid;
}

FloatRegisters::Code FloatRegisters::FromName(const char* name) {
  for (size_t i = 0; i < Total; i++) {
    if (strcmp(GetName(i), name) == 0) {
      return Code(i);
    }
  }

  return Invalid;
}

// This must sync with GetPushSizeInBytes just below and also with
// MacroAssembler::PushRegsInMask.
FloatRegisterSet FloatRegister::ReduceSetForPush(const FloatRegisterSet& s) {
  SetType all = s.bits();
  SetType set128b =
      (all & FloatRegisters::AllSimd128Mask) >> FloatRegisters::ShiftSimd128;
  SetType doubleSet =
      (all & FloatRegisters::AllDoubleMask) >> FloatRegisters::ShiftDouble;
  SetType singleSet =
      (all & FloatRegisters::AllSingleMask) >> FloatRegisters::ShiftSingle;

  // See GetPushSizeInBytes.
  SetType set64b = (singleSet | doubleSet) & ~set128b;

  SetType reduced = (set128b << FloatRegisters::ShiftSimd128) |
                    (set64b << FloatRegisters::ShiftDouble);
  return FloatRegisterSet(reduced);
}

// Compute the size of the dump area for |s.ReduceSetForPush()|, as defined by
// MacroAssembler::PushRegsInMask for this target.
uint32_t FloatRegister::GetPushSizeInBytes(const FloatRegisterSet& s) {
  SetType all = s.bits();
  SetType set128b =
      (all & FloatRegisters::AllSimd128Mask) >> FloatRegisters::ShiftSimd128;
  SetType doubleSet =
      (all & FloatRegisters::AllDoubleMask) >> FloatRegisters::ShiftDouble;
  SetType singleSet =
      (all & FloatRegisters::AllSingleMask) >> FloatRegisters::ShiftSingle;

  // PushRegsInMask pushes singles as if they were doubles.  Also we need to
  // remove singles or doubles which are also pushed as part of a vector
  // register.
  SetType set64b = (singleSet | doubleSet) & ~set128b;

  // The "+ 1) & ~1" is to take into account the alignment hole below the
  // double-reg dump area.  See MacroAssembler::PushRegsInMaskSizeInBytes.
  return ((set64b.size() + 1) & ~1) * sizeof(double) +
         set128b.size() * SizeOfSimd128;
}

uint32_t FloatRegister::getRegisterDumpOffsetInBytes() {
  // See block comment in MacroAssembler.h for further required invariants.
  static_assert(sizeof(jit::FloatRegisters::RegisterContent) == 16);
  return encoding() * sizeof(jit::FloatRegisters::RegisterContent);
}

// For N in 0..31, if any of sN, dN or qN is a member of `s`, the returned set
// will contain all of sN, dN and qN.
FloatRegisterSet FloatRegister::BroadcastToAllSizes(const FloatRegisterSet& s) {
  SetType all = s.bits();
  SetType set128b =
      (all & FloatRegisters::AllSimd128Mask) >> FloatRegisters::ShiftSimd128;
  SetType doubleSet =
      (all & FloatRegisters::AllDoubleMask) >> FloatRegisters::ShiftDouble;
  SetType singleSet =
      (all & FloatRegisters::AllSingleMask) >> FloatRegisters::ShiftSingle;

  SetType merged = set128b | doubleSet | singleSet;
  SetType broadcasted = (merged << FloatRegisters::ShiftSimd128) |
                        (merged << FloatRegisters::ShiftDouble) |
                        (merged << FloatRegisters::ShiftSingle);

  return FloatRegisterSet(broadcasted);
}

uint32_t GetARM64Flags() { return 0; }

// CPU flags handling on ARM64 is currently different from other platforms:
// the flags are computed and stored per-assembler and are thus "always
// computed".
bool CPUFlagsHaveBeenComputed() { return true; }

void FlushICache(void* code, size_t size) {
  vixl::CPU::EnsureIAndDCacheCoherency(code, size);
}

void FlushExecutionContext() { vixl::CPU::FlushExecutionContext(); }

}  // namespace jit
}  // namespace js