3v4l.org

run code in 300+ PHP versions simultaneously
<?php define ("FNV_prime_32", 16777619); define ("FNV_prime_64", 1099511628211); define ("FNV_prime_128", 309485009821345068724781371); define ("FNV_offset_basis_32", 2166136261); define ("FNV_offset_basis_64", 14695981039346656037); define ("FNV_offset_basis_128", 144066263297769815596495629667062367629); /* * The core of the FNV-1 hash algorithm is as follows: * * hash = offset_basis * for each octet_of_data to be hashed * hash = hash * FNV_prime * hash = hash xor octet_of_data * return hash * * Source: http://www.isthe.com/chongo/tech/comp/fnv/ */ /* * Example Java implementation: * * long fnv(byte[] buf, int offset, int len, long seed) * { * for (int i = offset; i < offset + len; i++) * { * seed += (seed << 1) + (seed << 4) + (seed << 7) + (seed << 8) + (seed << 24); * seed ^= buf[i]; * } * return seed; * } * * `Source: http://www.getopt.org/ - FNV1 Hash */ function fnvhash_fnv1($txt) { $buf = str_split($txt); $hash = FNV_offset_basis_32; foreach ($buf as $chr) { $hash += ($hash << 1) + ($hash << 4) + ($hash << 7) + ($hash << 8) + ($hash << 24); $hash = $hash ^ ord($chr); } $hash = $hash & 0x0ffffffff; return $hash; } var_dump(fnvhash_fnv1("test")); var_dump(fnvhash_fnv1("tess"));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/bXN6i
function name:  (null)
number of ops:  37
compiled vars:  none
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   3     0  E >   INIT_FCALL                                               'define'
         1        SEND_VAL                                                 'FNV_prime_32'
         2        SEND_VAL                                                 16777619
         3        DO_ICALL                                                 
   4     4        INIT_FCALL                                               'define'
         5        SEND_VAL                                                 'FNV_prime_64'
         6        SEND_VAL                                                 1099511628211
         7        DO_ICALL                                                 
   5     8        INIT_FCALL                                               'define'
         9        SEND_VAL                                                 'FNV_prime_128'
        10        SEND_VAL                                                 3.09485e+26
        11        DO_ICALL                                                 
   7    12        INIT_FCALL                                               'define'
        13        SEND_VAL                                                 'FNV_offset_basis_32'
        14        SEND_VAL                                                 2166136261
        15        DO_ICALL                                                 
   8    16        INIT_FCALL                                               'define'
        17        SEND_VAL                                                 'FNV_offset_basis_64'
        18        SEND_VAL                                                 1.4696e+19
        19        DO_ICALL                                                 
   9    20        INIT_FCALL                                               'define'
        21        SEND_VAL                                                 'FNV_offset_basis_128'
        22        SEND_VAL                                                 1.44066e+38
        23        DO_ICALL                                                 
  53    24        INIT_FCALL                                               'var_dump'
        25        INIT_FCALL                                               'fnvhash_fnv1'
        26        SEND_VAL                                                 'test'
        27        DO_FCALL                                      0  $6      
        28        SEND_VAR                                                 $6
        29        DO_ICALL                                                 
  54    30        INIT_FCALL                                               'var_dump'
        31        INIT_FCALL                                               'fnvhash_fnv1'
        32        SEND_VAL                                                 'tess'
        33        DO_FCALL                                      0  $8      
        34        SEND_VAR                                                 $8
        35        DO_ICALL                                                 
        36      > RETURN                                                   1

Function fnvhash_fnv1:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 25
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 25
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
filename:       /in/bXN6i
function name:  fnvhash_fnv1
number of ops:  30
compiled vars:  !0 = $txt, !1 = $buf, !2 = $hash, !3 = $chr
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  39     0  E >   RECV                                             !0      
  41     1        INIT_FCALL                                               'str_split'
         2        SEND_VAR                                                 !0
         3        DO_ICALL                                         $4      
         4        QM_ASSIGN                                                !1
  42     5        FETCH_CONSTANT                                   ~6      'FNV_offset_basis_32'
         6        QM_ASSIGN                                                !2
  43     7      > FE_RESET_R                                       $8      !1, ->25
         8    > > FE_FETCH_R                                               $8, !3, ->25
  45     9    >   SL                                               ~9      !2, 1
        10        SL                                               ~10     !2, 4
        11        ADD                                              ~11     ~9, ~10
        12        SL                                               ~12     !2, 7
        13        ADD                                              ~13     ~11, ~12
        14        SL                                               ~14     !2, 8
        15        ADD                                              ~15     ~13, ~14
        16        SL                                               ~16     !2, 24
        17        ADD                                              ~17     ~15, ~16
        18        ASSIGN_DIV                                    1          !2, ~17
  46    19        INIT_FCALL                                               'ord'
        20        SEND_VAR                                                 !3
        21        DO_ICALL                                         $19     
        22        BW_XOR                                           ~20     !2, $19
        23        QM_ASSIGN                                                !2
  43    24      > JMP                                                      ->8
        25    >   FE_FREE                                                  $8
  48    26        BW_AND                                           ~22     !2, 4294967295
        27        QM_ASSIGN                                                !2
  49    28      > RETURN                                                   !2
  50    29*     > RETURN                                                   null

End of function fnvhash_fnv1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
38.36 ms | 416 KiB | 7 Q