Skip to content

Commit f8e9c70

Browse files
committed
a few more fixes/tests
1 parent e25a63a commit f8e9c70

File tree

4 files changed

+45
-29
lines changed

4 files changed

+45
-29
lines changed

src/rp2_common/pico_double/double_aeabi_rp2040.S

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -650,17 +650,11 @@ regular_func double2fix_z
650650
// adjust
651651
adds r3, r2
652652
ble 2f // adjusted input is zero or dedornmal or < 1
653-
lsrs r2, r3, #11
653+
lsrs r3, r3, #11
654654
bne 3f // adjusted input is > infinite
655655

656-
// put updated exponent back in double and convert to int
657-
movs r2, #1
658-
lsls r2, #11
659-
subs r2, #1
660-
lsls r2, #20
661-
bics r1, r2
662-
lsls r3, #20
663-
orrs r1, r3
656+
lsls r2, r2, #20 // align exponent adjustment offset
657+
adds r1, r1, r2 // we know adjustment is safe
664658
b double2int_z
665659
2:
666660
// result is zero

src/rp2_common/pico_double/double_conv_m33.S

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,11 +259,11 @@ regular_func double2int64
259259
beq 2f // input zero or denormal, means answer remains zero
260260
sub r3, #0x3ff
261261
cmp r3, #0
262-
blt 1f // modified input zero or denormal, or less than 1.0
262+
blt 1f // input is less than 1.0
263263
cmp r3, #52
264264
bge double2int64_z // modified input must be an integer or infinite
265265
adds r3, #12
266-
lsls r2, r1, r3 // ip has remaining fractional mantissa bits of r1
266+
lsls r2, r1, r3 // r2 has remaining fractional mantissa bits of r1
267267
bne 1f // not integer as non zero fractional bits remain
268268
subs r3, #32
269269
bics r3, r3, r3, asr #31 // map negative shift to zero

src/rp2_common/pico_float/float_aeabi_dcp.S

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -160,19 +160,21 @@ regular_func float2fix_z
160160
ubfx r2, r0, #23, #8
161161
cbz r2, 2f // input is zero or denormal
162162
cmp r2, #0xff
163-
beq 1f // infinte just pass thru
163+
beq 3f // input infinite or nan
164164
adds r2, r1
165-
asrs r3, r2, #8
166-
beq 1f // exponent in range
167-
ite pl
168-
movpl r2, #0xff
169-
movmi r2, #0
165+
ble 2f // modified input is denormal so zero
166+
cmp r2, #0xff
167+
beq 3f // modified input is infinite
170168
1:
171169
bfi r0, r2, #23, #8
172170
b float2int_z_entry
173171
2:
174172
movs r0, #0
175173
bx lr
174+
3:
175+
mvn r1, #0x80000000
176+
add r0, r1, r0, lsr#31 @ so -Inf → 0x80000000, +Inf → 0x7fffffff
177+
bx lr
176178

177179
float_wrapper_section __aeabi_f2iz
178180
saving_func wrapper __aeabi_f2iz float2int_z
@@ -187,19 +189,20 @@ regular_func float2ufix_z
187189
ubfx r2, r0, #23, #8
188190
cbz r2, 2f // input is zero or denormal
189191
cmp r2, #0xff
190-
beq 1f // infinte just pass thru
192+
beq 3f // input infinite or nan
191193
adds r2, r1
192-
asrs r3, r2, #8
193-
beq 1f // exponent in range
194-
ite pl
195-
movpl r2, #0xff
196-
movmi r2, #0
194+
ble 2f // modified input is denormal so zero
195+
cmp r2, #0xff
196+
beq 3f // modified input is infinite
197197
1:
198198
bfi r0, r2, #23, #8
199199
b float2uint_z_entry
200200
2:
201201
movs r0, #0
202202
bx lr
203+
3:
204+
mvn r0, r0, asr #31
205+
bx lr
203206

