From: Eunki, Hong Date: Thu, 8 May 2025 03:19:25 +0000 (+0900) Subject: Make HashUtil function as inline X-Git-Tag: accepted/tizen/unified/20250515.075542~1^2~6 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8fdf5cf4031651d7c34a2df79d0d2ce518fcc171;p=platform%2Fcore%2Fuifw%2Fdali-core.git Make HashUtil function as inline Let we make hashutil functions as inline instead of cpp. Seperate it as cpp if we prepare to implement as NEON. Change-Id: I6c6c8eae8e3b7d0407bceef5b675c5410b33768f Signed-off-by: Eunki, Hong --- diff --git a/dali/internal/common/hash-utils.cpp b/dali/internal/common/hash-utils.cpp deleted file mode 100644 index 3fdce90d5..000000000 --- a/dali/internal/common/hash-utils.cpp +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright (c) 2025 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -// CLASS HEADERS -#include - -// EXTERNAL INCLUDES -#include // uint8_t - -namespace Dali::Internal::HashUtils -{ -HashType HashRawByteBufferMultipleComponent(const uint8_t* __restrict__ buffer, std::size_t bufferSize, HashType& hash) -{ - // TODO : use ARM_NEON here in future - static constexpr HashType SCALE_LEVEL_1 = Dali::Power<33, 1>::value; - static constexpr HashType SCALE_LEVEL_2 = Dali::Power<33, 2>::value; - static constexpr HashType SCALE_LEVEL_3 = Dali::Power<33, 3>::value; - static constexpr HashType SCALE_LEVEL_4 = Dali::Power<33, 4>::value; - static constexpr HashType SCALE_LEVEL_5 = Dali::Power<33, 5>::value; - static constexpr HashType SCALE_LEVEL_6 = Dali::Power<33, 6>::value; - static constexpr HashType SCALE_LEVEL_7 = Dali::Power<33, 7>::value; - static constexpr HashType SCALE_LEVEL_8 = Dali::Power<33, 8>::value; - - while(bufferSize & (~0x7)) // bufferSize >= 8 - { - // clang-format off - hash = hash * SCALE_LEVEL_8 + - *(buffer + 0) * SCALE_LEVEL_7 + - *(buffer + 1) * SCALE_LEVEL_6 + - *(buffer + 2) * SCALE_LEVEL_5 + - *(buffer + 3) * SCALE_LEVEL_4 + - *(buffer + 4) * SCALE_LEVEL_3 + - *(buffer + 5) * SCALE_LEVEL_2 + - *(buffer + 6) * SCALE_LEVEL_1 + - *(buffer + 7); - // clang-format on - buffer += 8; - bufferSize -= 8; - } - - if(bufferSize & 0x4) // bufferSize >= 4. Note that 0 <= bufferSize < 8 in here. - { - // clang-format off - hash = hash * SCALE_LEVEL_4 + - *(buffer + 0) * SCALE_LEVEL_3 + - *(buffer + 1) * SCALE_LEVEL_2 + - *(buffer + 2) * SCALE_LEVEL_1 + - *(buffer + 3); - // clang-format on - buffer += 4; - bufferSize &= 0x3; - } - - // Now bufferSize is 0, 1, 2, 3. We can optimize here by switch-case - switch(bufferSize) - { - case 3: - { - hash = hash * 33 + *(buffer++); - DALI_FALLTHROUGH; - } - case 2: - { - hash = hash * 33 + *(buffer++); - DALI_FALLTHROUGH; - } - case 1: - { - hash = hash * 33 + *(buffer++); - DALI_FALLTHROUGH; - } - case 0: - default: - { - break; - } - } - - return hash; -} - -} // namespace Dali::Internal::HashUtils diff --git a/dali/internal/common/hash-utils.h b/dali/internal/common/hash-utils.h index 5fe123390..c911d7abb 100644 --- a/dali/internal/common/hash-utils.h +++ b/dali/internal/common/hash-utils.h @@ -70,7 +70,75 @@ constexpr HashType INITIAL_HASH_VALUE = 5381; } // Hash functions with specified length, which we could optimize for -[[maybe_unused]] HashType HashRawByteBufferMultipleComponent(const uint8_t* __restrict__ buffer, std::size_t bufferSize, HashType& hash); +[[maybe_unused]] inline HashType HashRawByteBufferMultipleComponent(const uint8_t* __restrict__ buffer, std::size_t bufferSize, HashType& hash) +{ + // TODO : use ARM_NEON here in future + static constexpr HashType SCALE_LEVEL_1 = Dali::Power<33, 1>::value; + static constexpr HashType SCALE_LEVEL_2 = Dali::Power<33, 2>::value; + static constexpr HashType SCALE_LEVEL_3 = Dali::Power<33, 3>::value; + static constexpr HashType SCALE_LEVEL_4 = Dali::Power<33, 4>::value; + static constexpr HashType SCALE_LEVEL_5 = Dali::Power<33, 5>::value; + static constexpr HashType SCALE_LEVEL_6 = Dali::Power<33, 6>::value; + static constexpr HashType SCALE_LEVEL_7 = Dali::Power<33, 7>::value; + static constexpr HashType SCALE_LEVEL_8 = Dali::Power<33, 8>::value; + + while(bufferSize & (~0x7)) // bufferSize >= 8 + { + // clang-format off + hash = hash * SCALE_LEVEL_8 + + *(buffer + 0) * SCALE_LEVEL_7 + + *(buffer + 1) * SCALE_LEVEL_6 + + *(buffer + 2) * SCALE_LEVEL_5 + + *(buffer + 3) * SCALE_LEVEL_4 + + *(buffer + 4) * SCALE_LEVEL_3 + + *(buffer + 5) * SCALE_LEVEL_2 + + *(buffer + 6) * SCALE_LEVEL_1 + + *(buffer + 7); + // clang-format on + buffer += 8; + bufferSize -= 8; + } + + if(bufferSize & 0x4) // bufferSize >= 4. Note that 0 <= bufferSize < 8 in here. + { + // clang-format off + hash = hash * SCALE_LEVEL_4 + + *(buffer + 0) * SCALE_LEVEL_3 + + *(buffer + 1) * SCALE_LEVEL_2 + + *(buffer + 2) * SCALE_LEVEL_1 + + *(buffer + 3); + // clang-format on + buffer += 4; + bufferSize &= 0x3; + } + + // Now bufferSize is 0, 1, 2, 3. We can optimize here by switch-case + switch(bufferSize) + { + case 3: + { + hash = hash * 33 + *(buffer++); + DALI_FALLTHROUGH; + } + case 2: + { + hash = hash * 33 + *(buffer++); + DALI_FALLTHROUGH; + } + case 1: + { + hash = hash * 33 + *(buffer++); + DALI_FALLTHROUGH; + } + case 0: + default: + { + break; + } + } + + return hash; +} [[maybe_unused]] inline HashType HashRawByteBuffer(const uint8_t* __restrict__ buffer, std::size_t bufferSize, HashType& hash) { diff --git a/dali/internal/file.list b/dali/internal/file.list index 63f3a5e95..e8956ec52 100644 --- a/dali/internal/file.list +++ b/dali/internal/file.list @@ -6,7 +6,6 @@ SET( internal_src_files ${internal_src_dir}/common/blending-options.cpp ${internal_src_dir}/common/core-impl.cpp ${internal_src_dir}/common/dummy-memory-pool.cpp - ${internal_src_dir}/common/hash-utils.cpp ${internal_src_dir}/common/math.cpp ${internal_src_dir}/common/matrix-utils.cpp ${internal_src_dir}/common/message-buffer.cpp