1/*
2 * Copyright (C) 2008-2017 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#pragma once
27
28#include "Options.h"
29
30namespace JSC {
31
32#if USE(JSVALUE64)
33using CPURegister = int64_t;
34using UCPURegister = uint64_t;
35#else
36using CPURegister = int32_t;
37using UCPURegister = uint32_t;
38#endif
39
40constexpr bool isARMv7IDIVSupported()
41{
42#if HAVE(ARM_IDIV_INSTRUCTIONS)
43 return true;
44#else
45 return false;
46#endif
47}
48
49constexpr bool isARM64()
50{
51#if CPU(ARM64)
52 return true;
53#else
54 return false;
55#endif
56}
57
58constexpr bool isX86()
59{
60#if CPU(X86_64) || CPU(X86)
61 return true;
62#else
63 return false;
64#endif
65}
66
67constexpr bool isX86_64()
68{
69#if CPU(X86_64)
70 return true;
71#else
72 return false;
73#endif
74}
75
76constexpr bool is64Bit()
77{
78#if USE(JSVALUE64)
79 return true;
80#else
81 return false;
82#endif
83}
84
85constexpr bool is32Bit()
86{
87 return !is64Bit();
88}
89
90constexpr bool isAddress64Bit()
91{
92 return sizeof(void*) == 8;
93}
94
95constexpr bool isAddress32Bit()
96{
97 return !isAddress64Bit();
98}
99
100constexpr bool isMIPS()
101{
102#if CPU(MIPS)
103 return true;
104#else
105 return false;
106#endif
107}
108
109inline bool optimizeForARMv7IDIVSupported()
110{
111 return isARMv7IDIVSupported() && Options::useArchitectureSpecificOptimizations();
112}
113
114inline bool optimizeForARM64()
115{
116 return isARM64() && Options::useArchitectureSpecificOptimizations();
117}
118
119inline bool optimizeForX86()
120{
121 return isX86() && Options::useArchitectureSpecificOptimizations();
122}
123
124inline bool optimizeForX86_64()
125{
126 return isX86_64() && Options::useArchitectureSpecificOptimizations();
127}
128
129inline bool hasSensibleDoubleToInt()
130{
131 return optimizeForX86();
132}
133
134} // namespace JSC
135
136