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

memmove implementation #140

Open
lab313ru opened this issue Mar 25, 2019 · 1 comment
Open

memmove implementation #140

lab313ru opened this issue Mar 25, 2019 · 1 comment

Comments

@lab313ru
Copy link

It would be great to add this function.

@polluks
Copy link

polluks commented Sep 3, 2020

vbcc's implementation

void *memcpy(__reg("a0") void *, __reg("a1") const void *,
             __reg("d2") size_t) =
        "\tinline\n"
        "\tmove.l\ta0,d0\n"
        "\tcmp.l\t#16,d2\n"
        "\tblo\t.l5\n"
        "\tmoveq\t#1,d1\n"
        "\tand.b\td0,d1\n"
        "\tbeq\t.l1\n"
        "\tmove.b\t(a1)+,(a0)+\n"
        "\tsubq.l\t#1,d2\n"
        ".l1\n"
        "\tmove.l\ta1,d1\n"
        "\tand.b\t#1,d1\n"
        "\tbeq\t.l3\n"
        "\tcmp.l\t#$10000,d2\n"
        "\tblo\t.l5\n"
        ".l2\n"
        "\tmove.b\t(a1)+,(a0)+\n"
        "\tsubq.l\t#1,d2\n"
        "\tbne\t.l2\n"
        "\tbra\t.l7\n"
        ".l3\n"
        "\tmoveq\t#3,d1\n"
        "\tand.l\td2,d1\n"
        "\tsub.l\td1,d2\n"
        ".l4\n"
        "\tmove.l\t(a1)+,(a0)+\n"
        "\tsubq.l\t#4,d2\n"
        "\tbne\t.l4\n"
        "\tmove.w\td1,d2\n"
        ".l5\n"
        "\tsubq.w\t#1,d2\n"
        "\tblo\t.l7\n"
        ".l6\n"
        "\tmove.b\t(a1)+,(a0)+\n"
        "\tdbf\td2,.l6\n"
        ".l7\n"
        "\teinline";
void *__memcpy_desc(__reg("a0") void *, __reg("a1") const void *,
                    __reg("d2") size_t) =
        "\tinline\n"
        "\tcmp.l\t#16,d2\n"
        "\tblo\t.l5\n"
        "\tmoveq\t#1,d1\n"
        "\tmove.l\ta0,d0\n"
        "\tand.b\td1,d0\n"
        "\tbeq\t.l1\n"
        "\tmove.b\t-(a1),-(a0)\n"
        "\tsubq.l\t#1,d2\n"
        ".l1\n"
        "\tmove.l\ta1,d0\n"
        "\tand.b\td1,d0\n"
        "\tbeq\t.l3\n"
        "\tcmp.l\t#$10000,d2\n"
        "\tblo\t.l5\n"
        ".l2\n"
        "\tmove.b\t-(a1),-(a0)\n"
        "\tsubq.l\t#1,d2\n"
        "\tbne\t.l2\n"
        "\tbra\t.l7\n"
        ".l3\n"
        "\tmoveq\t#3,d1\n"
        "\tand.l\td2,d1\n"
        "\tsub.l\td1,d2\n"
        ".l4\n"
        "\tmove.l\t-(a1),-(a0)\n"
        "\tsubq.l\t#4,d2\n"
        "\tbne\t.l4\n"
        "\tmove.w\td1,d2\n"
        ".l5\n"
        "\tsubq.w\t#1,d2\n"
        "\tblo\t.l7\n"
        ".l6\n"
        "\tmove.b\t-(a1),-(a0)\n"
        "\tdbf\td2,.l6\n"
        ".l7\n"
        "\tmove.l\ta0,d0\n"
        "\teinline";

#define memmove(d,s,n) ((d)<=(s) ? memcpy(d,s,n) : \
                                   __memcpy_desc((char *)(d)+(n),(char *)(s)+(n),n))

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

2 participants