string< on simple-base-strings producing suspicious code

Bug #1848776 reported by Paul F. Dietz
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
SBCL
Fix Released
Undecided
Unassigned

Bug Description

(defun f1 (s1 s2) (declare (optimize speed (safety 0) (debug 0) (compilation-speed 0) (space 2)) (type simple-base-string s1 s2)) (string<= s1 s2))

It produces both a call to %SP-STRING-COMPARE, and some complicated branching.

(disassemble 'f1) ==>

; disassembly for F1
; Size: 167 bytes. Origin: #x52D4C06D ; F1
; 06D: 4C894DE8 MOV [RBP-24], R9
; 071: 4C8945E0 MOV [RBP-32], R8
; 075: 4D8B50F9 MOV R10, [R8-7]
; 079: 4C8955F8 MOV [RBP-8], R10
; 07D: 4D8B61F9 MOV R12, [R9-7]
; 081: 4C8965F0 MOV [RBP-16], R12
; 085: 488D4424F0 LEA RAX, [RSP-16]
; 08A: 4883EC30 SUB RSP, 48
; 08E: 498BD0 MOV RDX, R8
; 091: 31FF XOR EDI, EDI
; 093: 498BF2 MOV RSI, R10
; 096: 4C8948F0 MOV [RAX-16], R9
; 09A: 488978E8 MOV [RAX-24], RDI
; 09E: 4C8960E0 MOV [RAX-32], R12
; 0A2: B90C000000 MOV ECX, 12
; 0A7: 488928 MOV [RAX], RBP
; 0AA: 488BE8 MOV RBP, RAX
; 0AD: B802BD4450 MOV EAX, #x5044BD02 ; #<FDEFN SB-KERNEL:%SP-STRING-COMPARE>
; 0B2: FFD0 CALL RAX
; 0B4: 4C8B45E0 MOV R8, [RBP-32]
; 0B8: 4C8B4DE8 MOV R9, [RBP-24]
; 0BC: 4C8B65F0 MOV R12, [RBP-16]
; 0C0: 4C8B55F8 MOV R10, [RBP-8]
; 0C4: 488BDA MOV RBX, RDX
; 0C7: 4881FB17001050 CMP RBX, #x50100017 ; NIL
; 0CE: 7509 JNE L1
; 0D0: 498BD2 MOV RDX, R10
; 0D3: L0: 488BE5 MOV RSP, RBP
; 0D6: F8 CLC
; 0D7: 5D POP RBP
; 0D8: C3 RET
; 0D9: L1: 488BD3 MOV RDX, RBX
; 0DC: 4939D2 CMP R10, RDX
; 0DF: 7505 JNE L3
; 0E1: L2: 488BD3 MOV RDX, RBX
; 0E4: EBED JMP L0
; 0E6: L3: 488BD3 MOV RDX, RBX
; 0E9: 4939D4 CMP R12, RDX
; 0EC: 7507 JNE L5
; 0EE: L4: BA17001050 MOV EDX, #x50100017 ; NIL
; 0F3: EBDE JMP L0
; 0F5: L5: 488BD3 MOV RDX, RBX
; 0F8: 48D1FA SAR RDX, 1
; 0FB: 410FB6441001 MOVZX EAX, BYTE PTR [R8+RDX+1]
; 101: 488BD3 MOV RDX, RBX
; 104: 48D1FA SAR RDX, 1
; 107: 410FB64C1101 MOVZX ECX, BYTE PTR [R9+RDX+1]
; 10D: 4839C8 CMP RAX, RCX
; 110: 72CF JB L2
; 112: EBDA JMP L4

Revision history for this message
Stas Boukarev (stassats) wrote :

SB-KERNEL:%SP-STRING-COMPARE returns the first non-matching index, then it has to decide whether it's >, or <, or >=, etc.

Revision history for this message
Stas Boukarev (stassats) wrote :

7441f3b09404f18492caa6a73e1963dec80f1d50

Changed in sbcl:
status: New → Fix Committed
Changed in sbcl:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.