Skip to content

Commit 202e092

Browse files
committed
implemented s_normSubnormalF64Sig in assembly to save 78 bytes and inlined functions only used by f64_to_f32 saving an additional 118 bytes
1 parent b56d688 commit 202e092

File tree

5 files changed

+72
-0
lines changed

5 files changed

+72
-0
lines changed

src/softfloat/include/specialize.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,15 @@ void softfloat_f32UIToCommonNaN( uint_fast32_t uiA, struct commonNaN *zPtr );
145145
| Converts the common NaN pointed to by 'aPtr' into a 32-bit floating-point
146146
| NaN, and returns the bit pattern of this value as an unsigned integer.
147147
*----------------------------------------------------------------------------*/
148+
#if 0
148149
uint_fast32_t softfloat_commonNaNToF32UI( const struct commonNaN *aPtr );
150+
#else
151+
/** only used by f64_to_f32 currently */
152+
static inline uint_fast32_t softfloat_commonNaNToF32UI( const struct commonNaN *aPtr )
153+
{
154+
return (uint_fast32_t) aPtr->sign<<31 | 0x7FC00000 | aPtr->v64>>41;
155+
}
156+
#endif
149157

150158
/*----------------------------------------------------------------------------
151159
| Interpreting 'uiA' and 'uiB' as the bit patterns of two 32-bit floating-
@@ -178,7 +186,20 @@ bool softfloat_isSigNaNF64UI(uint64_t a) __attribute__((__const__, __nothrow__,
178186
| location pointed to by 'zPtr'. If the NaN is a signaling NaN, the invalid
179187
| exception is raised.
180188
*----------------------------------------------------------------------------*/
189+
#if 0
181190
void softfloat_f64UIToCommonNaN( uint_fast64_t uiA, struct commonNaN *zPtr );
191+
#else
192+
/** only used by f64_to_f32 currently */
193+
static inline void softfloat_f64UIToCommonNaN( uint_fast64_t uiA, struct commonNaN *zPtr )
194+
{
195+
if ( softfloat_isSigNaNF64UI( uiA ) ) {
196+
softfloat_raiseFlags( softfloat_flag_invalid );
197+
}
198+
zPtr->sign = uiA>>63;
199+
zPtr->v64 = uiA<<12;
200+
zPtr->v0 = 0;
201+
}
202+
#endif
182203

183204
/*----------------------------------------------------------------------------
184205
| Converts the common NaN pointed to by 'aPtr' into a 64-bit floating-point

src/softfloat/s_commonNaNToF32UI.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3434
3535
=============================================================================*/
3636

37+
#if 0
38+
3739
#include <stdint.h>
3840
#include "platform.h"
3941
#include "specialize.h"
@@ -49,3 +51,4 @@ uint_fast32_t softfloat_commonNaNToF32UI( const struct commonNaN *aPtr )
4951

5052
}
5153

54+
#endif

src/softfloat/s_f64UIToCommonNaN.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3434
3535
=============================================================================*/
3636

37+
#if 0
38+
3739
#include <stdint.h>
3840
#include "platform.h"
3941
#include "specialize.h"
@@ -57,3 +59,4 @@ void softfloat_f64UIToCommonNaN( uint_fast64_t uiA, struct commonNaN *zPtr )
5759

5860
}
5961

62+
#endif

src/softfloat/s_normSubnormalF64Sig.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3434
3535
=============================================================================*/
3636

37+
#if 0
38+
3739
#include <stdint.h>
3840
#include "platform.h"
3941
#include "internals.h"
@@ -50,3 +52,4 @@ struct exp16_sig64 softfloat_normSubnormalF64Sig( uint_fast64_t sig )
5052

5153
}
5254

55+
#endif
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
assume adl = 1
2+
3+
section .text
4+
5+
public _softfloat_normSubnormalF64Sig
6+
7+
; saves 78 bytes
8+
; this function is called in the float64_ldexp tests
9+
_softfloat_normSubnormalF64Sig:
10+
ld iy, 0
11+
add iy, sp
12+
ld hl, (iy + 6)
13+
ld de, (iy + 9)
14+
ld bc, (iy + 12)
15+
ld iy, (iy + 3) ; struct
16+
call __llctlz
17+
18+
push hl
19+
; shiftDist = softfloat_countLeadingZeros64( sig ) - 11;
20+
sub a, 11
21+
or a, a
22+
sbc hl, hl
23+
ld l, a
24+
; z.exp = 1 - shiftDist;
25+
call __ineg
26+
inc hl
27+
ld (iy + 0), hl
28+
; z.sig = sig<<shiftDist;
29+
ld l, a
30+
ex (sp), hl
31+
call __llshl
32+
pop af ; reset SP
33+
ld (iy + 2), hl
34+
ld (iy + 5), de
35+
ld (iy + 8), bc
36+
37+
lea hl, iy ; ABI struct ptr
38+
ret
39+
40+
extern __llshl
41+
extern __llctlz
42+
extern __ineg

0 commit comments

Comments
 (0)