Re: Comparing lowtags: slightly inefficient assembly code

Stas Boukarev <[email protected]> Wed, 30 Apr 2025 22:51:37 +0300
Newsgroups gmane.lisp.steel-bank.general
Message-ID <CAF63=12-M9orU7HNoG6cMJp6nivK_kPWz+JOgOshfsrgSXKeng@mail.gmail.com>
Is that causing you some unexpected performance issues?

On Wed, Apr 30, 2025 at 10:50 PM David Scherfgen via Sbcl-help
<[email protected]> wrote:
>
> Hello,
>
> I have this SBCL-specific code to determine whether two objects X and Y have the same lowtag:
>
> (defun same-lowtag-p (x y)
>   (= (sb-kernel:lowtag-of x) (sb-kernel:lowtag-of y)))
>
> The relevant part of the disassembly:
>
> MOV RDX, R8
> SHL RDX, 1
> AND EDX, 30
> MOV RDI, RSI
> SHL RDI, 1
> AND EDI, 30
> CMP RDI, RDX
>
> It shifts the address of X and Y to the left by 1 bit, then masks with 30 (= 15 << 1), then compares.
> The bit shift is unnecessary. It could mask X and Y with 15 and directly compare without shifting.
>
> Is there any (hacky, using internals) way to modify the Lisp function so that it results in optimal assembly without bit shifts?
>
> Thank you.
>
> Best regards
> David Scherfgen
> _______________________________________________
> Sbcl-help mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/sbcl-help


_______________________________________________
Sbcl-help mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sbcl-help