Make HashUtil function as inline 42/323842/5
authorEunki, Hong <eunkiki.hong@samsung.com>
Thu, 8 May 2025 03:19:25 +0000 (12:19 +0900)
committerEunki Hong <eunkiki.hong@samsung.com>
Fri, 9 May 2025 03:08:10 +0000 (03:08 +0000)
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 <eunkiki.hong@samsung.com>
dali/internal/common/hash-utils.cpp [deleted file]
dali/internal/common/hash-utils.h
dali/internal/file.list

diff --git a/dali/internal/common/hash-utils.cpp b/dali/internal/common/hash-utils.cpp
deleted file mode 100644 (file)
index 3fdce90..0000000
+++ /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 <dali/internal/common/hash-utils.h>
-
-// EXTERNAL INCLUDES
-#include <cstdint> // 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
index 5fe123390f70469c82207a4d417069b5fd14368c..c911d7abb342dada3019427c4d9f8bc6c518320e 100644 (file)
@@ -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)
 {
index 63f3a5e954965d0a9117832cc5d665e038716aa4..e8956ec52d147427e216ad630b95f975135a9dda 100644 (file)
@@ -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