Skip to content

Optimisation 03: Reuse reg iso LIMM #112

@shahab-vahedi

Description

@shahab-vahedi

Having the following code:

long long func(long long m)
{
  return m * 0x82345678;
}

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:
        mov_s   r12,-2110499208 ;13
        mpy     r1,r1,-2110499208
        mpymu   r3,r0,r12
        mpy     r2,r0,r12
        add_s   r3,r1,r3 ;1
        mov_s   r0,r2   ;4
        j_s.d   [blink]
        mov_s   r1,r3   ;4
        .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   r12,-2110499208     \
  mpy     r1,r1,-2110499208   |          mov_s   r12,-2110499208
  mpymu   r3,r0,r12           |          mpy_s   r1,r1,r12
  mpy     r2,r0,r12           |========> mpymu   r3,r0,r12
  add_s   r3,r1,r3            |          mpy_s   r0,r0,r12
  mov_s   r0,r2               |          j_s.d   [blink]
  j_s.d   [blink]             |          add_s   r1,r1,r3
  mov_s   r1,r3               /

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions