Faster Array Element Assignment - Solved
Posted: Mon Jan 10, 2022 1:58 am
Looking for the faster way to assign elements to a small array. Is there an native way to do this? arry[0:2] <-- 100,200,300
The idea is that the values 100,200,300 would be constantly changing.
Here is a way for 1-3 elements that is up to 1.45x faster than the traditional way.
The asm_thumb is limited to 4 parameters so if there was a way to embed an array address in the code all four could be used.
Sam
The idea is that the values 100,200,300 would be constantly changing.
Here is a way for 1-3 elements that is up to 1.45x faster than the traditional way.
Code: Select all
import array
a=array.array('i',(0,0,0))
@micropython.asm_thumb
def array_asm(r0,r1,r2,r3): #r0=array, r1=value1, r2=value2, r3=value3
str(r1, [r0, 0]) # strh(r1, [r0, 0]) for 2 byte arrays, eg. 'h' or 'H'
str(r2, [r0, 4]) # strh(r2, [r0, 2])
str(r3, [r0, 8]) # strh(r2, [r0, 4])
array_asm(a,100,200,300)
#traditional way
a[0] = 100
a[1] = 200
a[2] = 300
Sam