Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions src/rp2_common/pico_double/double_aeabi_dcp.S
Original file line number Diff line number Diff line change
Expand Up @@ -203,23 +203,22 @@ double_section double2int
saving_func regular double2int
double2int_entry:
lsls r2, r1, #1
// r1 = abs(zero) => r1 = 0x00000000
// r1 = abs(denornaml) => r1 = 0x00.xxxxx
// r1 = abs(1.0f) => r1 = 0x7f800000
// r1 = abs(inf/nan) => r1 = 0xffXxxxxx
bcc double2int_z_entry // positive is ok for int64_z
orrs r3, r2, r0
beq double2int_z_entry // 0 or -0 is ok for int64_z
// r3 = last 3 bits of 23 significant bits of mantissa at position 32-23
lsrs r3, r0, #32 - 3
lsls r3, #9

lsrs r2, #21
adds r2, #1
subs r2, r2, #0x400
bcc 1f // <1 means subtract 1
// recreate the 23 significant bits of mantissa for float at the top of r3
adds r3, r3, r1, lsl #12
cmp r2, #52
bge double2int_z_entry // must be an integer
lsls r3, r1, #12
adds r3, r3, r0, lsr #20
// r3 now has highest 32 mantissa bits
lsls r3, r2
bne 1f // not integer as non zero fractional bits remain
lsls r3, r0, #12
lsls r3, r2
beq double2int_z_entry // integer
1:
Expand Down
22 changes: 18 additions & 4 deletions test/pico_float_test/custom_double_funcs_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,11 @@ int test() {
test_checku64(double2ufix64_z(3.25, 2), 13, "double2ufix64_z7");
test_checki64(double2ufix64_z(3.0, -1), 1, "double2fuix64_z8"); // not very useful

union {
uint64_t u;
double d;
} u64d;

printf("double2int\n");
test_checki(double2int(0.0), 0, "double2int1");
test_checki(double2int(0.25), 0, "double2int1b");
Expand All @@ -236,12 +241,25 @@ int test() {
test_checki(double2int(-0.75), -1, "double2int5");
test_checki(double2int(-1.0), -1, "double2int5b");
// todo test correct rounding around maximum precision
test_checki(double2int(2147483646.0), INT32_MAX-1, "double2int6");
test_checki(double2int(2147483647.0), INT32_MAX, "double2int6");
test_checki(double2int(21474836470.0), INT32_MAX, "double2int7");
test_checki(double2int(-2147483648.0), INT32_MIN, "double2int8");
test_checki(double2int(-21474836480.0), INT32_MIN, "double2int9");
test_checki(double2int(-2.5), -3, "double2int10");
test_checki(double2int(-2.4), -3, "double2int11");
u64d.u = 0xc000000000000000ull;
test_checki(double2int(u64d.d), -2, "double2int12");
u64d.u = 0xc008000000000000ull;
test_checki(double2int(u64d.d), -3, "double2int12b");
u64d.u = 0xc000000000000001ull;
test_checki(double2int(u64d.d), -3, "double2int12c");
u64d.u = 0xc000000080000000ull;
test_checki(double2int(u64d.d), -3, "double2int12d");
u64d.u = 0xc000000100000000ull;
test_checki(double2int(u64d.d), -3, "double2int12e");
u64d.u = 0xc000000100000001ull;
test_checki(double2int(u64d.d), -3, "double2int12f");

printf("double2uint\n");
test_checku(double2uint(0.0), 0, "double2uint1");
Expand Down Expand Up @@ -274,10 +292,6 @@ int test() {
test_checki64(double2int64(-21474836480.0), -21474836480ll, "double2int649");
test_checki64(double2int64(-2.5), -3, "double2int6410");
test_checki64(double2int64(-2.4), -3, "double2int6411");
union {
uint64_t u;
double d;
} u64d;
u64d.u = 0xc000000000000000ull;
test_checki64(double2int64(u64d.d), -2, "double2int6412");
u64d.u = 0xc008000000000000ull;
Expand Down