Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Thumb2 optimized string routines for performance and/or size #58

Open
jserv opened this issue Jul 16, 2018 · 0 comments
Open

Thumb2 optimized string routines for performance and/or size #58

jserv opened this issue Jul 16, 2018 · 0 comments
Assignees

Comments

@jserv
Copy link
Member

jserv commented Jul 16, 2018

Piko/RT depends on several string routines such as memcpy and memset. They can be optimized in Thumb2 assembly in consideration of performance and/or size.

Sample implementation for memcpy:

static inline void memcpy(void *restrict dst, const void *restrict src, size_t l)
{
    __asm__ volatile(" \
        mov r1, %2; \
        mov r3, %1; \
        mov r4, %0; \
        orr r2, r3, r4; \
        ands r2, #3; \
        bne 2f; \
1: \
    cmp r1, #4; \
    ittt hs; \
    ldrhs r2, [r3], #4; \
    strhs r2, [r4], #4; \
    subshs r1, #4; \
    bhs 1b; \
2: \
    cmp r1, #0; \
    ittt ne; \
    ldrbne r2, [r3], #1; \
    strbne r2, [r4], #1; \
    subsne r1, #1; \
    bne 2b"
    :
    : "r" (dst), "r" (src), "r" (l)
    : "r1", "r2", "r3", "r4", "memory", "cc");
}

Sample implementation for memcpy:

static inline void memset(void *dst, int v, size_t l)
{
    __asm__ volatile(" \
        mov r1, %2; \
        mov r3, %1; \
        orr r3, r3, r3, lsl #8; \
        orr r3, r3, r3, lsl #16; \
        mov r4, %0; \
        ands r2, r4, #3; \
        bne 2f; \
1: \
        cmp r1, #4; \
        itt hs; \
        strhs r3, [r4], #4; \
        subshs r1, #4; \
        bhs 1b; \
2: \
        cmp r1, #0; \
        itt ne; \
        strbne r3, [r4], #1; \
        subsne r1, #1; \
        bne 2b"
    :
    : "r" (dst), "r" (v & 0xff), "r" (l)
    : "r1", "r2", "r3", "r4", "memory", "cc");
}
@jserv jserv self-assigned this Jul 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant