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

Optimisation 02: The operations and the moves #111

Open
shahab-vahedi opened this issue Mar 2, 2023 · 1 comment
Open

Optimisation 02: The operations and the moves #111

shahab-vahedi opened this issue Mar 2, 2023 · 1 comment
Assignees

Comments

@shahab-vahedi
Copy link
Member

shahab-vahedi commented Mar 2, 2023

Having the following code:

long long func(long long m, long long n)
{
  return m * n;
}

results in an assembly like:

$ arc-elf32-gcc -O3 func.c -S -o -
        .file   "func.c"
        .cpu HS
        .arc_attribute Tag_ARC_PCS_config, 2
        .arc_attribute Tag_ARC_ABI_rf16, 0
        .arc_attribute Tag_ARC_ABI_pic, 0
        .arc_attribute Tag_ARC_ABI_tls, 0
        .arc_attribute Tag_ARC_ABI_sda, 2
        .arc_attribute Tag_ARC_ABI_exceptions, 0
        .arc_attribute Tag_ARC_CPU_variation, 2
        .section        .text
        .align 4
        .global func
        .type   func, @function
func:
        std.a r14,[sp,-8]
        mpy_s   r3,r3,r0
        mpy_s   r1,r1,r2
        add_s   r1,r1,r3
        mpymu   r15,r0,r2
        mpy     r14,r0,r2
        add_s   r15,r1,r15
        mov_s   r0,r14
        mov_s   r1,r15
        j_s.d   [blink]
        ldd.ab r14,[sp,8]
        .size   func, .-func
        .ident  "GCC: (ARCompact/ARCv2 ISA elf32 toolchain) 10.2.0"
        .section        .note.GNU-stack,"",@progbits

But there are rooms for improvement:

  mpymu   r15,r0,r2     \
  mpy     r14,r0,r2     |           mpymu   r15,r0,r2
  add_s   r15,r1,r15    |========>  mpy_s   r0,r0,r2
  mov_s   r0,r14        |           add_s   r1,r1,r15
  mov_s   r1,r15        /
@shahab-vahedi shahab-vahedi changed the title Optimising the operations and the moves Optimisation 02: The operations and the moves Mar 2, 2023
@shahab-vahedi
Copy link
Member Author

shahab-vahedi commented Mar 2, 2023

Having the following code:

long long func(long long m)
{
  return m * 47806;
}

results in an assembly like:

$ arc-elf32-gcc -mcpu=hs38_linux -O3 -S func.c -o -
        .file   "func.c"
        .cpu HS
        .arc_attribute Tag_ARC_PCS_config, 2
        .arc_attribute Tag_ARC_ABI_rf16, 0
        .arc_attribute Tag_ARC_ABI_pic, 0
        .arc_attribute Tag_ARC_ABI_tls, 0
        .arc_attribute Tag_ARC_ABI_sda, 2
        .arc_attribute Tag_ARC_ABI_exceptions, 0
        .arc_attribute Tag_ARC_CPU_variation, 2
        .section        .text
        .align 4
        .global func
        .type   func, @function
func:
        mov_s   r2,r1   ;4
        mpydu   r0,r0,47806
        mpy     r2,r2,47806
        j_s.d   [blink]
        add_s r1,r2,r1 ;1
        .size   func, .-func
        .ident  "GCC: (ARCompact/ARCv2 ISA elf32 toolchain) 10.2.0"
        .section        .note.GNU-stack,"",@progbits

But there are rooms for improvement:

  mov_s   r2,r1               \
  mpydu   r0,r0,47806         |           mpy     r2,r1,47806
  mpy     r2,r2,47806         |========>  mpydu   r0,r0,47806
  j_s.d   [blink]             |           j_s.d   [blink]
  add_s   r1,r2,r1            /           add_s   r1,r1,r2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants