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 #ifndef jit_ScalarTypeUtils_h
8 #define jit_ScalarTypeUtils_h
10 #include "mozilla/CheckedInt.h"
14 #include "js/ScalarType.h"
19 // Compute |index * Scalar::byteSize(type) + offsetAdjustment|. If this doesn't
20 // overflow and is non-negative, return true and store the result in *offset.
21 // If the computation overflows or the result is negative, false is returned and
22 // *offset is left unchanged.
23 [[nodiscard
]] inline bool ArrayOffsetFitsInInt32(int32_t index
,
25 int32_t offsetAdjustment
,
27 mozilla::CheckedInt
<int32_t> val
= index
;
28 val
*= Scalar::byteSize(type
);
29 val
+= offsetAdjustment
;
30 if (!val
.isValid() || val
.value() < 0) {
34 *offset
= val
.value();
41 #endif /* jit_ScalarTypeUtils_h */