public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/95151] New: Add cmpmemM pattern for -minline-all-stringops
@ 2020-05-15 12:32 hjl.tools at gmail dot com
  2020-05-19 12:11 ` [Bug target/95151] [9/10/11 Regression] " hjl.tools at gmail dot com
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: hjl.tools at gmail dot com @ 2020-05-15 12:32 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95151

            Bug ID: 95151
           Summary: Add cmpmemM pattern for -minline-all-stringops
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: hjl.tools at gmail dot com
                CC: crazylht at gmail dot com
  Target Milestone: ---
            Target: i386,x86-64

'cmpmemM'
     Block compare instruction, with five operands like the operands of
     'cmpstrM'.  The two memory blocks specified are compared byte by
     byte in lexicographic order starting at the beginning of each
     block.  Unlike 'cmpstrM' the instruction can prefetch any bytes in
     the two memory blocks.  Also unlike 'cmpstrM' the comparison will
     not stop if both bytes are zero.  The effect of the instruction is
     to store a value in operand 0 whose sign indicates the result of
     the comparison.

We should add

(define_expand "cmpmemsi"
  [(set (match_operand:SI 0 "register_operand" "")
        (compare:SI (match_operand:BLK 1 "memory_operand" "")
                    (match_operand:BLK 2 "memory_operand" "") ) )
   (use (match_operand 3 "general_operand"))
   (use (match_operand 4 "immediate_operand"))]
  ""
{
  if (ix86_expand_cmpmem (operands[0], operands[1], operands[2],
                          operands[3]))
    DONE; 
  else
    FAIL; 
})

which can be expanded to sysdeps/i386/memcmp.S in glibc:

        movl BLK1(%esp), %esi
        cfi_rel_offset (esi, 0)
        movl BLK2(%esp), %edi
        movl LEN(%esp), %ecx

        cld                     /* Set direction of comparison.  */

        xorl %eax, %eax         /* Default result.  */

        repe                    /* Compare at most %ecx bytes.  */
        cmpsb
        jz L(1)                 /* If even last byte was equal we return 0.  */

        /* The memory blocks are not equal.  So result of the last
           subtraction is present in the carry flag.  It is set when
           the byte in block #2 is bigger.  In this case we have to
           return -1 (=0xffffffff), else 1.  */
        sbbl %eax, %eax         /* This is tricky.  %eax == 0 and carry is set
                                   or not depending on last subtraction.  */

        /* At this point %eax == 0, if the byte of block #1 was bigger, and
           0xffffffff if the last byte of block #2 was bigger.  The latter
           case is already correct but the former needs a little adjustment.
           Note that the following operation does not change 0xffffffff.  */
        orb $1, %al             /* Change 0 to 1.  */

L(1):

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2020-10-26 11:19 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-15 12:32 [Bug target/95151] New: Add cmpmemM pattern for -minline-all-stringops hjl.tools at gmail dot com
2020-05-19 12:11 ` [Bug target/95151] [9/10/11 Regression] " hjl.tools at gmail dot com
2020-05-30 12:14 ` hjl.tools at gmail dot com
2020-05-31  1:40 ` hjl.tools at gmail dot com
2020-05-31 23:13 ` hjl.tools at gmail dot com
2020-05-31 23:14 ` hjl.tools at gmail dot com
2020-07-13 17:35 ` hjl.tools at gmail dot com
2020-07-14 19:10 ` ro at gcc dot gnu.org
2020-07-14 21:08 ` hjl.tools at gmail dot com
2020-10-16 11:43 ` rguenth at gcc dot gnu.org
2020-10-26 11:19 ` hjl.tools at gmail dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).