1 | /* |
2 | * Copyright (C) 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 | #if ENABLE(B3_JIT) |
29 | |
30 | #include "B3Bank.h" |
31 | #include "B3Type.h" |
32 | |
33 | #if ASSERT_DISABLED |
34 | IGNORE_RETURN_TYPE_WARNINGS_BEGIN |
35 | #endif |
36 | |
37 | namespace JSC { namespace B3 { |
38 | |
39 | enum Width : int8_t { |
40 | Width8, |
41 | Width16, |
42 | Width32, |
43 | Width64 |
44 | }; |
45 | |
46 | inline Width pointerWidth() |
47 | { |
48 | if (sizeof(void*) == 8) |
49 | return Width64; |
50 | return Width32; |
51 | } |
52 | |
53 | // Don't use this unless the compiler forces you to. |
54 | #if CPU(X86_64) || CPU(ARM64) |
55 | #define POINTER_WIDTH Width64 |
56 | #else |
57 | #define POINTER_WIDTH Width32 |
58 | #endif |
59 | |
60 | inline Width widthForType(Type type) |
61 | { |
62 | switch (type.kind()) { |
63 | case Void: |
64 | case Tuple: |
65 | ASSERT_NOT_REACHED(); |
66 | return Width8; |
67 | case Int32: |
68 | case Float: |
69 | return Width32; |
70 | case Int64: |
71 | case Double: |
72 | return Width64; |
73 | } |
74 | ASSERT_NOT_REACHED(); |
75 | return Width8; |
76 | } |
77 | |
78 | inline Width canonicalWidth(Width width) |
79 | { |
80 | return std::max(Width32, width); |
81 | } |
82 | |
83 | inline bool isCanonicalWidth(Width width) |
84 | { |
85 | return width >= Width32; |
86 | } |
87 | |
88 | Type bestType(Bank bank, Width width); |
89 | |
90 | inline Width conservativeWidth(Bank bank) |
91 | { |
92 | return bank == GP ? pointerWidth() : Width64; |
93 | } |
94 | |
95 | inline Width minimumWidth(Bank bank) |
96 | { |
97 | return bank == GP ? Width8 : Width32; |
98 | } |
99 | |
100 | inline unsigned bytes(Width width) |
101 | { |
102 | return 1 << width; |
103 | } |
104 | |
105 | inline Width widthForBytes(unsigned bytes) |
106 | { |
107 | switch (bytes) { |
108 | case 0: |
109 | case 1: |
110 | return Width8; |
111 | case 2: |
112 | return Width16; |
113 | case 3: |
114 | case 4: |
115 | return Width32; |
116 | default: |
117 | return Width64; |
118 | } |
119 | } |
120 | |
121 | inline uint64_t mask(Width width) |
122 | { |
123 | switch (width) { |
124 | case Width8: |
125 | return 0x00000000000000ffllu; |
126 | case Width16: |
127 | return 0x000000000000ffffllu; |
128 | case Width32: |
129 | return 0x00000000ffffffffllu; |
130 | case Width64: |
131 | return 0xffffffffffffffffllu; |
132 | } |
133 | ASSERT_NOT_REACHED(); |
134 | } |
135 | |
136 | } } // namespace JSC::B3 |
137 | |
138 | namespace WTF { |
139 | |
140 | class PrintStream; |
141 | |
142 | void printInternal(PrintStream&, JSC::B3::Width); |
143 | |
144 | } // namespace WTF |
145 | |
146 | #if ASSERT_DISABLED |
147 | IGNORE_RETURN_TYPE_WARNINGS_END |
148 | #endif |
149 | |
150 | #endif // ENABLE(B3_JIT) |
151 | |
152 | |