lightning
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Optimizing jit_divi_u()


From: Paulo César Pereira de Andrade
Subject: Re: Optimizing jit_divi_u()
Date: Fri, 25 Aug 2023 09:33:42 -0300

Em sex., 25 de ago. de 2023 às 06:02, Paul Cercueil
<paul@crapouillou.net> escreveu:
>
> Hi Paulo,

  Hi Paul,

> I saw you added jit_hmulr(), thanks!

[snip]

> I believe we could implement it as a fallback, and also handle special
> values in there. Then have all architectures that can't do better use
> this fallback.

  Probably we should create a peephole optimization pass.

> Note that signed division should be possible as well, I know that
> "libdivide" supports it.

  Did not know about libdivide. I had tested this:

"""
long sdiv7(long v)
{
    return v / 7;
}

unsigned long udiv7(unsigned long v)
{
    return v / 7;
}
"""

and disassemble is:

"""
0000000000000000 <sdiv7>:
   0:    48 b8 25 49 92 24 49     movabs $0x4924924924924925,%rax
   7:    92 24 49
   a:    48 f7 ef                 imul   %rdi
   d:    48 c1 ff 3f              sar    $0x3f,%rdi
  11:    48 d1 fa                 sar    %rdx
  14:    48 89 d0                 mov    %rdx,%rax
  17:    48 29 f8                 sub    %rdi,%rax
  1a:    c3                       ret
  1b:    0f 1f 44 00 00           nopl   0x0(%rax,%rax,1)

0000000000000020 <udiv7>:
  20:    48 b8 93 24 49 92 24     movabs $0x2492492492492493,%rax
  27:    49 92 24
  2a:    48 f7 e7                 mul    %rdi
  2d:    48 29 d7                 sub    %rdx,%rdi
  30:    48 d1 ef                 shr    %rdi
  33:    48 8d 04 3a              lea    (%rdx,%rdi,1),%rax
  37:    48 c1 e8 02              shr    $0x2,%rax
  3b:    c3                       ret
"""

> Cheers,
> -Paul

Thanks,
Paulo



reply via email to

[Prev in Thread] Current Thread [Next in Thread]