Skip to content
Snippets Groups Projects
  1. May 18, 2018
  2. May 16, 2018
  3. Apr 03, 2018
    • Damien George's avatar
      py/vm: Optimise handling of stackless mode when pystack is enabled. · bc365213
      Damien George authored
      When pystack is enabled mp_obj_fun_bc_prepare_codestate() will always
      return a valid pointer, and if there is no more pystack available then it
      will raise an exception (a RuntimeError).  So having pystack enabled with
      stackless enabled automatically gives strict stackless mode.  There is
      therefore no need to have code for strict stackless mode when pystack is
      enabled, and this patch optimises the VM for such a case.
      bc365213
    • Damien George's avatar
      py/vm: Don't do unnecessary updates of ip and sp variables. · c7f880ed
      Damien George authored
      Neither the ip nor sp variables are used again after the execution of the
      RAISE_VARARGS opcode, so they don't need to be updated.
      c7f880ed
  4. Feb 27, 2018
    • Damien George's avatar
      py/vm: Simplify handling of special-case STOP_ITERATION in yield from. · a9f6d492
      Damien George authored
      There's no need to have MP_OBJ_NULL a special case, the code can re-use
      the MP_OBJ_STOP_ITERATION value to signal the special case and the VM can
      detect this with only one check (for MP_OBJ_STOP_ITERATION).
      a9f6d492
    • Damien George's avatar
      py/vm: Fix case of handling raised StopIteration within yield from. · 22ade2f5
      Damien George authored
      This patch concerns the handling of an NLR-raised StopIteration, raised
      during a call to mp_resume() which is handling the yield from opcode.
      
      Previously, commit 6738c1dd introduced code
      to handle this case, along with a test.  It seems that it was lucky that
      the test worked because the code did not correctly handle the stack pointer
      (sp).
      
      Furthermore, commit 79d996a5 improved the
      way mp_resume() propagated certain exceptions: it changed raising an NLR
      value to returning MP_VM_RETURN_EXCEPTION.  This change meant that the
      test introduced in gen_yield_from_ducktype.py was no longer hitting the
      code introduced in 6738c1dd.
      
      The patch here does two things:
      
      1. Fixes the handling of sp in the VM for the case that yield from is
         interrupted by a StopIteration raised via NLR.
      
      2. Introduces a new test to check this handling of sp and re-covers the
         code in the VM.
      22ade2f5
  5. Feb 15, 2018
    • Damien George's avatar
      py/objexcept: Remove long-obsolete mp_const_MemoryError_obj. · 73d1d20b
      Damien George authored
      This constant exception instance was once used by m_malloc_fail() to raise
      a MemoryError without allocating memory, but it was made obsolete long ago
      by 3556e457.  The functionality is now
      replaced by the use of mp_emergency_exception_obj which lives in the global
      uPy state, and which can handle any exception type, not just MemoryError.
      73d1d20b
  6. Feb 08, 2018
    • Damien George's avatar
      py/vm: Simplify stack sentinel values for unwind return and jump. · 0c650d42
      Damien George authored
      This patch simplifies how sentinel values are stored on the stack when
      doing an unwind return or jump.  Instead of storing two values on the stack
      for an unwind jump it now stores only one: a negative small integer means
      unwind-return and a non-negative small integer means unwind-jump with the
      value being the number of exceptions to unwind.  The savings in code size
      are:
      
         bare-arm:   -56
      minimal x86:   -68
         unix x64:   -80
      unix nanbox:    -4
            stm32:   -56
           cc3200:   -64
          esp8266:   -76
            esp32:  -156
      0c650d42
  7. Dec 11, 2017
  8. Dec 09, 2017
  9. Oct 04, 2017
    • Damien George's avatar
      all: Remove inclusion of internal py header files. · a3dc1b19
      Damien George authored
      Header files that are considered internal to the py core and should not
      normally be included directly are:
          py/nlr.h - internal nlr configuration and declarations
          py/bc0.h - contains bytecode macro definitions
          py/runtime0.h - contains basic runtime enums
      
      Instead, the top-level header files to include are one of:
          py/obj.h - includes runtime0.h and defines everything to use the
              mp_obj_t type
          py/runtime.h - includes mpstate.h and hence nlr.h, obj.h, runtime0.h,
              and defines everything to use the general runtime support functions
      
      Additional, specific headers (eg py/objlist.h) can be included if needed.
      a3dc1b19
  10. Sep 22, 2017
  11. Jul 31, 2017
  12. Jul 18, 2017
  13. Jul 03, 2017
  14. Jun 09, 2017
    • Damien George's avatar
      py: Provide mp_decode_uint_skip() to help reduce stack usage. · a8a5d1e8
      Damien George authored
      Taking the address of a local variable leads to increased stack usage, so
      the mp_decode_uint_skip() function is added to reduce the need for taking
      addresses.  The changes in this patch reduce stack usage of a Python call
      by 8 bytes on ARM Thumb, by 16 bytes on non-windowing Xtensa archs, and by
      16 bytes on x86-64.  Code size is also slightly reduced on most archs by
      around 32 bytes.
      a8a5d1e8
  15. May 29, 2017
  16. May 25, 2017
  17. Apr 22, 2017
    • Damien George's avatar
      py: Add LOAD_SUPER_METHOD bytecode to allow heap-free super meth calls. · dd11af20
      Damien George authored
      This patch allows the following code to run without allocating on the heap:
      
          super().foo(...)
      
      Before this patch such a call would allocate a super object on the heap and
      then load the foo method and call it right away.  The super object is only
      needed to perform the lookup of the method and not needed after that.  This
      patch makes an optimisation to allocate the super object on the C stack and
      discard it right after use.
      
      Changes in code size due to this patch are:
      
         bare-arm: +128
          minimal: +232
         unix x64: +416
      unix nanbox: +364
           stmhal: +184
          esp8266: +340
           cc3200: +128
      dd11af20
  18. Mar 26, 2017
  19. Mar 24, 2017
  20. Mar 23, 2017
  21. Mar 20, 2017
  22. Mar 17, 2017
    • Damien George's avatar
      py: Provide mp_decode_uint_value to help optimise stack usage. · 5640e6da
      Damien George authored
      This has a noticeable improvement on x86-64 and Thumb2 archs, where stack
      usage is reduced by 2 machine words in the VM.
      5640e6da
    • Damien George's avatar
      py: Reduce size of mp_code_state_t structure. · 71a3d6ec
      Damien George authored
      Instead of caching data that is constant (code_info, const_table and
      n_state), store just a pointer to the underlying function object from which
      this data can be derived.
      
      This helps reduce stack usage for the case when the mp_code_state_t
      structure is stored on the stack, as well as heap usage when it's stored
      on the heap.
      
      The downside is that the VM becomes a little more complex because it now
      needs to derive the data from the underlying function object.  But this
      doesn't impact the performance by much (if at all) because most of the
      decoding of data is done outside the main opcode loop.  Measurements using
      pystone show that little to no performance is lost.
      
      This patch also fixes a nasty bug whereby the bytecode can be reclaimed by
      the GC during execution.  With this patch there is always a pointer to the
      function object held by the VM during execution, since it's stored in the
      mp_code_state_t structure.
      71a3d6ec
  23. Feb 16, 2017
  24. Feb 15, 2017
  25. Jan 27, 2017
  26. Sep 27, 2016
    • Damien George's avatar
    • Damien George's avatar
      py: Only store the exception instance on Py stack in bytecode try block. · f040685b
      Damien George authored
      When an exception is raised and is to be handled by the VM, it is stored
      on the Python value stack so the bytecode can access it.  CPython stores
      3 objects on the stack for each exception: exc type, exc instance and
      traceback.  uPy followed this approach, but it turns out not to be
      necessary.  Instead, it is enough to store just the exception instance on
      the Python value stack.  The only place where the 3 values are needed
      explicitly is for the __exit__ handler of a with-statement context, but
      for these cases the 3 values can be extracted from the single exception
      instance.
      
      This patch removes the need to store 3 values on the stack, and instead
      just stores the exception instance.
      
      Code size is reduced by about 50-100 bytes, the compiler and VM are
      slightly simpler, generate bytecode is smaller (by 2 bytes for each try
      block), and the Python value stack is reduced in size for functions that
      handle exceptions.
      f040685b
  27. Sep 19, 2016
    • Damien George's avatar
      py: Combine 3 comprehension opcodes (list/dict/set) into 1. · adaf0d86
      Damien George authored
      With the previous patch combining 3 emit functions into 1, it now makes
      sense to also combine the corresponding VM opcodes, which is what this
      patch does.  This eliminates 2 opcodes which simplifies the VM and reduces
      code size, in bytes: bare-arm:44, minimal:64, unix(NDEBUG,x86-64):272,
      stmhal:92, esp8266:200.  Profiling (with a simple script that creates many
      list/dict/set comprehensions) shows no measurable change in performance.
      adaf0d86
  28. Aug 27, 2016
Loading