From b7ffb7e49336527f549f4a4ef7a02f22a8b55136 Mon Sep 17 00:00:00 2001 From: Stas Boukarev Date: Fri, 2 Feb 2018 16:33:26 +0300 Subject: [PATCH] Inline expansion of two-arg-char-equal without using notinline. Go through another function that is declared inline, otherwise it stops the ir1 transforms from being applied. --- src/code/string.lisp | 64 +++++++++++++++++++++++------------------------ src/code/target-char.lisp | 11 +++++--- 2 files changed, 39 insertions(+), 36 deletions(-) diff --git a/src/code/string.lisp b/src/code/string.lisp index 42da1d852..d8ed21ab9 100644 --- a/src/code/string.lisp +++ b/src/code/string.lisp @@ -303,20 +303,21 @@ (let ((end-test (if (= end 1) `(= index1 (the fixnum end1)) `(= index2 (the fixnum end2))))) - `(locally (declare (inline two-arg-char-equal)) - (do ((index1 start1 (1+ index1)) - (index2 start2 (1+ index2))) - (,(if abortp - end-test - `(or ,end-test - (not (char-equal (schar string1 index1) - (schar string2 index2))))) - ,end-value) - (declare (fixnum index1 index2)) - ,@(if abortp - `((if (not (char-equal (schar string1 index1) - (schar string2 index2))) - (return ,abort-value)))))))) + `(do ((index1 start1 (1+ index1)) + (index2 start2 (1+ index2))) + (,(if abortp + end-test + `(or ,end-test + (not (two-arg-char-equal-inline + (schar string1 index1) + (schar string2 index2))))) + ,end-value) + (declare (fixnum index1 index2)) + ,@(if abortp + `((if (not (two-arg-char-equal-inline + (schar string1 index1) + (schar string2 index2))) + (return ,abort-value))))))) ) ; EVAL-WHEN @@ -389,24 +390,23 @@ (sb!xc:defmacro string-less-greater-equal (lessp equalp) (multiple-value-bind (length-test character-test) (string-less-greater-equal-tests lessp equalp) - `(locally (declare (inline two-arg-char-equal)) - (with-two-strings string1 string2 start1 end1 offset1 start2 end2 - (let ((slen1 (- (the fixnum end1) start1)) - (slen2 (- (the fixnum end2) start2))) - (declare (fixnum slen1 slen2)) - (do ((index1 start1 (1+ index1)) - (index2 start2 (1+ index2)) - (char1) - (char2)) - ((or (= index1 (the fixnum end1)) (= index2 (the fixnum end2))) - (if (,length-test slen1 slen2) (- index1 offset1))) - (declare (fixnum index1 index2)) - (setq char1 (schar string1 index1)) - (setq char2 (schar string2 index2)) - (if (not (char-equal char1 char2)) - (if ,character-test - (return (- index1 offset1)) - (return ()))))))))) + `(with-two-strings string1 string2 start1 end1 offset1 start2 end2 + (let ((slen1 (- (the fixnum end1) start1)) + (slen2 (- (the fixnum end2) start2))) + (declare (fixnum slen1 slen2)) + (do ((index1 start1 (1+ index1)) + (index2 start2 (1+ index2)) + (char1) + (char2)) + ((or (= index1 (the fixnum end1)) (= index2 (the fixnum end2))) + (if (,length-test slen1 slen2) (- index1 offset1))) + (declare (fixnum index1 index2)) + (setq char1 (schar string1 index1)) + (setq char2 (schar string2 index2)) + (if (not (two-arg-char-equal-inline char1 char2)) + (if ,character-test + (return (- index1 offset1)) + (return ())))))))) ) ; EVAL-WHEN diff --git a/src/code/target-char.lisp b/src/code/target-char.lisp index edd94b9cf..fc58891b3 100644 --- a/src/code/target-char.lisp +++ b/src/code/target-char.lisp @@ -662,8 +662,8 @@ is either numeric or alphabetic." code down-code))))) -(declaim (inline two-arg-char-equal)) -(defun two-arg-char-equal (c1 c2) +(declaim (inline two-arg-char-equal-inline)) +(defun two-arg-char-equal-inline (c1 c2) (flet ((base-char-equal-p () (let* ((code1 (char-code c1)) (code2 (char-code c2)) @@ -691,9 +691,12 @@ is either numeric or alphabetic." (or (= (aref cases index) (char-code c2)) ;; lower case (= (aref cases (1+ index)) (char-code c2)))))))) +;;; There are transforms on two-arg-char-equal, don't make it inlinable itself. +(defun two-arg-char-equal (c1 c2) + (two-arg-char-equal-inline c1 c2)) + (defun two-arg-char-not-equal (c1 c2) - (not (two-arg-char-equal c1 c2))) -(declaim (notinline two-arg-char-equal)) + (not (two-arg-char-equal-inline c1 c2))) (macrolet ((def (name test doc) `(defun ,name (character &rest more-characters) -- 2.11.4.GIT