commit 705c7570d315225246806ab188b5a965c0866a53 Author: cfif Date: Fri Jan 24 13:22:33 2025 +0300 Перенос на новую организацию GONEC diff --git a/fastfunc.h b/fastfunc.h new file mode 100644 index 0000000..05bafaf --- /dev/null +++ b/fastfunc.h @@ -0,0 +1,14 @@ +// +// Created by cfif on 08.06.23. +// + +#ifndef FASTFUNC_H +#define FASTFUNC_H + +#include + +void *memcpy_fast(void *dst0, const void *src0, size_t len0); +void *memmove_fast(void *dst_void, const void *src_void, size_t length); +void memcpy32 (void* dest, const void* src, size_t size); + +#endif //FASTFUNC_H diff --git a/memcpy-fast.c b/memcpy-fast.c new file mode 100755 index 0000000..68096fa --- /dev/null +++ b/memcpy-fast.c @@ -0,0 +1,94 @@ +/* +FUNCTION + <>---copy memory regions + +ANSI_SYNOPSIS + #include + void* memcpy(void *<[out]>, const void *<[in]>, size_t <[n]>); + +TRAD_SYNOPSIS + void *memcpy(<[out]>, <[in]>, <[n]> + void *<[out]>; + void *<[in]>; + size_t <[n]>; + +DESCRIPTION + This function copies <[n]> bytes from the memory region + pointed to by <[in]> to the memory region pointed to by + <[out]>. + + If the regions overlap, the behavior is undefined. + +RETURNS + <> returns a pointer to the first byte of the <[out]> + region. + +PORTABILITY +<> is ANSI C. + +<> requires no supporting OS subroutines. + +QUICKREF + memcpy ansi pure + */ + +#include + +#undef memcpy + +/* Nonzero if either X or Y is not aligned on a "long" boundary. */ +#define UNALIGNED(X, Y) \ + (((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1))) + +/* How many bytes are copied each iteration of the 4X unrolled loop. */ +#define BIGBLOCKSIZE (sizeof (long) << 2) + +/* How many bytes are copied each iteration of the word copy loop. */ +#define LITTLEBLOCKSIZE (sizeof (long)) + +/* Threshhold for punting to the byte copier. */ +#define TOO_SMALL(LEN) ((LEN) < BIGBLOCKSIZE) + +void * +memcpy_fast(void *dst0, const void *src0, size_t len0) +{ + unsigned char *dst = dst0; + const unsigned char *src = src0; + long *aligned_dst; + const long *aligned_src; + int len = len0; + + /* If the size is small, or either SRC or DST is unaligned, + then punt into the byte copy loop. This should be rare. */ + if (!TOO_SMALL(len) && !UNALIGNED (src, dst)) + { + aligned_dst = (long*)dst; + aligned_src = (long*)src; + + /* Copy 4X long words at a time if possible. */ + while (len >= BIGBLOCKSIZE) + { + *aligned_dst++ = *aligned_src++; + *aligned_dst++ = *aligned_src++; + *aligned_dst++ = *aligned_src++; + *aligned_dst++ = *aligned_src++; + len -= BIGBLOCKSIZE; + } + + /* Copy one long word at a time if possible. */ + while (len >= LITTLEBLOCKSIZE) + { + *aligned_dst++ = *aligned_src++; + len -= LITTLEBLOCKSIZE; + } + + /* Pick up any residual with a byte copier. */ + dst = (unsigned char*)aligned_dst; + src = (unsigned char*)aligned_src; + } + + while (len--) + *dst++ = *src++; + + return dst0; +} diff --git a/memcpy32.s b/memcpy32.s new file mode 100644 index 0000000..6687e30 --- /dev/null +++ b/memcpy32.s @@ -0,0 +1,50 @@ +.syntax unified +.cpu cortex-m4 +.fpu softvfp +.thumb + + +.global memcpy32 +.type memcpy32, %function + + +memcpy32: +push {r4, r5, r6, r7, r8, r9, r10, r11} + +bics r11, r2, #31 +beq 2f +add r11, r0 + +1: ldmia r1!, { r3, r4, r5, r6, r7, r8, r9, r10 } +stmia r0!, { r3, r4, r5, r6, r7, r8, r9, r10 } +cmp r0, r11 +bne 1b +2: + +tst r2, #16 +itt NE +ldmiane r1!, { r3, r4, r5, r6 } +stmiane r0!, { r3, r4, r5, r6 } + +tst r2, #8 +itt NE +ldrdne r3, r4, [r1], #+8 +strdne r3, r4, [r0], #+8 + +tst r2, #4 +itt NE +ldrne r3, [r1], #+4 +strne r3, [r0], #+4 + +tst r2, #2 +itt NE +ldrhne r3, [r1], #+2 +strhne r3, [r0], #+2 + +tst r2, #1 +itt NE +ldrbne r3, [r1], #+1 +strbne r3, [r0], #+1 + +pop {r4, r5, r6, r7, r8, r9, r10, r11} +bx lr \ No newline at end of file diff --git a/memmove-fast.c b/memmove-fast.c new file mode 100755 index 0000000..d0b81e1 --- /dev/null +++ b/memmove-fast.c @@ -0,0 +1,112 @@ +/* +FUNCTION + <>---move possibly overlapping memory + +INDEX + memmove + +ANSI_SYNOPSIS + #include + void *memmove(void *<[dst]>, const void *<[src]>, size_t <[length]>); + +TRAD_SYNOPSIS + #include + void *memmove(<[dst]>, <[src]>, <[length]>) + void *<[dst]>; + void *<[src]>; + size_t <[length]>; + +DESCRIPTION + This function moves <[length]> characters from the block of + memory starting at <<*<[src]>>> to the memory starting at + <<*<[dst]>>>. <> reproduces the characters correctly + at <<*<[dst]>>> even if the two areas overlap. + + +RETURNS + The function returns <[dst]> as passed. + +PORTABILITY +<> is ANSI C. + +<> requires no supporting OS subroutines. + +QUICKREF + memmove ansi pure +*/ +#include + +#undef memmove + +/* Nonzero if either X or Y is not aligned on a "long" boundary. */ +#define UNALIGNED(X, Y) \ + (((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1))) + +/* How many bytes are copied each iteration of the 4X unrolled loop. */ +#define BIGBLOCKSIZE (sizeof (long) << 2) + +/* How many bytes are copied each iteration of the word copy loop. */ +#define LITTLEBLOCKSIZE (sizeof (long)) + +/* Threshhold for punting to the byte copier. */ +#define TOO_SMALL(LEN) ((LEN) < BIGBLOCKSIZE) + +void * +memmove_fast(void *dst_void, const void *src_void, size_t length) +{ + unsigned char *dst = dst_void; + const unsigned char *src = src_void; + long *aligned_dst; + const long *aligned_src; + int len = length; + + if (src < dst && dst < src + len) + { + /* Destructive overlap...have to copy backwards */ + src += len; + dst += len; + while (len--) + { + *--dst = *--src; + } + } + else + { + /* Use optimizing algorithm for a non-destructive copy to closely + match memcpy. If the size is small or either SRC or DST is unaligned, + then punt into the byte copy loop. This should be rare. */ + if (!TOO_SMALL(len) && !UNALIGNED (src, dst)) + { + aligned_dst = (long*)dst; + aligned_src = (long*)src; + + /* Copy 4X long words at a time if possible. */ + while (len >= BIGBLOCKSIZE) + { + *aligned_dst++ = *aligned_src++; + *aligned_dst++ = *aligned_src++; + *aligned_dst++ = *aligned_src++; + *aligned_dst++ = *aligned_src++; + len -= BIGBLOCKSIZE; + } + + /* Copy one long word at a time if possible. */ + while (len >= LITTLEBLOCKSIZE) + { + *aligned_dst++ = *aligned_src++; + len -= LITTLEBLOCKSIZE; + } + + /* Pick up any residual with a byte copier. */ + dst = (unsigned char*)aligned_dst; + src = (unsigned char*)aligned_src; + } + + while (len--) + { + *dst++ = *src++; + } + } + + return dst_void; +} diff --git a/modular.json b/modular.json new file mode 100644 index 0000000..82bec95 --- /dev/null +++ b/modular.json @@ -0,0 +1,11 @@ +{ + "cmake": { + "inc_dirs": [ + "./" + ], + "srcs": [ + "./**.c", + "**.s" + ] + } +} \ No newline at end of file