Skip to content

Conversation

@PierreAntoineGuillaume
Copy link

Hi !

I don't know if you are interested, but here's a tiny opcode optimisation for your retry.

It happens that it does not use goto, and of course it passes your tests.

Each commit has the opcode details of the transformation (the first is just a dummy commit to log the first opcode list).

Please know that I am not here for drama.

Have a nice day

igorw and others added 6 commits September 20, 2014 13:58
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   3     0  E >   RECV                                             !0
         1        RECV                                             !1
         2        RECV_INIT                                        !2      null
   6     3    >   NOP
   7     4        INIT_DYNAMIC_CALL                                        !1
         5        DO_FCALL                                      0  $4
         6      > RETURN                                                   $4
         7*       JMP                                                      ->24
   8     8  E > > CATCH                                       last         'Exception'
   9     9    > > JMPZ                                                     !2, ->13
  10    10    >   INIT_DYNAMIC_CALL                                        !2
        11        SEND_VAR_EX                                              !3
        12        DO_FCALL                                      0
  12    13    >   BOOL_XOR                                         ~6      !0
        14      > JMPZ                                                     ~6, ->21
  13    15    >   NEW                                              $7      :18
        16        SEND_VAL_EX                                              ''
        17        SEND_VAL_EX                                              0
        18        SEND_VAR_EX                                              !3
        19        DO_FCALL                                      0
        20      > THROW                                         0          $7
  15    21    >   POST_DEC                                         ~9      !0
        22        FREE                                                     ~9
  16    23      > JMP                                                      ->3
  18    24*     > RETURN                                                   null
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   3     0  E >   RECV                                             !0
         1        RECV                                             !1
         2        RECV_INIT                                        !2      null
   6     3    >   NOP
   7     4        INIT_DYNAMIC_CALL                                        !1
         5        DO_FCALL                                      0  $4
         6      > RETURN                                                   $4
         7*       JMP                                                      ->9
   8     8  E > > CATCH                                       last         'Exception'
  10     9    > > JMPZ                                                     !2, ->13
  11    10    >   INIT_DYNAMIC_CALL                                        !2
        11        SEND_VAR_EX                                              !3
        12        DO_FCALL                                      0
  13    13    >   BOOL_XOR                                         ~6      !0
        14      > JMPZ                                                     ~6, ->21
  14    15    >   NEW                                              $7      :18
        16        SEND_VAL_EX                                              ''
        17        SEND_VAL_EX                                              0
        18        SEND_VAR_EX                                              !3
        19        DO_FCALL                                      0
        20      > THROW                                         0          $7
  16    21    >   POST_DEC                                         ~9      !0
        22        FREE                                                     ~9
  17    23      > JMP                                                      ->3
  18    24*     > RETURN                                                   null
… {...}" because postfix operation returns a copy of the previous value

line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   2     0  E >   RECV                                             !0
         1        RECV                                             !1
         2        RECV_INIT                                        !2      null
   5     3    >   NOP
   6     4        INIT_DYNAMIC_CALL                                        !1
         5        DO_FCALL                                      0  $4
         6      > RETURN                                                   $4
         7*       JMP                                                      ->9
   7     8  E > > CATCH                                       last         'Exception'
   8     9    > > JMPZ                                                     !2, ->13
   9    10    >   INIT_DYNAMIC_CALL                                        !2
        11        SEND_VAR_EX                                              !3
        12        DO_FCALL                                      0
  11    13    >   POST_DEC                                         ~6      !0
        14        BOOL_XOR                                         ~7      ~6
        15      > JMPZ                                                     ~7, ->22
  12    16    >   NEW                                              $8      :14
        17        SEND_VAL_EX                                              ''
        18        SEND_VAL_EX                                              0
        19        SEND_VAR_EX                                              !3
        20        DO_FCALL                                      0
        21      > THROW                                         0          $8
  14    22    > > JMP                                                      ->3
  15    23*     > RETURN                                                   null
…ning, and if we dont, we fail too hard.

line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   2     0  E >   RECV                                             !0
         1        RECV                                             !1
         2        RECV_INIT                                        !2      null
   5     3    >   NOP
   6     4        INIT_DYNAMIC_CALL                                        !1
         5        DO_FCALL                                      0  $4
         6      > RETURN                                                   $4
         7*       JMP                                                      ->9
   7     8  E > > CATCH                                       last         'Exception'
   8     9    > > JMPZ                                                     !2, ->13
   9    10    >   INIT_DYNAMIC_CALL                                        !2
        11        SEND_VAR_EX                                              !3
        12        DO_FCALL                                      0
  11    13    >   POST_DEC                                         ~6      !0
        14      > JMPZ                                                     ~6, ->16
  12    15    > > JMP                                                      ->3
  14    16    >   NEW                                              $7      :13
        17        SEND_VAL_EX                                              ''
        18        SEND_VAL_EX                                              0
        19        SEND_VAR_EX                                              !3
        20        DO_FCALL                                      0
        21      > THROW                                         0          $7
  15    22*     > RETURN                                                   null
….. while condition, that does only one

line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   2     0  E >   RECV                                             !0
         1        RECV                                             !1
         2        RECV_INIT                                        !2      null
   7     3    >   INIT_DYNAMIC_CALL                                        !1
         4        DO_FCALL                                      0  $4
         5      > RETURN                                                   $4
         6*       JMP                                                      ->8
   8     7  E > > CATCH                                       last         'Exception'
   9     8    > > JMPZ                                                     !2, ->12
  10     9    >   INIT_DYNAMIC_CALL                                        !2
        10        SEND_VAR_EX                                              !3
        11        DO_FCALL                                      0
  13    12    >   POST_DEC                                         ~6      !0
        13      > JMPNZ                                                    ~6, ->3
  14    14    >   NEW                                              $7      :12
        15        SEND_VAL_EX                                              ''
        16        SEND_VAL_EX                                              0
        17        SEND_VAR_EX                                              !3
        18        DO_FCALL                                      0
        19      > THROW                                         0          $7
  15    20*     > RETURN                                                   null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants