Skip to content

Commit ddfa43d

Browse files
committed
gas64: changelog, tests
- gas64: fix casting ulong (with "negative value") to double/single (SARG) - gas64: fix optimization prevented converting 32bit memory/register (SARG) see c132cf3 see edee975
1 parent 9046964 commit ddfa43d

File tree

3 files changed

+159
-0
lines changed

3 files changed

+159
-0
lines changed

changelog.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ Version 1.20.0
9595
- updated bindings: WinAPI: Allow FD_SETSIZE to be defined by user before including winsock.bi and winsock2.bi
9696
- sf.net #469, sf.net #721: check for unallocated dynamic arrays and wrong number of dimensions at run time and throw an error if attempting to access an unallocated array or indexing with the wrong number of dimensions
9797
- allow long ar and ld command lines in standalone windows builds (adeyblue)
98+
- gas64: fix casting ulong (with "negative value") to double/single (SARG)
99+
- gas64: fix optimization prevented converting 32bit memory/register (SARG)
98100

99101

100102
Version 1.10.3

tests/numbers/cast_f2l.bas

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
#include "fbcunit.bi"
2+
3+
'' show the compared numbers, but only if fbcu.getHideCases() is false
4+
#undef CU_ASSERT_EQUAL
5+
#define CU_ASSERT_EQUAL(a, b) if ((a) <> (b)) and (fbcu.getHideCases() = false) then print (a), (b) end if: CU_ASSERT( (a) = (b) )
6+
7+
SUITE( fbc_tests.numbers.cast_f2l )
8+
9+
sub checkcast(byval x as double, byval ul as ulong)
10+
11+
'' 32 bit
12+
CU_ASSERT_EQUAL( cuint( x ), cuint( ul ) )
13+
14+
if( ul > 1ul shl 31 ) then return
15+
CU_ASSERT_EQUAL( cint( -x ), cint( -ul ) )
16+
CU_ASSERT_EQUAL( clng( -x ), clng( -ul ) )
17+
18+
if( ul > (1ul shl 31) - 1 ) then return
19+
CU_ASSERT_EQUAL( cint( x ), cint( ul ) )
20+
CU_ASSERT_EQUAL( clng( x ), clng( ul ) )
21+
22+
if( ul > (1ul shl 31) - 1 ) then return
23+
CU_ASSERT_EQUAL( cint( x ), cint( ul ) )
24+
CU_ASSERT_EQUAL( clng( x ), clng( ul ) )
25+
26+
'' 16 bit
27+
if( ul > 65535 ) then return
28+
CU_ASSERT_EQUAL( cushort( x ), cushort( ul ) )
29+
30+
if( ul > 32768 ) then return
31+
CU_ASSERT_EQUAL( cshort( -x ), cshort( -ul ) )
32+
33+
if( ul > 32767 ) then return
34+
CU_ASSERT_EQUAL( cshort( x ), cshort( ul ) )
35+
36+
'' 8 bit
37+
if( ul > 255 ) then return
38+
CU_ASSERT_EQUAL( cubyte( x ), cubyte( ul ) )
39+
40+
if( ul > 128 ) then return
41+
CU_ASSERT_EQUAL( cbyte( -x ), cbyte( -ul ) )
42+
43+
if( ul > 127 ) then return
44+
CU_ASSERT_EQUAL( cbyte( x ), cbyte( ul ) )
45+
46+
end sub
47+
48+
sub testnum( byval n as ulong )
49+
50+
#define lsb(n) ((n) and -(n)) '' keep only least significant bit
51+
52+
'' only run when n has <= 53 significant bits
53+
if( n and -(lsb(n) shl 53) ) then return
54+
55+
dim x as double = cdbl(n)
56+
57+
checkcast( x, n )
58+
59+
if( n < 1ul shl 31 ) then
60+
61+
'' make sure that cdbl(l) concurs with cdbl(ul)
62+
CU_ASSERT_EQUAL( x, cdbl(clng(n)) )
63+
64+
65+
if( n < 1ul shl 52 ) then
66+
checkcast( x + 0.5, n + (n and 1) )
67+
checkcast( x - 0.5, n - (n and 1) )
68+
end if
69+
70+
if( n < 1ul shl 51 ) then
71+
checkcast( x + 0.25, n )
72+
checkcast( x - 0.25, n )
73+
end if
74+
75+
end if
76+
77+
end sub
78+
79+
TEST( cast_l )
80+
81+
dim as long n = 1l
82+
dim as double x = 1.0
83+
84+
dim as integer i, j, k, l
85+
86+
'' test powers of 2
87+
for i = 0 to 31
88+
testnum( 1ul shl i )
89+
next i
90+
91+
'' test various bit combinations
92+
for i = 0 to 31
93+
for j = 0 to 31
94+
testnum( (1 shl i) + (1 shl j) )
95+
next j
96+
next i
97+
98+
END_TEST
99+
100+
END_SUITE

tests/numbers/cast_l2f.bas

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#include "fbcunit.bi"
2+
3+
SUITE( fbc_tests.numbers.cast_l2f )
4+
5+
const c as longint = 1l shl 16
6+
7+
TEST( cast_ul )
8+
9+
dim as ulong n = 1ul
10+
dim as double x = 1.0
11+
12+
for i as integer = 0 to 31
13+
14+
cu_assert_equal( cdbl(n), x )
15+
if n <= not c then
16+
cu_assert_equal( cdbl(n + c), x + c )
17+
end if
18+
if n >= c then
19+
cu_assert_equal( cdbl(n - c), x - c )
20+
end if
21+
22+
cu_assert_equal( cdbl(n + 1), x + 1.0 )
23+
cu_assert_equal( cdbl(n - 1), x - 1.0 )
24+
25+
n shl= 1: x *= 2.0
26+
27+
next
28+
29+
END_TEST
30+
31+
TEST( cast_l )
32+
33+
dim as long n = 1l
34+
dim as double x = 1.0
35+
36+
for i as integer = 0 to 30
37+
38+
cu_assert_equal( cdbl(n), x )
39+
cu_assert_equal( cdbl(n + c), x + c )
40+
cu_assert_equal( cdbl(n - c), x - c )
41+
42+
cu_assert_equal( cdbl(-n), -x )
43+
cu_assert_equal( cdbl(-n + c), -x + c )
44+
cu_assert_equal( cdbl(-n - c), -x - c )
45+
46+
cu_assert_equal( cdbl(n + 1), x + 1.0 )
47+
cu_assert_equal( cdbl(n - 1), x - 1.0 )
48+
cu_assert_equal( cdbl(-n + 1), -x + 1.0 )
49+
cu_assert_equal( cdbl(-n - 1), -x - 1.0 )
50+
51+
n shl= 1: x *= 2.0
52+
53+
next
54+
55+
END_TEST
56+
57+
END_SUITE

0 commit comments

Comments
 (0)