Skip to content

Commit

Permalink
remove array util inline
Browse files Browse the repository at this point in the history
  • Loading branch information
chaokunyang committed Jan 15, 2025
1 parent 4793946 commit 8ba4b1b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
28 changes: 28 additions & 0 deletions cpp/fury/util/array_util.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/

#pragma once
#include "fury/util/platform.h"
#include <cstdint>

namespace fury {
uint16_t getMaxValue(const uint16_t *arr, size_t length);

void copyArray(const uint16_t *from, uint8_t *to, size_t length);
} // namespace fury
12 changes: 6 additions & 6 deletions cpp/fury/util/array_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

namespace fury {
#if defined(FURY_HAS_NEON)
inline uint16_t getMaxValue(const uint16_t *arr, size_t length) {
uint16_t getMaxValue(const uint16_t *arr, size_t length) {
if (length == 0) {
return 0; // Return 0 for empty arrays
}
Expand Down Expand Up @@ -54,7 +54,7 @@ inline uint16_t getMaxValue(const uint16_t *arr, size_t length) {
return max_neon;
}

inline void copyArray(const uint16_t *from, uint8_t *to, size_t length) {
void copyArray(const uint16_t *from, uint8_t *to, size_t length) {
size_t i = 0;
for (; i + 7 < length; i += 8) {
uint16x8_t src = vld1q_u16(&from[i]);
Expand All @@ -68,7 +68,7 @@ inline void copyArray(const uint16_t *from, uint8_t *to, size_t length) {
}
}
#elif defined(FURY_HAS_SSE2)
inline uint16_t getMaxValue(const uint16_t *arr, size_t length) {
uint16_t getMaxValue(const uint16_t *arr, size_t length) {
if (length == 0) {
return 0; // Return 0 for empty arrays
}
Expand Down Expand Up @@ -100,7 +100,7 @@ inline uint16_t getMaxValue(const uint16_t *arr, size_t length) {
return max_sse;
}

inline void copyArray(const uint16_t *from, uint8_t *to, size_t length) {
void copyArray(const uint16_t *from, uint8_t *to, size_t length) {
size_t i = 0;
__m128i mask = _mm_set1_epi16(0xFF); // Mask to zero out the high byte
for (; i + 7 < length; i += 8) {
Expand All @@ -116,7 +116,7 @@ inline void copyArray(const uint16_t *from, uint8_t *to, size_t length) {
}
}
#else
inline uint16_t getMaxValue(const uint16_t *arr, size_t length) {
uint16_t getMaxValue(const uint16_t *arr, size_t length) {
if (length == 0) {
return 0; // Return 0 for empty arrays
}
Expand All @@ -129,7 +129,7 @@ inline uint16_t getMaxValue(const uint16_t *arr, size_t length) {
return max_val;
}

inline void copyArray(const uint16_t *from, uint8_t *to, size_t length) {
void copyArray(const uint16_t *from, uint8_t *to, size_t length) {
// Fallback for systems without SSE2/NEON
for (size_t i = 0; i < length; ++i) {
to[i] = static_cast<uint8_t>(from[i]);
Expand Down

0 comments on commit 8ba4b1b

Please sign in to comment.