Skip to content
Tcl Source Code History Of Ticket 2958832fffffffffffffffffffffffffffffffff
Login

History Of Ticket 2958832fffffffffffffffffffffffffffffffff

Artifacts Associated With Ticket 2958832fffffffffffffffffffffffffffffffff

  1. Ticket change [d1077a049c] (rid 113280) by nijtmans on 2010-02-25 17:07:34:

    1. assignee initialized to: "nijtmans"
    2. cmimetype initialized to: "text/plain"
    3. comment initialized to:
      The ouster-hash function (HashStringKey in tclHash.c,
      and two variants in other places) can be speed up
      further. Here is my suggestion, which is 5 assembler
      instructions faster for every function call. For
      an explanation, see below (read on).
      
      ================ new ====================
      if ((result = UCHAR(*string)) != 0) {
          while ((c = *++string) != 0) {
              result += (result << 3) + UCHAR(c);
          }
      }
      return result;
      ================ old =====================
      for (; (c=*string++) != 0 ;) {
          result += (result<<3) + UCHAR(c);
      }
      return result;
      ===========================================
      
      There is no difference in using a for loop and
      a while loop. It's exactly the same, apart from
      personal preference...
      
      The first loop entry, result starts being 0, we will
      shift the 0 value 3 bits, resulting in 0. Then we
      are adding 0 to UCHAR(c), resulting in UCHAR(c).
      The question is, when we already know that the
      result after the first shift and addition will be
      UCHAR(c), why do we do the shift and the addition
      at all?
      
      In the last loop entry, the pointer is incremented,
      but the incremented pointer is not accessed any more.
      So, a little re-ordering could prevent this increment.
      That's how I came up with the faster code above.
      
      How much faster is it? Here is the generated i86 assembler
      code for both versions, using gcc-4.4.
      ================ new ====================
      HashStringKey:
      pushl%ebp
      movl%esp, %ebp
      movl12(%ebp), %edx
      movzbl(%edx), %eax
      testl%eax, %eax
      je.L32
      leal1(%edx), %ecx
      movzbl1(%edx), %edx
      testb%dl, %dl
      je.L32
      .L35:
      movzbl%dl, %edx
      addl$1, %ecx
      leal(%edx,%eax,8), %edx
      addl%edx, %eax
      movzbl(%ecx), %edx
      testb%dl, %dl
      jne.L35
      .L32:
      popl%ebp
      ret
      ================ old =====================
      HashStringKey:
      pushl%ebp
      xorl%eax, %eax
      movl%esp, %ebp
      movl12(%ebp), %ecx
      movzbl(%ecx), %edx
      testb%dl, %dl
      je.L33
      addl$1, %ecx
      .L34:
      movzbl%dl, %edx
      leal(%edx,%eax,8), %edx
      addl%edx, %eax
      movzbl(%ecx), %edx
      addl$1, %ecx
      testb%dl, %dl
      jne.L34
      .L33:
      popl%ebp
      ret
      ===========================================
      
      Zo, the main loop has 7 instructions, only in
      a different order. The preparation has 10
      instructions, against 8 before, but the loop
      has to be run one less time! So, we gain 5
      instructions! Using another processor, the
      result will be different, but fact is that
      we save a shift, an addition and an increment.
      
      Anyone, who can do better?
      
      
    4. foundin initialized to: "None"
    5. is_private initialized to: "0"
    6. priority initialized to: "3 Low"
    7. resolution initialized to: "None"
    8. status initialized to: "Open"
    9. submitter initialized to: "nijtmans"
    10. subsystem initialized to: "11. Conversions From String"
    11. title initialized to: "Further speed-up of ouster-hash function"
    12. type initialized to: "RFE"
  2. Ticket change [0267c5b1ca] (rid 119643) by nijtmans on 2010-02-26 05:28:22:

    1. closedate changed to: "2010-02-25T22:28:22"
    2. closer changed to: "nijtmans"
    3. icomment:
      It turns out, that the variants in tclObj.c
      and tclLiteral.c gain less, only 2 instructions,
      when doing the same. However, it IS
      a speedup, however little.
      
      Committed in HEAD. Not really worth to be
      backported, or is it? First, let it be proven
      a little bit more in 8.6
      
      
    4. login: "nijtmans"
    5. mimetype: "text/plain"
    6. resolution changed to: "Fixed"
    7. status changed to: "Closed"
    8. username: "nijtmans"
  3. Ticket change [ce1ee311fe] (rid 148440) by dkf on 2016-08-23 13:45:21:

    1. assignee changed to: "aku"
    2. closedate changed to: "2457624.07316888"
    3. closer changed to: "dkf"
    4. comment changed to:
      The ouster-hash function (HashStringKey in tclHash.c,
      and two variants in other places) can be speed up
      further. Here is my suggestion, which is 5 assembler
      instructions faster for every function call. For
      an explanation, see below (read on).
      
      ================ new ====================
      if ((result = UCHAR(*string)) != 0) {
          while ((c = *++string) != 0) {
              result += (result << 3) + UCHAR(c);
          }
      }
      return result;
      ================ old =====================
      for (; (c=*string++) != 0 ;) {
          result += (result<<3) + UCHAR(c);
      }
      return result;
      ===========================================
      
      There is no difference in using a for loop and
      a while loop. It's exactly the same, apart from
      personal preference...
      
      The first loop entry, result starts being 0, we will
      shift the 0 value 3 bits, resulting in 0. Then we
      are adding 0 to UCHAR(c), resulting in UCHAR(c).
      The question is, when we already know that the
      result after the first shift and addition will be
      UCHAR(c), why do we do the shift and the addition
      at all?
      
      In the last loop entry, the pointer is incremented,
      but the incremented pointer is not accessed any more.
      So, a little re-ordering could prevent this increment.
      That's how I came up with the faster code above.
      
      How much faster is it? Here is the generated i86 assembler
      code for both versions, using gcc-4.4.
      ================ new ====================
      HashStringKey:
      pushl%ebp
      movl%esp, %ebp
      movl12(%ebp), %edx
      movzbl(%edx), %eax
      testl%eax, %eax
      je.L32
      leal1(%edx), %ecx
      movzbl1(%edx), %edx
      testb%dl, %dl
      je.L32
      .L35:
      movzbl%dl, %edx
      addl$1, %ecx
      leal(%edx,%eax,8), %edx
      addl%edx, %eax
      movzbl(%ecx), %edx
      testb%dl, %dl
      jne.L35
      .L32:
      popl%ebp
      ret
      ================ old =====================
      HashStringKey:
      pushl%ebp
      xorl%eax, %eax
      movl%esp, %ebp
      movl12(%ebp), %ecx
      movzbl(%ecx), %edx
      testb%dl, %dl
      je.L33
      addl$1, %ecx
      .L34:
      movzbl%dl, %edx
      leal(%edx,%eax,8), %edx
      addl%edx, %eax
      movzbl(%ecx), %edx
      addl$1, %ecx
      testb%dl, %dl
      jne.L34
      .L33:
      popl%ebp
      ret
      ===========================================
      
      Zo, the main loop has 7 instructions, only in
      a different order. The preparation has 10
      instructions, against 8 before, but the loop
      has to be run one less time! So, we gain 5
      instructions! Using another processor, the
      result will be different, but fact is that
      we save a shift, an addition and an increment.
      
      Anyone, who can do better?
      
    5. login: "dkf"
    6. mimetype: "text/plain"
    7. severity changed to: "Minor"
    8. subsystem changed to: "11. Conversions from String"