[SM91] Update to Spidermonkey 91.1.3 APIs
[0ad.git] / libraries / source / spidermonkey / include-win32-debug / js / ScalarType.h
blobd60fa9d8d88121279530a599d9773f750f894cb3
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: set ts=8 sts=2 et sw=2 tw=80:
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 /* An enumeration of all possible element types in typed data. */
9 #ifndef js_ScalarType_h
10 #define js_ScalarType_h
12 #include "mozilla/Assertions.h" // MOZ_CRASH
14 #include <stddef.h> // size_t
16 namespace js {
18 namespace Scalar {
20 // Scalar types that can appear in typed arrays.
21 // The enum values must be kept in sync with:
22 // * the TYPEDARRAY_KIND constants
23 // * the SCTAG_TYPED_ARRAY constants
24 // * JS_FOR_EACH_TYPEDARRAY
25 // * JS_FOR_PROTOTYPES_
26 // * JS_FOR_EACH_UNIQUE_SCALAR_TYPE_REPR_CTYPE
27 // * JIT compilation
28 enum Type {
29 Int8 = 0,
30 Uint8,
31 Int16,
32 Uint16,
33 Int32,
34 Uint32,
35 Float32,
36 Float64,
38 /**
39 * Special type that is a uint8_t, but assignments are clamped to [0, 256).
40 * Treat the raw data type as a uint8_t.
42 Uint8Clamped,
44 BigInt64,
45 BigUint64,
47 /**
48 * Types that don't have their own TypedArray equivalent, for now.
50 MaxTypedArrayViewType,
52 Int64,
53 Simd128,
56 static inline size_t byteSize(Type atype) {
57 switch (atype) {
58 case Int8:
59 case Uint8:
60 case Uint8Clamped:
61 return 1;
62 case Int16:
63 case Uint16:
64 return 2;
65 case Int32:
66 case Uint32:
67 case Float32:
68 return 4;
69 case Int64:
70 case Float64:
71 case BigInt64:
72 case BigUint64:
73 return 8;
74 case Simd128:
75 return 16;
76 case MaxTypedArrayViewType:
77 break;
79 MOZ_CRASH("invalid scalar type");
82 static inline bool isSignedIntType(Type atype) {
83 switch (atype) {
84 case Int8:
85 case Int16:
86 case Int32:
87 case Int64:
88 case BigInt64:
89 return true;
90 case Uint8:
91 case Uint8Clamped:
92 case Uint16:
93 case Uint32:
94 case Float32:
95 case Float64:
96 case BigUint64:
97 case Simd128:
98 return false;
99 case MaxTypedArrayViewType:
100 break;
102 MOZ_CRASH("invalid scalar type");
105 static inline bool isBigIntType(Type atype) {
106 switch (atype) {
107 case BigInt64:
108 case BigUint64:
109 return true;
110 case Int8:
111 case Int16:
112 case Int32:
113 case Int64:
114 case Uint8:
115 case Uint8Clamped:
116 case Uint16:
117 case Uint32:
118 case Float32:
119 case Float64:
120 case Simd128:
121 return false;
122 case MaxTypedArrayViewType:
123 break;
125 MOZ_CRASH("invalid scalar type");
128 static inline const char* name(Type atype) {
129 switch (atype) {
130 case Int8:
131 return "Int8";
132 case Uint8:
133 return "Uint8";
134 case Int16:
135 return "Int16";
136 case Uint16:
137 return "Uint16";
138 case Int32:
139 return "Int32";
140 case Uint32:
141 return "Uint32";
142 case Float32:
143 return "Float32";
144 case Float64:
145 return "Float64";
146 case Uint8Clamped:
147 return "Uint8Clamped";
148 case BigInt64:
149 return "BigInt64";
150 case BigUint64:
151 return "BigUint64";
152 case MaxTypedArrayViewType:
153 return "MaxTypedArrayViewType";
154 case Int64:
155 return "Int64";
156 case Simd128:
157 return "Simd128";
159 MOZ_CRASH("invalid scalar type");
162 static inline const char* byteSizeString(Type atype) {
163 switch (atype) {
164 case Int8:
165 case Uint8:
166 case Uint8Clamped:
167 return "1";
168 case Int16:
169 case Uint16:
170 return "2";
171 case Int32:
172 case Uint32:
173 case Float32:
174 return "4";
175 case Int64:
176 case Float64:
177 case BigInt64:
178 case BigUint64:
179 return "8";
180 case Simd128:
181 return "16";
182 case MaxTypedArrayViewType:
183 break;
185 MOZ_CRASH("invalid scalar type");
188 } // namespace Scalar
190 } // namespace js
192 #endif // js_ScalarType_h