Skip to content

Commit

Permalink
Merge pull request #2248 from ghaerr/float
Browse files Browse the repository at this point in the history
[owc libc] Fix soft float emulation underflow/overflow
  • Loading branch information
ghaerr authored Mar 1, 2025
2 parents 8df0177 + c45a393 commit 6b091b7
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 18 deletions.
4 changes: 2 additions & 2 deletions elks/tools/objtools/ewcc
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ ELKSINCLUDE2=$TOPDIR/libc/include/watcom
# unused:
# -fno-stack-check # don't generate stack check code
# -ztNum # specify far data threshold (default 32767, or 256 if no Num)
# -Wc,-fpi87 # inline 8087 fp
# -Wc,-fpi87 # generate inline 8087 hardware fp
# -mhard-emu-float # -Wc,-fpi (inline 8087 w/emulation)
# -msoft-float # -Wc,-fpc (software fp)
# -msoft-float # -Wc,-fpc (non-IEEE software fp)
# -fpmath
# -mabi=cdecl # push all args
# -fnonconst-initializers # -Wc,aa
Expand Down
2 changes: 1 addition & 1 deletion libc/watcom.inc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ CARCH =\
-march=i86 \
-std=c99 \
-fno-stack-check \
-Wc,-fpc \
-msoft-float \
-Wc,-zev \
-Wc,-zls \
-Wc,-x \
Expand Down
24 changes: 15 additions & 9 deletions libc/watcom/asm/fstat386.asm
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
;* ========================================================================
;*
;* Description: Floating-point exception signaling
;* Modified by ghaerr for 8086 CPU
;* Modified by ghaerr for 8086 CPU (16-bits)
;* 32-bit "float" type stored in DX:AX
;* 64-bit "double" type stored in AX:BX:CX:DX
;*****************************************************************************


Expand Down Expand Up @@ -107,13 +109,15 @@ include fstatus.inc
; F8UnderFlow( void ) : reallong
;
defp F8UnderFlow
xor dx,dx ; return zero FIXME
xor bx,bx ; return zero
xor cx,cx
;
; F4UnderFlow( void ) : real
;
defp F4UnderFlow
call FPUnderFlow ; handle underflow
xor ax,ax ; return zero FIXME
xor dx,dx ; return zero
xor ax,ax
ret ; return
endproc F4UnderFlow
endproc F8UnderFlow
Expand All @@ -133,8 +137,9 @@ include fstatus.inc
; F4RetInf( sign : int ) : real
;
defp F4RetInf
;;;;and ax,80000000h ; get sign FIXME
;;;;or ax,7F800000h ; set infinity
and dx,8000h ; get sign
or dx,7F80h ; set infinity
xor ax,ax
ret ; return
endproc F4RetInf
endproc F4OverFlow
Expand All @@ -155,10 +160,11 @@ include fstatus.inc
; F8RetInf( sign : int ) : reallong
;
defp F8RetInf
;;;;and ax,80000000h ; get sign FIXME
;;;;or ax,7FF00000h ; set infinity
mov dx,ax ; FIXME
sub ax,ax ; ... FIXME
and ax,8000h ; get sign
or ax,7FF0h ; set infinity
xor bx,bx
xor cx,cx
xor dx,dx
ret ; return
endproc F8RetInf
endproc F8OverFlow
Expand Down
5 changes: 0 additions & 5 deletions libc/watcom/syscall/crt0.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,6 @@ char **environ;
unsigned int __stacklow; /* lowest protected SP value */
unsigned char _HShift = 12; /* huge pointer support required by pia.asm */

/* floating point globals */
char _8087;
char _real87;
char _chipbug;

#if defined(__SMALL__) || defined(__MEDIUM__) /* near data models */
/* no argv/environ rewrite */
static noreturn void premain(void)
Expand Down
7 changes: 6 additions & 1 deletion libc/watcom/syscall/fpexcept.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
/* Various routines called from OWC soft float library */
/* Various routines or globals called/referenced from OWC soft float library */
#include <assert.h>
#include <errno.h>

/* floating point globals - FIXME should initialize at startup? */
char _8087;
char _real87;
char _chipbug;

/*
__FPE_exception is called from machine language with parm in AX
(see "fstatus" module in CGSUPP)
Expand Down

0 comments on commit 6b091b7

Please sign in to comment.