aboutsummaryrefslogtreecommitdiff
path: root/py/objint_mpz.c
AgeCommit message (Collapse)Author
2022-05-03all: Use mp_obj_malloc everywhere it's applicable.Jim Mussared
This replaces occurences of foo_t *foo = m_new_obj(foo_t); foo->base.type = &foo_type; with foo_t *foo = mp_obj_malloc(foo_t, &foo_type); Excludes any places where base is a sub-field or when new0/memset is used. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2020-11-11py/mpz: Do sign extension in mpz_as_bytes for negative values.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2020-05-28py/modsys: Use consistent naming pattern for module-level const objects.David Lechner
This renames a few identifiers to follow the usual naming convention of mp_<module>_<name>. This makes them easier to find, e.g. when grep'ing.
2020-04-05all: Use MP_ERROR_TEXT for all error messages.Jim Mussared
2020-03-28all: Remove spaces inside and around parenthesis.Damien George
Using new options enabled in the uncrustify configuration.
2020-02-28all: Reformat C and Python source code with tools/codeformat.py.Damien George
This is run with uncrustify 0.70.1, and black 19.10b0.
2020-02-28all: Add *FORMAT-OFF* in various places.Damien George
This string is recognised by uncrustify, to disable formatting in the region marked by these comments. This is necessary in the qstrdef*.h files to prevent modification of the strings within the Q(...). In other places it is used to prevent excessive reformatting that would make the code less readable.
2020-02-28py: Un-nest configuration #if/#endif's for selection of complex code.Damien George
Because un-nested #if's are simpler to handle with formatting tools.
2020-02-28py: Removing dangling "else" to improve code format consistency.Damien George
2020-01-14py/objint: Add mp_obj_int_get_uint_checked() helper.Yonatan Goldschmidt
Can be used where mp_obj_int_get_checked() will overflow due to the sign-bit solely. This returns an mp_uint_t, so it also verifies the given integer is not negative. Currently implemented only for mpz configurations.
2019-05-06py: remove "if (0)" and "if (false)" branches.Jun Wu
Prior to this commit, building the unix port with `DEBUG=1` and `-finstrument-functions` the compilation would fail with an error like "control reaches end of non-void function". This change fixes this by removing the problematic "if (0)" branches. Not all branches affect compilation, but they are all removed for consistency.
2019-02-12py: Downcase all MP_OBJ_IS_xxx macros to make a more consistent C API.Damien George
These macros could in principle be (inline) functions so it makes sense to have them lower case, to match the other C API functions. The remaining macros that are upper case are: - MP_OBJ_TO_PTR, MP_OBJ_FROM_PTR - MP_OBJ_NEW_SMALL_INT, MP_OBJ_SMALL_INT_VALUE - MP_OBJ_NEW_QSTR, MP_OBJ_QSTR_VALUE - MP_OBJ_FUN_MAKE_SIG - MP_DECLARE_CONST_xxx - MP_DEFINE_CONST_xxx These must remain macros because they are used when defining const data (at least, MP_OBJ_NEW_SMALL_INT is so it makes sense to have MP_OBJ_SMALL_INT_VALUE also a macro). For those macros that have been made lower case, compatibility macros are provided for the old names so that users do not need to change their code immediately.
2018-09-20py: Shorten error messages by using contractions and some rewording.Damien George
2018-04-05py/objint: Simplify LHS arg type checking in int binary op functions.Damien George
The LHS passed to mp_obj_int_binary_op() will always be an integer, either a small int or a big int, so the test for this type doesn't need to include an "other, unsupported type" case.
2017-11-24py/runtime: Add MP_BINARY_OP_CONTAINS as reverse of MP_BINARY_OP_IN.Damien George
Before this patch MP_BINARY_OP_IN had two meanings: coming from bytecode it meant that the args needed to be swapped, but coming from within the runtime meant that the args were already in the correct order. This lead to some confusion in the code and comments stating how args were reversed. It also lead to 2 bugs: 1) containment for a subclass of a native type didn't work; 2) the expression "{True} in True" would illegally succeed and return True. In both of these cases it was because the args to MP_BINARY_OP_IN ended up being reversed twice. To fix these things this patch introduces MP_BINARY_OP_CONTAINS which corresponds exactly to the __contains__ special method, and this is the operator that built-in types should implement. MP_BINARY_OP_IN is now only emitted by the compiler and is converted to MP_BINARY_OP_CONTAINS by swapping the arguments.
2017-10-04all: Remove inclusion of internal py header files.Damien George
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.
2017-09-18py/modbuiltins: Implement abs() by dispatching to MP_UNARY_OP_ABS.Paul Sokolovsky
This allows user classes to implement __abs__ special method, and saves code size (104 bytes for x86_64), even though during refactor, an issue was fixed and few optimizations were made: * abs() of minimum (negative) small int value is calculated properly. * objint_longlong and objint_mpz avoid allocating new object is the argument is already non-negative.
2017-09-08py/runtime0.h: Put inplace arith ops in front of normal operations.Paul Sokolovsky
This is to allow to place reverse ops immediately after normal ops, so they can be tested as one range (which is optimization for reverse ops introduction in the next patch).
2017-09-07py/runtime0.h: Move relational ops to the beginning of mp_binary_op_t.Paul Sokolovsky
This is to allow to encode arithmetic operations more efficiently, in preparation to introduction of __rOP__ method support.
2017-08-29all: Convert mp_uint_t to mp_unary_op_t/mp_binary_op_t where appropriateDamien George
The unary-op/binary-op enums are already defined, and there are no arithmetic tricks used with these types, so it makes sense to use the correct enum type for arguments that take these values. It also reduces code size quite a bit for nan-boxing builds.
2017-07-31all: Use the name MicroPython consistently in commentsAlexander Steffen
There were several different spellings of MicroPython present in comments, when there should be only one.
2017-07-25py: Implement raising a big-int to a negative power.Damien George
Before this patch raising a big-int to a negative power would just return 0. Now it returns a floating-point number with the correct value.
2017-04-21extmod/moductypes: Fix bigint handling for 32-bit ports.Paul Sokolovsky
2017-04-04py/objint: Consolidate mp_obj_new_int_from_float to one implementation.Damien George
This reduces code duplication and allows to make mp_classify_fp_as_int static, which reduces code size.
2017-03-28py: Use mp_raise_TypeError/mp_raise_ValueError helpers where possible.Damien George
Saves 168 bytes on bare-arm.
2017-02-16py/objint: Convert mp_uint_t to size_t where appropriate.Damien George
2017-02-02py: Added optimised support for 3-argument calls to builtin.pow()Nicko van Someren
Updated modbuiltin.c to add conditional support for 3-arg calls to pow() using MICROPY_PY_BUILTINS_POW3 config parameter. Added support in objint_mpz.c for for optimised implementation.
2017-01-21py/objint: from_bytes(): Implement "byteorder" param and arbitrary precision.Paul Sokolovsky
If result guaranteedly fits in a small int, it is handled in objint.c. Otherwise, it is delegated to mp_obj_int_from_bytes_impl(), which should be implemented by individual objint_*.c, similar to mp_obj_int_to_bytes_impl().
2017-01-19py/objint_mpz: Refactor switch-statement to remove unreachable default.Damien George
2016-12-21py/objint: Rename mp_obj_int_as_float to mp_obj_int_as_float_impl.Damien George
And also simplify it to remove the check for small int. This can be done because this function is only ever called if the argument is not a small int.
2016-10-17py: Use mp_raise_msg helper function where appropriate.Damien George
Saves the following number of bytes of code space: 176 for bare-arm, 352 for minimal, 272 for unix x86-64, 140 for stmhal, 120 for esp8266.
2016-10-11py/objint: Use size_t for arguments that measure bytes/sizes.Damien George
2016-10-11py: Factor duplicated function to calculate size of formatted int.Damien George
2016-05-08py/mpz: Do Python style division/modulo within bignum divmod routine.Damien George
This patch consolidates the Python logic for division/modulo to one place within the bignum code.
2016-03-10py: Use MP_SMALL_INT_POSITIVE_MASK to check if uint fits in a small int.Damien George
Using the original WORD_MSBIT_HIGH-logic resulted in errors when the object model is not REPR_A or REPR_C.
2016-01-07py: Change mp_obj_int_is_positive to more general mp_obj_int_sign.Damien George
This function returns the sign (-1, 0 or 1) of the integer object.
2015-11-29py: Wrap all obj-ptr conversions in MP_OBJ_TO_PTR/MP_OBJ_FROM_PTR.Damien George
This allows the mp_obj_t type to be configured to something other than a pointer-sized primitive type. This patch also includes additional changes to allow the code to compile when sizeof(mp_uint_t) != sizeof(void*), such as using size_t instead of mp_uint_t, and various casts.
2015-10-20py: Add mp_obj_is_float function (macro) and use it where appropriate.Damien George
2015-10-11py: Rename MP_BOOL() to mp_obj_new_bool() for consistency in naming.Paul Sokolovsky
2015-10-01py: Catch all cases of integer (big and small) division by zero.Damien George
2015-09-15py/mpz: Fix calculation of max digit storage for mpz; fix sys.maxsize.Damien George
When creating constant mpz's, the length of the mpz must be exactly how many digits are used (not allocated) otherwise these numbers are not compatible with dynamically allocated numbers. Addresses issue #1448.
2015-06-13py: Implement divmod for mpz bignum.Damien George
2015-05-12py: Convert hash API to use MP_UNARY_OP_HASH instead of ad-hoc function.Damien George
Hashing is now done using mp_unary_op function with MP_UNARY_OP_HASH as the operator argument. Hashing for int, str and bytes still go via fast-path in mp_unary_op since they are the most common objects which need to be hashed. This lead to quite a bit of code cleanup, and should be more efficient if anything. It saves 176 bytes code space on Thumb2, and 360 bytes on x86. The only loss is that the error message "unhashable type" is now the more generic "unsupported type for __hash__".
2015-04-25py: Support conversion of bignum to bytes.Damien George
This gets int.to_bytes working for bignum, and also struct.pack with 'q' and 'Q' args on 32-bit machines. Addresses issue #1155.
2015-04-22py/objint_mpz.c: Make int_from_uint actually return uint.Damien George
2015-03-14py: Fix builtin abs so it works for bools and bignum.Damien George
2015-01-24py: Use float-to-int classifications for mp_obj_new_int_from_float() functionsDavid Steinberg
2015-01-07py: Temporary fix for conversion of float to int when fits in small int.Damien George
Addresses issue #1044 (see also #1040). Could do with a better fix.
2015-01-02py: Raise exception if trying to convert inf/nan to int.Damien George
2015-01-02py: Fix float to int conversion for large exponents.David Steinberg