1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef ECMASCRIPT_MEM_MEM_COMMON_H 17 #define ECMASCRIPT_MEM_MEM_COMMON_H 18 19 #include <cstddef> 20 #include <cstdint> 21 22 namespace panda::ecmascript { 23 /* 24 uint64_t return type usage in memory literals for giving 25 compile-time error in case of integer overflow 26 */ 27 constexpr uint64_t SHIFT_KB = 10ULL; 28 constexpr uint64_t SHIFT_MB = 20ULL; 29 constexpr uint64_t SHIFT_GB = 30ULL; 30 31 constexpr uint64_t operator"" _KB(long double count) 32 { 33 return count * (1ULL << SHIFT_KB); 34 } 35 36 // NOLINTNEXTLINE(google-runtime-int) 37 constexpr uint64_t operator"" _KB(unsigned long long count) 38 { 39 return count * (1ULL << SHIFT_KB); 40 } 41 42 constexpr uint64_t operator"" _MB(long double count) 43 { 44 return count * (1ULL << SHIFT_MB); 45 } 46 47 // NOLINTNEXTLINE(google-runtime-int) 48 constexpr uint64_t operator"" _MB(unsigned long long count) 49 { 50 return count * (1ULL << SHIFT_MB); 51 } 52 53 constexpr uint64_t operator"" _GB(long double count) 54 { 55 return count * (1ULL << SHIFT_GB); 56 } 57 58 // NOLINTNEXTLINE(google-runtime-int) 59 constexpr uint64_t operator"" _GB(unsigned long long count) 60 { 61 return count * (1ULL << SHIFT_GB); 62 } 63 } // namespace panda::ecmascript 64 65 #endif // ECMASCRIPT_MEM_MEM_COMMON_H 66