forked from micropython/micropython
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
py/inlinethumb: Support for core floating point instructions.
Adds support for the following Thumb2 VFP instructions, via the option MICROPY_EMIT_INLINE_THUMB_FLOAT: vcmp vsqrt vneg vcvt_f32_to_s32 vcvt_s32_to_f32 vmrs vmov vldr vstr vadd vsub vmul vdiv
- Loading branch information
1 parent
d8cbbca
commit 5008972
Showing
12 changed files
with
219 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
@micropython.asm_thumb # r0 = r0+r1-r2 | ||
def add_sub(r0, r1, r2): | ||
vmov(s0, r0) | ||
vcvt_f32_s32(s0, s0) | ||
vmov(s1, r1) | ||
vcvt_f32_s32(s1, s1) | ||
vmov(s2, r2) | ||
vcvt_f32_s32(s2, s2) | ||
vadd(s0, s0, s1) | ||
vsub(s0, s0, s2) | ||
vcvt_s32_f32(s31, s0) | ||
vmov(r0, s31) | ||
|
||
print(add_sub(100, 20, 30)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
90 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
@micropython.asm_thumb # test vcmp, vmrs | ||
def f(r0, r1): | ||
vmov(s0, r0) | ||
vcvt_f32_s32(s0, s0) | ||
vmov(s1, r1) | ||
vcvt_f32_s32(s1, s1) | ||
vcmp(s1, s0) | ||
vmrs(r0, FPSCR) | ||
mov(r1, 28) | ||
lsr(r0, r1) | ||
|
||
print(f(0,1)) | ||
print(f(1,1)) | ||
print(f(1,0)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
2 | ||
6 | ||
8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import array | ||
@micropython.asm_thumb # test vldr, vstr | ||
def arrayadd(r0): | ||
vldr(s0, [r0, 0]) | ||
vldr(s1, [r0, 1]) | ||
vadd(s2, s0, s1) | ||
vstr(s2, [r0, 2]) | ||
|
||
z = array.array("f", [2, 4, 10]) | ||
arrayadd(z) | ||
print(z[2]) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
6.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
@micropython.asm_thumb # r0 = (int)(r0*r1/r2) | ||
def muldiv(r0, r1, r2): | ||
vmov(s0, r0) | ||
vcvt_f32_s32(s0, s0) | ||
vmov(s1, r1) | ||
vcvt_f32_s32(s1, s1) | ||
vmov(s2, r2) | ||
vcvt_f32_s32(s2, s2) | ||
vmul(s7, s0, s1) | ||
vdiv(s8, s7, s2) | ||
vcvt_s32_f32(s31, s8) | ||
vmov(r0, s31) | ||
|
||
print(muldiv(100, 10, 50)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
20 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# test vsqrt, vneg | ||
@micropython.asm_thumb # r0 = -(int)(sqrt(r0)*r1) | ||
def sqrt_test(r0, r1): | ||
vmov(s1, r0) | ||
vcvt_f32_s32(s1, s1) | ||
vsqrt(s1, s1) | ||
vmov(s2, r1) | ||
vcvt_f32_s32(s2, s2) | ||
vmul(s0, s1, s2) | ||
vneg(s7, s0) | ||
vcvt_s32_f32(s31, s7) | ||
vmov(r0, s31) | ||
|
||
print(sqrt_test(256, 10)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
-160 |