3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * @return array */ function crc64Table() { $crc64tab = []; // ECMA polynomial $poly64rev = (0xC96C5795 << 32) | 0xD7870F42; echo sprintf("%x", $poly64rev) . PHP_EOL; // ISO polynomial // $poly64rev = (0xD8 << 56); for ($i = 0; $i < 256; $i++) { for ($part = $i, $bit = 0; $bit < 8; $bit++) { if ($part & 1) { $part = (($part >> 1) & ~(0x8 << 60)) ^ $poly64rev; } else { $part = ($part >> 1) & ~(0x8 << 60); } } $crc64tab[$i] = $part; } return $crc64tab; } /** * @param string $string * @param string $format * @return mixed * * Formats: * crc64('php'); // afe4e823e7cef190 * crc64('php', '0x%x'); // 0xafe4e823e7cef190 * crc64('php', '0x%X'); // 0xAFE4E823E7CEF190 * crc64('php', '%d'); // -5772233581471534704 signed int * crc64('php', '%u'); // 12674510492238016912 unsigned int */ function crc64($string, $format = '%x') { static $crc64tab; if ($crc64tab === null) { $crc64tab = crc64Table(); } printf("%u", $crc64tab[1]); echo PHP_EOL; $crc = 0; for ($i = 0; $i < strlen($string); $i++) { //$crc = $crc64tab[($crc ^ ord($string[$i])) & 0xff] ^ (($crc >> 8) & ~(0xff << 56)); $crc = $crc64tab[$crc^ord($string[$i]) & 0xff] ^ ($crc >> 8) & ~(0xff << 56); } return sprintf($format, $crc); } echo crc64("123456", "%u");
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EFiio
function name:  (null)
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   67     0  E >   INIT_FCALL                                               'crc64'
          1        SEND_VAL                                                 '123456'
          2        SEND_VAL                                                 '%25u'
          3        DO_FCALL                                      0  $0      
          4        ECHO                                                     $0
          5      > RETURN                                                   1

Function crc64table:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
2 jumps found. (Code = 44) Position 1 = 31, Position 2 = 10
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
2 jumps found. (Code = 44) Position 1 = 26, Position 2 = 13
Branch analysis from position: 26
2 jumps found. (Code = 44) Position 1 = 31, Position 2 = 10
Branch analysis from position: 31
Branch analysis from position: 10
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 20
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
2 jumps found. (Code = 44) Position 1 = 26, Position 2 = 13
Branch analysis from position: 26
Branch analysis from position: 13
Branch analysis from position: 20
2 jumps found. (Code = 44) Position 1 = 26, Position 2 = 13
Branch analysis from position: 26
Branch analysis from position: 13
filename:       /in/EFiio
function name:  crc64Table
number of ops:  33
compiled vars:  !0 = $crc64tab, !1 = $poly64rev, !2 = $i, !3 = $part, !4 = $bit
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   ASSIGN                                                   !0, <array>
   11     1        ASSIGN                                                   !1, -3932672073523589310
   13     2        INIT_FCALL                                               'sprintf'
          3        SEND_VAL                                                 '%25x'
          4        SEND_VAR                                                 !1
          5        DO_ICALL                                         $7      
          6        CONCAT                                           ~8      $7, '%0A'
          7        ECHO                                                     ~8
   18     8        ASSIGN                                                   !2, 0
          9      > JMP                                                      ->29
   20    10    >   ASSIGN                                                   !3, !2
         11        ASSIGN                                                   !4, 0
         12      > JMP                                                      ->24
   21    13    >   BW_AND                                           ~12     !3, 1
         14      > JMPZ                                                     ~12, ->20
   22    15    >   SR                                               ~13     !3, 1
         16        BW_AND                                           ~14     ~13, 9223372036854775807
         17        BW_XOR                                           ~15     !1, ~14
         18        ASSIGN                                                   !3, ~15
         19      > JMP                                                      ->23
   24    20    >   SR                                               ~17     !3, 1
         21        BW_AND                                           ~18     ~17, 9223372036854775807
         22        ASSIGN                                                   !3, ~18
   20    23    >   PRE_INC                                                  !4
         24    >   IS_SMALLER                                               !4, 8
         25      > JMPNZ                                                    ~21, ->13
   28    26    >   ASSIGN_DIM                                               !0, !2
         27        OP_DATA                                                  !3
   18    28        PRE_INC                                                  !2
         29    >   IS_SMALLER                                               !2, 256
         30      > JMPNZ                                                    ~24, ->10
   31    31    > > RETURN                                                   !0
   32    32*     > RETURN                                                   null

End of function crc64table

Function crc64:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 8
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
2 jumps found. (Code = 44) Position 1 = 32, Position 2 = 17
Branch analysis from position: 32
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
2 jumps found. (Code = 44) Position 1 = 32, Position 2 = 17
Branch analysis from position: 32
Branch analysis from position: 17
Branch analysis from position: 8
filename:       /in/EFiio
function name:  crc64
number of ops:  38
compiled vars:  !0 = $string, !1 = $format, !2 = $crc64tab, !3 = $crc, !4 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   46     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      '%25x'
   48     2        BIND_STATIC                                              !2
   50     3        TYPE_CHECK                                    2          !2
          4      > JMPZ                                                     ~5, ->8
   51     5    >   INIT_FCALL                                               'crc64table'
          6        DO_FCALL                                      0  $6      
          7        ASSIGN                                                   !2, $6
   54     8    >   INIT_FCALL                                               'printf'
          9        SEND_VAL                                                 '%25u'
         10        FETCH_DIM_R                                      ~8      !2, 1
         11        SEND_VAL                                                 ~8
         12        DO_ICALL                                                 
   55    13        ECHO                                                     '%0A'
   57    14        ASSIGN                                                   !3, 0
   59    15        ASSIGN                                                   !4, 0
         16      > JMP                                                      ->29
   61    17    >   INIT_FCALL                                               'ord'
         18        FETCH_DIM_R                                      ~12     !0, !4
         19        SEND_VAL                                                 ~12
         20        DO_ICALL                                         $13     
         21        BW_AND                                           ~14     $13, 255
         22        BW_XOR                                           ~15     !3, ~14
         23        FETCH_DIM_R                                      ~16     !2, ~15
         24        SR                                               ~17     !3, 8
         25        BW_AND                                           ~18     ~17, 72057594037927935
         26        BW_XOR                                           ~19     ~16, ~18
         27        ASSIGN                                                   !3, ~19
   59    28        PRE_INC                                                  !4
         29    >   STRLEN                                           ~22     !0
         30        IS_SMALLER                                               !4, ~22
         31      > JMPNZ                                                    ~23, ->17
   64    32    >   INIT_FCALL                                               'sprintf'
         33        SEND_VAR                                                 !1
         34        SEND_VAR                                                 !3
         35        DO_ICALL                                         $24     
         36      > RETURN                                                   $24
   65    37*     > RETURN                                                   null

End of function crc64

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
145.92 ms | 1407 KiB | 21 Q