Home | History | Annotate | Download | only in mips
      1     /*
      2      * String's compareTo.
      3      *
      4      * Requires a0/a1 to have been previously checked for null.  Will
      5      * return negative if this's string is < comp, 0 if they are the
      6      * same and positive if >.
      7      *
      8      * IMPORTANT NOTE:
      9      *
     10      * This code relies on hard-coded offsets for string objects, and must be
     11      * kept in sync with definitions in UtfString.h.  See asm-constants.h
     12      *
     13      * On entry:
     14      *    a0:   this object pointer
     15      *    a1:   comp object pointer
     16      *
     17      */
     18 
     19      subu  v0, a0, a1                # Same?
     20      bnez  v0, 1f
     21      RETURN
     22 1:
     23      lw    t0, STRING_FIELDOFF_OFFSET(a0)
     24      lw    t1, STRING_FIELDOFF_OFFSET(a1)
     25      lw    t2, STRING_FIELDOFF_COUNT(a0)
     26      lw    a2, STRING_FIELDOFF_COUNT(a1)
     27      lw    a0, STRING_FIELDOFF_VALUE(a0)
     28      lw    a1, STRING_FIELDOFF_VALUE(a1)
     29 
     30     /*
     31      * At this point, we have this/comp:
     32      *    offset: t0/t1
     33      *    count:  t2/a2
     34      *    value:  a0/a1
     35      * We're going to compute
     36      *    a3 <- countDiff
     37      *    a2 <- minCount
     38      */
     39      subu  a3, t2, a2                # a3<- countDiff
     40      sleu  t7, t2, a2
     41      movn  a2, t2, t7                # a2<- minCount
     42 
     43      /*
     44       * Note: data pointers point to first element.
     45       */
     46      addu  a0, 16                    # point to contents[0]
     47      addu  a1, 16                    # point to contents[0]
     48 
     49      /* Now, build pointers to the string data */
     50      sll   t7, t0, 1                 # multiply offset by 2
     51      addu  a0, a0, t7
     52      sll   t7, t1, 1                 # multiply offset by 2
     53      addu  a1, a1, t7
     54 
     55      /*
     56       * At this point we have:
     57       *   a0: *this string data
     58       *   a1: *comp string data
     59       *   a2: iteration count for comparison
     60       *   a3: value to return if the first part of the string is equal
     61       *   v0: reserved for result
     62       *   t0-t5 available for loading string data
     63       */
     64 
     65      subu  a2, 2
     66      bltz  a2, do_remainder2
     67 
     68      /*
     69       * Unroll the first two checks so we can quickly catch early mismatch
     70       * on long strings (but preserve incoming alignment)
     71       */
     72      lhu   t0, 0(a0)
     73      lhu   t1, 0(a1)
     74      subu  v0, t0, t1
     75      beqz  v0, 1f
     76      RETURN
     77 1:
     78      lhu   t2, 2(a0)
     79      lhu   t3, 2(a1)
     80      subu  v0, t2, t3
     81      beqz  v0, 2f
     82      RETURN
     83 2:
     84      addu  a0, 4                     # offset to contents[2]
     85      addu  a1, 4                     # offset to contents[2]
     86      li    t7, 28
     87      bgt   a2, t7, do_memcmp16
     88      subu  a2, 3
     89      bltz  a2, do_remainder
     90 
     91 loopback_triple:
     92      lhu   t0, 0(a0)
     93      lhu   t1, 0(a1)
     94      subu  v0, t0, t1
     95      beqz  v0, 1f
     96      RETURN
     97 1:
     98      lhu   t2, 2(a0)
     99      lhu   t3, 2(a1)
    100      subu  v0, t2, t3
    101      beqz  v0, 2f
    102      RETURN
    103 2:
    104      lhu   t4, 4(a0)
    105      lhu   t5, 4(a1)
    106      subu  v0, t4, t5
    107      beqz  v0, 3f
    108      RETURN
    109 3:
    110      addu  a0, 6                     # offset to contents[i+3]
    111      addu  a1, 6                     # offset to contents[i+3]
    112      subu  a2, 3
    113      bgez  a2, loopback_triple
    114 
    115 do_remainder:
    116      addu  a2, 3
    117      beqz  a2, returnDiff
    118 
    119 loopback_single:
    120      lhu   t0, 0(a0)
    121      lhu   t1, 0(a1)
    122      subu  v0, t0, t1
    123      bnez  v0, 1f
    124      addu  a0, 2                     # offset to contents[i+1]
    125      addu  a1, 2                     # offset to contents[i+1]
    126      subu  a2, 1
    127      bnez  a2, loopback_single
    128 
    129 returnDiff:
    130      move  v0, a3
    131 1:
    132      RETURN
    133 
    134 do_remainder2:
    135      addu  a2, 2
    136      bnez  a2, loopback_single
    137      move  v0, a3
    138      RETURN
    139 
    140     /* Long string case */
    141 do_memcmp16:
    142      move  rOBJ, a3                  # save return value if strings are equal
    143      JAL(__memcmp16)
    144      seq   t0, v0, zero
    145      movn  v0, rOBJ, t0              # overwrite return value if strings are equal
    146      RETURN
    147