204207
float_wrapper_section __aeabi_f2uiz
205208
saving_func wrapper __aeabi_f2uiz float2uint_z float2uint
@@ -213,19 +216,21 @@ saving_func regular float2fix
213216
ubfx r2, r0, #23, #8
214217
cbz r2, 2f // input is zero or denormal
215218
cmp r2, #0xff
216-
beq 1f // infinte just pass thru
219+
beq 3f // input infinite or nan
217220
adds r2, r1
218-
asrs r3, r2, #8
219-
beq 1f // exponent in range
220-
ite pl
221-
movpl r2, #0xff
222-
movmi r2, #0
221+
ble 2f // modified input is denormal so zero
222+
cmp r2, #0xff
223+
beq 3f // modified input is infinite
223224
1:
224225
bfi r0, r2, #23, #8
225226
b float2int_entry
226227
2:
227228
movs r0, #0
228229
bx lr
230+
3:
231+
mvn r1, #0x80000000
232+
add r0, r1, r0, lsr#31 @ so -Inf → 0x80000000, +Inf → 0x7fffffff
233+
bx lr
229234

230235
float_section float2int
231236
// (not a real thing - kept because we use wrapper in saving_func)

test/pico_float_test/custom_float_funcs_test.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ int test() {
110110
// todo test correct rounding around maximum precision
111111
test_checkf(uint642float(UINT64_MAX), 18446744073709551615.0f, "uint642float7");
112112

113+
union {
114+
uint32_t u;
115+
float f;
116+
} u32f;
117+
113118
#if !(LIB_PICO_FLOAT_COMPILER || defined(__riscv))
114119
printf("fix2float\n");
115120
// todo test correct rounding around maximum precision
@@ -154,6 +159,10 @@ int test() {
154159
test_checki(float2fix(-3.25f, 2), -13, "float2fix9");
155160
test_checki(float2fix(-0.75f, 1), -2, "float2fix10");
156161
test_checki(float2fix(-3.0f, -1), -2, "float2fix11"); // not very useful
162+
u32f.u = 0x7f012345;
163+
test_checki(float2fix(u32f.f, 1), INT32_MAX, "float2fix12");
164+
u32f.u = 0xff012345;
165+
test_checki(float2fix(u32f.f, 1), INT32_MIN, "float2fix13");
157166

158167
printf("float2ufix\n");
159168
test_checku(float2ufix(3.5f, 8), 0x380, "float2ufix1");
@@ -203,6 +212,10 @@ int test() {
203212
test_checki(float2fix_z(-3.25f, 2), -13, "float2fix_z9");
204213
test_checki(float2fix_z(-0.75f, 1), -1, "float2fix_z10");
205214
test_checki(float2fix_z(-3.0f, -1), -1, "float2fix_z11"); // not very useful
215+
u32f.u = 0x7f012345;
216+
test_checki(float2fix_z(u32f.f, 1), INT32_MAX, "float2fix_z12");
217+
u32f.u = 0xff012345;
218+
test_checki(float2fix_z(u32f.f, 1), INT32_MIN, "float2fix_z13");
206219

207220
printf("float2ufix_z\n");
208221
test_checku(float2ufix_z(3.5f, 8), 0x380, "float2ufix_z1");
@@ -213,6 +226,10 @@ int test() {
213226
test_checku(float2ufix_z(3.24999f, 2), 12, "float2ufix_z6");
214227
test_checku(float2ufix_z(3.25f, 2), 13, "float2ufix_z7");
215228
test_checku(float2ufix_z(3.0f, -1), 1, "float2ufix_z8"); // not very useful
229+
u32f.u = 0x7f012345;
230+
test_checku(float2ufix_z(u32f.f, 1), UINT32_MAX, "float2fix_z9");
231+
u32f.u = 0xff012345;
232+
test_checku(float2ufix_z(u32f.f, 1), 0, "float2fix_z10");
216233

217234
printf("float2fix64_z\n");
218235
test_checki64(float2fix64_z(3.5f, 8), 0x380, "float2fix64_z1");

0 commit comments

Comments
 (0)