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 = 0x0ffffffff & ($hash * FNV_prime_32); $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/7fs0Y
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 = 18
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 18
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
filename:       /in/7fs0Y
function name:  fnvhash_fnv1
number of ops:  23
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, ->18
         8    > > FE_FETCH_R                                               $8, !3, ->18
  45     9    >   FETCH_CONSTANT                                   ~9      'FNV_prime_32'
        10        MUL                                              ~10     !2, ~9
        11        BW_AND                                           ~11     ~10, 4294967295
        12        QM_ASSIGN                                                !2
  46    13        INIT_FCALL                                               'ord'
        14        SEND_VAR                                                 !3
        15        DO_ICALL                                         $13     
        16        ASSIGN_DIV                                   11          !2, $13
  43    17      > JMP                                                      ->8
        18    >   FE_FREE                                                  $8
  48    19        BW_AND                                           ~15     !2, 4294967295
        20        QM_ASSIGN                                                !2
  49    21      > RETURN                                                   !2
  50    22*     > RETURN                                                   null

End of function fnvhash_fnv1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
11.24 ms | 416 KiB | 7 Q