Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenLibm working on 16-bit 8086 #259

Open
ghaerr opened this issue Apr 9, 2022 · 0 comments
Open

OpenLibm working on 16-bit 8086 #259

ghaerr opened this issue Apr 9, 2022 · 0 comments

Comments

@ghaerr
Copy link

ghaerr commented Apr 9, 2022

Hello all,

I'm not sure whether anyone is interested in this, but I have successfully ported a number of the OpenLibm math routines to ELKS, an 8086-based Linux kernel and C library, using the ia16-elf-gcc compiler. In this system, int is 16 bits, and long 32 bits. float and double are IEEE 754 32 and 64 bits.

The following patch was required. It may (or may not) be a good idea to consider changing the non-portable unsigned int definitions to something like uint32_t for portability. Not knowing this library well, I am unsure whether unsigned int may need to be 64 bits on some systems, in which case, this would not work. However, it seems the IEEEf2bits structure assumes unsigned int to be 32 bits for its bitfield definitions.

diff --git a/src/fpmath.h b/src/fpmath.h
index 6c37595..5843386 100644
--- a/src/fpmath.h
+++ b/src/fpmath.h
@@ -83,13 +83,13 @@ union IEEEf2bits {
        float   f;
        struct {
 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
-               unsigned int    man     :23;
-               unsigned int    exp     :8;
-               unsigned int    sign    :1;
+               unsigned long   man     :23;
+               unsigned long   exp     :8;
+               unsigned long   sign    :1;
 #else /* _BIG_ENDIAN */
-               unsigned int    sign    :1;
-               unsigned int    exp     :8;
-               unsigned int    man     :23;
+               unsigned long   sign    :1;
+               unsigned long   exp     :8;
+               unsigned long   man     :23;
 #endif
        } bits;
 };
@@ -102,19 +102,19 @@ union IEEEd2bits {
        struct {
 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
 #if __FLOAT_WORD_ORDER__ == __ORDER_LITTLE_ENDIAN__
-               unsigned int    manl    :32;
+               unsigned long   manl    :32;
 #endif
-               unsigned int    manh    :20;
-               unsigned int    exp     :11;
-               unsigned int    sign    :1;
+               unsigned long   manh    :20;
+               unsigned long   exp     :11;
+               unsigned long   sign    :1;
 #if __FLOAT_WORD_ORDER__ == __ORDER_BIG_ENDIAN__
-               unsigned int    manl    :32;
+               unsigned long   manl    :32;
 #endif
 #else /* _BIG_ENDIAN */
-               unsigned int    sign    :1;
-               unsigned int    exp     :11;
-               unsigned int    manh    :20;
-               unsigned int    manl    :32;
+               unsigned long   sign    :1;
+               unsigned long   exp     :11;
+               unsigned long   manh    :20;
+               unsigned long   manl    :32;
 #endif
        } bits;
 };
diff --git a/src/i386_fpmath.h b/src/i386_fpmath.h
index 455631c..8b29e38 100644
--- a/src/i386_fpmath.h
+++ b/src/i386_fpmath.h
@@ -29,16 +29,16 @@
 union IEEEl2bits {
        long double     e;
        struct {
-               unsigned int    manl    :32;
-               unsigned int    manh    :32;
-               unsigned int    exp     :15;
-               unsigned int    sign    :1;
-               unsigned int    junk    :16;
+               unsigned long   manl    :32;
+               unsigned long   manh    :32;
+               unsigned long   exp     :15;
+               unsigned long   sign    :1;
+               unsigned long   junk    :16;
        } bits;
        struct {
                unsigned long long man  :64;
-               unsigned int    expsign :16;
-               unsigned int    junk    :16;
+               unsigned long   expsign :16;
+               unsigned long   junk    :16;
        } xbits;
 };
 
diff --git a/src/math_private.h b/src/math_private.h
index 15a27b2..4f7e1d4 100644
--- a/src/math_private.h
+++ b/src/math_private.h
@@ -162,7 +162,7 @@ typedef union
 {
   float value;
   /* FIXME: Assumes 32 bit int.  */
-  unsigned int word;
+  unsigned long word;
 } ieee_float_shape_type;
 
 /* Get a 32 bit int from a float.  */

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant