Skip to content
Snippets Groups Projects
  1. Feb 01, 2018
  2. Jan 31, 2018
  3. Jan 10, 2018
  4. Dec 29, 2017
    • stijn's avatar
      42c4dd09
    • stijn's avatar
      py/nlr: Fix nlr functions for 64bit ports built with gcc on Windows · b184b6ae
      stijn authored
      The number of registers used should be 10, not 12, to match the assembly
      code in nlrx64.c. With this change the 64bit mingw builds don't need to
      use the setjmp implementation, and this fixes miscellaneous crashes and
      assertion failures as reported in #1751 for instance.
      
      To avoid mistakes in the future where something gcc-related for Windows
      only gets fixed for one particular compiler/environment combination,
      make use of a MICROPY_NLR_OS_WINDOWS macro.
      
      To make sure everything nlr-related is now ok when built with gcc this
      has been verified with:
      - unix port built with gcc on Cygwin (i686-pc-cygwin-gcc and
        x86_64-pc-cygwin-gcc, version 6.4.0)
      - windows port built with mingw-w64's gcc from Cygwin
       (i686-w64-mingw32-gcc and x86_64-w64-mingw32-gcc, version 6.4.0)
       and MSYS2 (like the ones on Cygwin but version 7.2.0)
      b184b6ae
    • stijn's avatar
      windows/mpconfigport: Enable some features, including the Python stack · 8041de59
      stijn authored
      Add some features which are already enabled in the unix port and
      default to using the Python stack for scoped allocations: this can be
      more performant in cases the heap is heavily used because for example
      the memory needed for storing *args and **kwargs doesn't require
      scanning the heap to find a free block.
      8041de59
    • stijn's avatar
      windows/mpconfigport: Provide off_t definition for MSVC port · 6fc58db5
      stijn authored
      For MSVC off_t is defined in sys/types.h but according to the comment
      earlier in mpconfigport.h this cannot be included directly.
      So just make off_t the same as mp_off_t.
      This fixes the build for MSVC with MICROPY_STREAMS_POSIX_API
      enabled because stream.h uses off_t.
      6fc58db5
    • Damien George's avatar
      py/mpz: In mpz_as_str_inpl, convert always-false checks to assertions. · e7842744
      Damien George authored
      There are two checks that are always false so can be converted to (negated)
      assertions to save code space and execution time.  They are:
      
      1. The check of the str parameter, which is required to be non-NULL as per
         the original comment that it has enough space in it as calculated by
         mp_int_format_size.  And for all uses of this function str is indeed
         non-NULL.
      
      2. The check of the base parameter, which is already required to be between
         2 and 16 (inclusive) via the assertion in mp_int_format_size.
      e7842744
    • Damien George's avatar
      py/mpz: Simplify handling of borrow and quo adjustment in mpn_div. · 9766fddc
      Damien George authored
      The motivation behind this patch is to remove unreachable code in mpn_div.
      This unreachable code was added some time ago in
      9a21d2e0, when a loop in mpn_div was copied
      and adjusted to work when mpz_dig_t was exactly half of the size of
      mpz_dbl_dig_t (a common case).  The loop was copied correctly but it wasn't
      noticed at the time that the final part of the calculation of num-quo*den
      could be optimised, and hence unreachable code was left for a case that
      never occurred.
      
      The observation for the optimisation is that the initial value of quo in
      mpn_div is either exact or too large (never too small), and therefore the
      subtraction of quo*den from num may subtract exactly enough or too much
      (but never too little).  Using this observation the part of the algorithm
      that handles the borrow value can be simplified, and most importantly this
      eliminates the unreachable code.
      
      The new code has been tested with DIG_SIZE=3 and DIG_SIZE=4 by dividing all
      possible combinations of non-negative integers with between 0 and 3
      (inclusive) mpz digits.
      9766fddc
    • Damien George's avatar
      py/parse: Fix macro evaluation by avoiding empty __VA_ARGS__. · c7cb1dfc
      Damien George authored
      Empty __VA_ARGS__ are not allowed in the C preprocessor so adjust the rule
      arg offset calculation to not use them.  Also, some compilers (eg MSVC)
      require an extra layer of macro expansion.
      c7cb1dfc
  5. Dec 28, 2017
    • Damien George's avatar
    • Damien George's avatar
      py/parse: Compress rule pointer table to table of offsets. · 0016a453
      Damien George authored
      This is the sixth and final patch in a series of patches to the parser that
      aims to reduce code size by compressing the data corresponding to the rules
      of the grammar.
      
      Prior to this set of patches the rules were stored as rule_t structs with
      rule_id, act and arg members.  And then there was a big table of pointers
      which allowed to lookup the address of a rule_t struct given the id of that
      rule.
      
      The changes that have been made are:
      - Breaking up of the rule_t struct into individual components, with each
        component in a separate array.
      - Removal of the rule_id part of the struct because it's not needed.
      - Put all the rule arg data in a big array.
      - Change the table of pointers to rules to a table of offsets within the
        array of rule arg data.
      
      The last point is what is done in this patch here and brings about the
      biggest decreases in code size, because an array of pointers is now an
      array of bytes.
      
      Code size changes for the six patches combined is:
      
         bare-arm:  -644
      minimal x86: -1856
         unix x64: -5408
      unix nanbox: -2080
            stm32:  -720
          esp8266:  -812
           cc3200:  -712
      
      For the change in parser performance: it was measured on pyboard that these
      six patches combined gave an increase in script parse time of about 0.4%.
      This is due to the slightly more complicated way of looking up the data for
      a rule (since the 9th bit of the offset into the rule arg data table is
      calculated with an if statement).  This is an acceptable increase in parse
      time considering that parsing is only done once per script (if compiled on
      the target).
      0016a453
    • Damien George's avatar
    • Damien George's avatar
    • Damien George's avatar
      py/parse: Pass rule_id to push_result_rule, instead of passing rule_t*. · 815a8cd1
      Damien George authored
      Reduces code size by eliminating quite a few pointer dereferences.
      815a8cd1
    • Damien George's avatar
      py/parse: Break rule data into separate act and arg arrays. · 845511af
      Damien George authored
      Instead of each rule being stored in ROM as a struct with rule_id, act and
      arg, the act and arg parts are now in separate arrays and the rule_id part
      is removed because it's not needed.  This reduces code size, by roughly one
      byte per grammar rule, around 150 bytes.
      845511af
    • Damien George's avatar
      py/parse: Split out rule name from rule struct into separate array. · 1039c5e6
      Damien George authored
      The rule name is only used for debugging, and this patch makes things a bit
      cleaner by completely separating out the rule name from the rest of the
      rule data.
      1039c5e6
    • Peter D. Gray's avatar
      stm32/spi: If MICROPY_HW_SPIn_MISO undefined, do not claim pin on init. · dfe8980a
      Peter D. Gray authored
      This permits output-only SPI use.
      dfe8980a
    • Damien George's avatar
      py/nlr: Factor out common NLR code to macro and generic funcs in nlr.c. · b25f9216
      Damien George authored
      Each NLR implementation (Thumb, x86, x64, xtensa, setjmp) duplicates a lot
      of the NLR code, specifically that dealing with pushing and popping the NLR
      pointer to maintain the linked-list of NLR buffers.  This patch factors all
      of that code out of the specific implementations into generic functions in
      nlr.c, along with a helper macro in nlr.h.  This eliminates duplicated
      code.
      b25f9216
    • Damien George's avatar
      py/nlr: Clean up selection and config of NLR implementation. · 5bf8e85f
      Damien George authored
      If MICROPY_NLR_SETJMP is not enabled and the machine is auto-detected then
      nlr.h now defines some convenience macros for the individual NLR
      implementations to use (eg MICROPY_NLR_THUMB).  This keeps nlr.h and the
      implementation in sync, and also makes the nlr_buf_t struct easier to read.
      5bf8e85f
    • Damien George's avatar
      py/nlrthumb: Fix use of naked funcs, must only contain basic asm code. · 97cc4855
      Damien George authored
      A function with a naked attribute must only contain basic inline asm
      statements and no C code.
      
      For nlr_push this means removing the "return 0" statement.  But for some
      gcc versions this induces a compiler warning so the __builtin_unreachable()
      line needs to be added.
      
      For nlr_jump, this function contains a combination of C code and inline asm
      so cannot be naked.
      97cc4855
Loading