summaryrefslogtreecommitdiff
path: root/py/asmarm.c
AgeCommit message (Collapse)Author
2025-07-01py/asmarm: Implement the full set of Viper load/store operations.Alessandro Gatti
This commit expands the implementation of Viper load/store operations that are optimised for the Arm platform. Now both load and store emitters should generate the shortest possible sequence in all cases. Redundant specialised operation emitters have been folded into the general case implementation - this was the case of integer-indexed load/store operations with a fixed offset of zero. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2025-06-10py/asmarm: Give a proper name to the temporary register.Alessandro Gatti
This commit performs a small refactoring on the Arm native emitter, by renaming all but one instance of ASM_ARM_REG_R8 into REG_TEMP. ASM_ARM_REG_R8 is the temporary register used by the emitter when operations cannot overwrite the value of a particular register and some extra storage is needed. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2025-06-10py/asmarm: Extend int-indexed 32-bit load/store offset ranges.Alessandro Gatti
This commit extends the range for int-indexed load/store opcode generators, making them emit correct code sequences for offsets that span more than 12 bits. This is necessary due to those generator bits being also used in the Viper emitter, where it's more probable to reference offsets that can not be embedded in the LDR/STR opcodes. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2025-05-21py/emitnative: Improve Viper register-indexed code for Arm.Alessandro Gatti
This commit lets the Viper code generator use optimised code sequences for register-indexed load and store operations when generating Arm code. The existing code defaulted to generic multi-operations code sequences for Arm code on most cases. Now optimised implementations are provided for register-indexed loads and stores of all data sizes, taking at most two machine opcodes for each operation. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2025-01-16py/asmarm: Fix halfword loads with larger offsets.Alessandro Gatti
This commit fixes code generation for loading halfwords using an offset greater than 255. The old code blindly encoded the offset into a `LDRH Rd, [Rn, #imm]` opcode, but only the lowest 8 bits would be put into the opcode itself. This commit instead generates a two-opcodes sequence, a constant load into R8, and then `LDRH Rd, [Rn, R8]`. This fixes `tests/extmod/vfs_rom.py` for the qemu/SABRELITE board. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2025-01-16py/asmarm: Fix locals address loading code generation with large imm.Alessandro Gatti
This commit fixes code generation for loading a local's address if its index is greater than 63. The old code blindly encoded the offset into an `ADD Rd, Rn, #imm` opcode, but only the lowest 8 bits would be put into the opcode itself. This commit instead generates a two-opcodes sequence, a constant load into R8, and then an `ADD Rd, Rn, R8` opcode. This fixes `tests/float/math_domain.py` for the qemu/SABRELITE board. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2025-01-06py/asmarm: Allow function state to be larger than 255.Damien George
Co-authored-by: Alessandro Gatti <a.gatti@frob.it> Signed-off-by: Damien George <damien@micropython.org>
2025-01-06py/asmarm: Fix asm_arm_ldrh_reg_reg_offset to emit correct machine code.Damien George
Prior to this fix, the assembler generated `LDRH Rd, [Rn, #imm]!`, so the second `LDRH` from the same origin would load from the wrong base. Co-authored-by: Alessandro Gatti <a.gatti@frob.it> Signed-off-by: Damien George <damien@micropython.org>
2024-03-19py/asm: Add ASM_NOT_REG and ASM_NEG_REG macros for unary ops.Damien George
ASM_NOT_REG is optional, it can be synthesised by xor(reg, -1). ASM_NEG_REG can also be synthesised with a subtraction, but most architectures have a dedicated instruction for it. Signed-off-by: Damien George <damien@micropython.org>
2024-03-07all: Remove the "STATIC" macro and just use "static" instead.Angus Gratton
The STATIC macro was introduced a very long time ago in commit d5df6cd44a433d6253a61cb0f987835fbc06b2de. The original reason for this was to have the option to define it to nothing so that all static functions become global functions and therefore visible to certain debug tools, so one could do function size comparison and other things. This STATIC feature is rarely (if ever) used. And with the use of LTO and heavy inline optimisation, analysing the size of individual functions when they are not static is not a good representation of the size of code when fully optimised. So the macro does not have much use and it's simpler to just remove it. Then you know exactly what it's doing. For example, newcomers don't have to learn what the STATIC macro is and why it exists. Reading the code is also less "loud" with a lowercase static. One other minor point in favour of removing it, is that it stops bugs with `STATIC inline`, which should always be `static inline`. Methodology for this commit was: 1) git ls-files | egrep '\.[ch]$' | \ xargs sed -Ei "s/(^| )STATIC($| )/\1static\2/" 2) Do some manual cleanup in the diff by searching for the word STATIC in comments and changing those back. 3) "git-grep STATIC docs/", manually fixed those cases. 4) "rg -t python STATIC", manually fixed codegen lines that used STATIC. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2022-05-23py/asmarm: Add asm_arm_ldrh_reg_reg_offset() helper func.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2021-06-05py/emitglue: Always flush caches when assigning native ARM code.Damien George
Prior to this commit, cache flushing for ARM native code was done only in the assembler code asm_thumb_end_pass()/asm_arm_end_pass(), at the last pass of the assembler. But this misses flushing the cache when loading native code from an .mpy file, ie in persistentcode.c. The change here makes sure the cache is always flushed/cleaned/invalidated when assigning native code on ARM architectures. This problem was found running tests/micropython/import_mpy_native_gc.py on the mimxrt port. Signed-off-by: Damien George <damien@micropython.org>
2021-05-26py/asmarm: Use builtin func to flush I- and D-cache on ARM 7 archs.Damien George
The inline assembler code does not work for __ARM_ARCH == 7. Signed-off-by: Damien George <damien@micropython.org>
2020-06-27py/asm: Add funcs/macros to emit machine code for logical-shift-right.Damien George
Signed-off-by: Damien George <damien@micropython.org>
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.
2019-07-12py/asmarm: Use __builtin___clear_cache instead of __clear_cache.David Lechner
__clear_cache causes a compile error when using clang. Instead use __builtin___clear_cache which is available under both gcc and clang. Also replace tabs with spaces in this section of code (introduced by a previous commit).
2019-07-03py/asmarm: Use __clear_cache on Linux/GCC when creating new asm code.David Lechner
Comes from https://community.arm.com/developer/ip-products/processors/b/processors-ip-blog/posts/caches-and-self-modifying-code This fixes a crash when running MicroPython using qemu-arm.
2019-03-08py: Add support to save native, viper and asm code to .mpy files.Damien George
This commit adds support for saving and loading .mpy files that contain native code (native, viper and inline-asm). A lot of the ground work was already done for this in the form of removing pointers from generated native code. The changes here are mainly to link in qstr values to the native code, and change the format of .mpy files to contain native code blocks (possibly mixed with bytecode). A top-level summary: - @micropython.native, @micropython.viper and @micropython.asm_thumb/ asm_xtensa are now allowed in .py files when compiling to .mpy, and they work transparently to the user. - Entire .py files can be compiled to native via mpy-cross -X emit=native and for the most part the generated .mpy files should work the same as their bytecode version. - The .mpy file format is changed to 1) specify in the header if the file contains native code and if so the architecture (eg x86, ARMV7M, Xtensa); 2) for each function block the kind of code is specified (bytecode, native, viper, asm). - When native code is loaded from a .mpy file the native code must be modified (in place) to link qstr values in, just like bytecode (see py/persistentcode.c:arch_link_qstr() function). In addition, this now defines a public, native ABI for dynamically loadable native code generated by other languages, like C.
2018-10-13py/asmarm: Simplify asm_arm_bl_ind to only load via index, not literal.Damien George
The maximum index into mp_fun_table is currently less than 1024 and should stay that way to keep things efficient for all architectures, so there is no need to handle loading the pointer directly via a literal in this function.
2018-08-16py/asm*: Support assembling code to jump to a register, and get PC+off.Damien George
Useful for position independent code, and implementing state machines.
2018-02-24py/asm*.c: Remove unnecessary check for num_locals<0 in asm entry func.Damien George
All callers of the asm entry function guarantee that num_locals>=0, so no need to add an explicit check for it. Use an assertion instead. Also, the signature of asm_x86_entry is changed to match the other asm entry functions.
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-19all: Remove trailing spaces, per coding conventions.Damien George
2017-01-03py/asmarm: Fix assembler's PASS_EMIT constant name.Damien George
2016-12-09py/asm: Fix x86 and ARM assemblers due to recent code refactoring.Damien George
2016-12-09py/asm: Remove need for dummy_data when doing initial assembler passes.Damien George
For all but the last pass the assembler only needs to count how much space is needed for the machine code, it doesn't actually need to emit anything. The dummy_data just uses unnecessary RAM and without it the code is not any more complex (and code size does not increase for Thumb and Xtensa archs).
2016-11-28py: Factor out common code from assemblers into asmbase.[ch].Damien George
All assemblers should "derive" from mp_asm_base_t.
2015-06-04py: Implement native multiply operation in viper emitter.Damien George
2015-05-08emitnative: Revamp ARM codegen compile after full-arg support refactors.Paul Sokolovsky
The code was apparently broken after 9988618e0e0f5c319e31b135d993e22efb593093 "py: Implement full func arg passing for native emitter.". This attempts to propagate those changes to ARM emitter.
2015-04-09py: Adjust some spaces in code style/format, purely for consistency.Damien George
2015-01-14py: Allocate memory for assembled code at start of PASS_EMIT.Damien George
Previously was allocating at end of PASS_COMPUTE, and this pass was being run twice, so memory was being allocated twice.
2015-01-01py: Move to guarded includes, everywhere in py/ core.Damien George
Addresses issue #1022.
2014-12-14asmarm: Fix bug with encoding small negative ints using MVN instruction.Paul Sokolovsky
2014-10-12py: Implement native load for viper.Damien George
Viper can now do: ptr8(buf)[0], which loads a byte from a buffer using machine instructions.
2014-10-12py: Implement and,or,xor native ops for viper.Damien George
2014-10-04Implement missing ARM emitter functions for viperFabian Vogt
2014-09-29py: Implement more binary ops for viper emitter.Damien George
This included a bit of restructuring of the assembler backends. Note that the ARM backend is missing a few functions and won't compile.
2014-09-29py: Make macro names in assemblers consistent, and tidy up a bit.Damien George
2014-09-15py: Make asm_arm_less_op take destination register as first arg.Damien George
This gets ARM native emitter working againg and addresses issue #858.
2014-09-03Code style/whitespace cleanup; remove obsolete headers.Damien George
And move the MAP_ANON redefinition from py/asmx64.c to unix/alloc.c.
2014-09-03Add cache flush in py/asmarm.c and add new MP_PLAT_ALLOC_EXEC and ↵Fabian Vogt
MP_PLAT_FREE_EXEC macros Fixes issue #840
2014-08-28Clarify copyright on asmarm filesFabian Vogt
2014-08-27Basic native ARM emitterFabian Vogt