Re: master: Change the ctz pattern to (lognor n (- n))
Stas Boukarev <[email protected]>
| Newsgroups | gmane.lisp.steel-bank.cvs,gmane.lisp.steel-bank.devel |
|---|---|
| Message-ID | <CAF63=11MRN--bjnUUfyTv_K-QjdYD48TBo=6X6BX0ui_gSML+Q@mail.gmail.com> |
I'm pretty sure you don't have (ldb (byte 64 0)), though, which makes it map to hardware. On Fri, Dec 12, 2025 at 11:21 AM Charles Zhang via Sbcl-commits <[email protected]> wrote: > > Shouldn’t both be recognized? I’m pretty sure I have the logand idiom written in some code somewhere. Not that it’s that important. > > > On 12. Dec 2025, at 00:22, stassats via Sbcl-commits <[email protected]> wrote: > > > > The branch "master" has been updated in SBCL: > > via 7cfd6dbda54b0520ca8488c5ae9e2faabb2b78d5 (commit) > > from c5f6f45800c814805366691207be92715d3a7282 (commit) > > > > - Log ----------------------------------------------------------------- > > commit 7cfd6dbda54b0520ca8488c5ae9e2faabb2b78d5 > > Author: Stas Boukarev <[email protected]> > > Date: Fri Dec 12 02:18:27 2025 +0300 > > > > Change the ctz pattern to (lognor n (- n)) > > > > No particular reason other than it's shorter. > > --- > > doc/manual/efficiency.texinfo | 2 +- > > src/compiler/srctran.lisp | 15 +++++++-------- > > 2 files changed, 8 insertions(+), 9 deletions(-) > > > > diff --git a/doc/manual/efficiency.texinfo b/doc/manual/efficiency.texinfo > > index 08d8afc1d..b13198598 100644 > > --- a/doc/manual/efficiency.texinfo > > +++ b/doc/manual/efficiency.texinfo > > @@ -346,7 +346,7 @@ features. > > @lisp > > (defun ctz (n) > > (declare (type (unsigned-byte 64) n)) > > - (integer-length (ldb (byte 64 0) (1- (logand n (- n)))))) > > + (integer-length (ldb (byte 64 0) (lognor n (- n))))) > > @end lisp > > is turned into hardware instructions on arm64 and x86-64. It returns 64 when @code{n} is 0. > > @code{n} can also be @code{(signed-byte 64)} or @code{fixnum}. > > diff --git a/src/compiler/srctran.lisp b/src/compiler/srctran.lisp > > index 1693d6643..86a616bbf 100644 > > --- a/src/compiler/srctran.lisp > > +++ b/src/compiler/srctran.lisp > > @@ -3003,19 +3003,18 @@ > > (when (< hi 0) > > (specifier-type `(integer ,(integer-length hi))))))))))) > > > > -;; (integer-length (ldb (byte 64 0) (1- (logand n (- n))))) => ctz > > +;; (integer-length (ldb (byte 64 0) (lognor n (- n)))) => ctz > > (when-vop-existsp (:translate count-trailing-zeros) > > (deftransform integer-length ((x) (word) * :important nil :node node) > > (delay-ir1-transform node :ir1-phases) > > (or > > (combination-match x > > - (sb-vm::--mod64 (:or (logand n ((:or sb-vm::%negate-mod64 sb-vm::%negate-modfx) n)) > > - (logand (logand n #.most-positive-word) > > - (sb-vm::%negate-mod64 (logand n #.most-positive-word))) > > - (logand (logand n #.(ash most-positive-word -1)) > > - (logand (sb-vm::%negate-mod64 (logand n #.(ash most-positive-word -1))) > > - #.(ash most-positive-word -1)))) > > - 1) > > + (sb-vm::lognot-mod64 (:or > > + (logior n (:or (sb-vm::%negate-mod64 n) > > + (logand (sb-vm::%negate-modfx n) #.most-positive-word))) > > + (logior (logand n #.most-positive-word) > > + (:or (sb-vm::%negate-mod64 (logand n #.most-positive-word)) > > + (logand (sb-vm::%negate-modfx n) #.most-positive-word))))) > > (when (word-sized-lvar-p n) > > (extract-lvar n node) > > `(count-trailing-zeros x))) > > > > ----------------------------------------------------------------------- > > > > > > hooks/post-receive > > -- > > SBCL > > > > > > _______________________________________________ > > Sbcl-commits mailing list > > [email protected] > > https://lists.sourceforge.net/lists/listinfo/sbcl-commits > > > > _______________________________________________ > Sbcl-commits mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/sbcl-commits _______________________________________________ Sbcl-commits mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/sbcl-commits