skip optimized memcpy/memset for small builds
This saves 100 bytes on trinket_m0 at the price of making many memset & memcpy calls slower.
This commit is contained in:
parent
016242aa26
commit
cb331309c9
@ -28,6 +28,8 @@
|
|||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "py/mpconfig.h"
|
||||||
|
|
||||||
#ifndef likely
|
#ifndef likely
|
||||||
#define likely(x) __builtin_expect((x), 1)
|
#define likely(x) __builtin_expect((x), 1)
|
||||||
#endif
|
#endif
|
||||||
@ -35,6 +37,7 @@
|
|||||||
#pragma GCC diagnostic push
|
#pragma GCC diagnostic push
|
||||||
#pragma GCC diagnostic ignored "-Wcast-align"
|
#pragma GCC diagnostic ignored "-Wcast-align"
|
||||||
void *memcpy(void *dst, const void *src, size_t n) {
|
void *memcpy(void *dst, const void *src, size_t n) {
|
||||||
|
#if CIRCUITPY_FULL_BUILD
|
||||||
if (likely(!(((uintptr_t)dst) & 3) && !(((uintptr_t)src) & 3))) {
|
if (likely(!(((uintptr_t)dst) & 3) && !(((uintptr_t)src) & 3))) {
|
||||||
// pointers aligned
|
// pointers aligned
|
||||||
uint32_t *d = dst;
|
uint32_t *d = dst;
|
||||||
@ -56,7 +59,9 @@ void *memcpy(void *dst, const void *src, size_t n) {
|
|||||||
// copy byte
|
// copy byte
|
||||||
*((uint8_t*)d) = *((const uint8_t*)s);
|
*((uint8_t*)d) = *((const uint8_t*)s);
|
||||||
}
|
}
|
||||||
} else {
|
} else
|
||||||
|
#endif
|
||||||
|
{
|
||||||
// unaligned access, copy bytes
|
// unaligned access, copy bytes
|
||||||
uint8_t *d = dst;
|
uint8_t *d = dst;
|
||||||
const uint8_t *s = src;
|
const uint8_t *s = src;
|
||||||
@ -93,6 +98,7 @@ void *memmove(void *dest, const void *src, size_t n) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void *memset(void *s, int c, size_t n) {
|
void *memset(void *s, int c, size_t n) {
|
||||||
|
#if CIRCUITPY_FULL_BUILD
|
||||||
if (c == 0 && ((uintptr_t)s & 3) == 0) {
|
if (c == 0 && ((uintptr_t)s & 3) == 0) {
|
||||||
// aligned store of 0
|
// aligned store of 0
|
||||||
uint32_t *s32 = s;
|
uint32_t *s32 = s;
|
||||||
@ -106,7 +112,9 @@ void *memset(void *s, int c, size_t n) {
|
|||||||
if (n & 1) {
|
if (n & 1) {
|
||||||
*((uint8_t*)s32) = 0;
|
*((uint8_t*)s32) = 0;
|
||||||
}
|
}
|
||||||
} else {
|
} else
|
||||||
|
#endif
|
||||||
|
{
|
||||||
uint8_t *s2 = s;
|
uint8_t *s2 = s;
|
||||||
for (; n > 0; n--) {
|
for (; n > 0; n--) {
|
||||||
*s2++ = c;
|
*s2++ = c;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user