mirror of
https://github.com/google/cpu_features.git
synced 2025-07-01 21:31:15 +02:00
Fix #205
Since buffers are a few tens of bytes there is no need for optimized memfunctions. For compile time sizes, the compiler will generate optimal code already.
This commit is contained in:
16
src/copy.inl
16
src/copy.inl
@ -13,21 +13,7 @@
|
||||
// limitations under the License.
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
static void copy(char *__restrict dst, const char *src, size_t count) {
|
||||
size_t offset = 0;
|
||||
|
||||
#define CHUNK_COPY(TYPE) \
|
||||
while (count - offset >= sizeof(TYPE)) { \
|
||||
*(TYPE *)(dst + offset) = *(const TYPE *)(src + offset); \
|
||||
offset += sizeof(TYPE); \
|
||||
}
|
||||
|
||||
CHUNK_COPY(uint64_t)
|
||||
CHUNK_COPY(uint32_t)
|
||||
CHUNK_COPY(uint16_t)
|
||||
CHUNK_COPY(uint8_t)
|
||||
|
||||
#undef CHUNK_COPY
|
||||
for (size_t i = 0; i < count; ++i) dst[i] = src[i];
|
||||
}
|
||||
|
@ -14,24 +14,9 @@
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
static bool equals(const char *lhs, const char *rhs, size_t count) {
|
||||
size_t offset = 0;
|
||||
|
||||
#define CHUNK_EQUALS(TYPE) \
|
||||
while (count - offset >= sizeof(TYPE)) { \
|
||||
TYPE l = *(const TYPE *)(lhs + offset); \
|
||||
TYPE r = *(const TYPE *)(rhs + offset); \
|
||||
if (l != r) return false; \
|
||||
offset += sizeof(TYPE); \
|
||||
}
|
||||
|
||||
CHUNK_EQUALS(uint64_t)
|
||||
CHUNK_EQUALS(uint32_t)
|
||||
CHUNK_EQUALS(uint16_t)
|
||||
CHUNK_EQUALS(uint8_t)
|
||||
#undef CHUNK_EQUALS
|
||||
|
||||
for (size_t i = 0; i < count; ++i)
|
||||
if (lhs[i] != rhs[i]) return false;
|
||||
return true;
|
||||
}
|
||||
|
Reference in New Issue
Block a user