diff --git a/libsrc/c64/extra/fp754kernal.s b/libsrc/c64/extra/fp754kernal.s index 63e05115f..f4de4b91e 100644 --- a/libsrc/c64/extra/fp754kernal.s +++ b/libsrc/c64/extra/fp754kernal.s @@ -10,6 +10,7 @@ .import ___cbmkernal_feaxint .import ___cbmkernal_feaxlong .import ___cbmkernal_fbnegeax + .import ___cbmkernal_fnegeax .import ___cbmkernal_ftosaddeax .import ___cbmkernal_ftossubeax .import ___cbmkernal_ftosdiveax @@ -30,6 +31,7 @@ .export feaxint := ___cbmkernal_feaxint .export feaxlong := ___cbmkernal_feaxlong .export fbnegeax := ___cbmkernal_fbnegeax + .export fnegeax := ___cbmkernal_fnegeax .export ftosaddeax := ___cbmkernal_ftosaddeax .export ftossubeax := ___cbmkernal_ftossubeax .export ftosdiveax := ___cbmkernal_ftosdiveax diff --git a/libsrc/float/cbmkernal/cbmfp-wrapper.s b/libsrc/float/cbmkernal/cbmfp-wrapper.s index 90819f388..8a2c2949e 100644 --- a/libsrc/float/cbmkernal/cbmfp-wrapper.s +++ b/libsrc/float/cbmkernal/cbmfp-wrapper.s @@ -193,11 +193,9 @@ ___cbmkernal_fbnegeax: jsr __ftoi jmp bnegax -.if 0 = 1 .export ___cbmkernal_fnegeax - ___cbmkernal_fnegeax: +___cbmkernal_fnegeax: jmp __fneg -.endif ;-------------------------------------------------------------- ; math ops diff --git a/libsrc/float/softfloat/softfloat-wrapper.s b/libsrc/float/softfloat/softfloat-wrapper.s index 4387bcb03..7e9e3b0eb 100644 --- a/libsrc/float/softfloat/softfloat-wrapper.s +++ b/libsrc/float/softfloat/softfloat-wrapper.s @@ -77,6 +77,29 @@ fbnegeax: ldx #0 rts + .import _float32_mul + ; arg0: a/x/sreg/sreg+1 + .export fnegeax +fnegeax: + pha +; txa +; pha + lda sreg+1 + eor #$80 ; sign bit + sta sreg+1 +; lda sreg+0 +; eor #$ff ; sign bit +; sta sreg+0 +; txa +; eor #$ff ; sign bit +; tax +; pla +; tax + pla +; eor #$ff ; sign bit + rts + + .import _float32_add .import _float32_sub .import _float32_mul diff --git a/test/val/float-bnegate.c b/test/val/float-bnegate.c new file mode 100644 index 000000000..9d6c1db6e --- /dev/null +++ b/test/val/float-bnegate.c @@ -0,0 +1,106 @@ + +// test basic arithmetic operations +// WIP WIP WIP + +#ifdef CONIO +#include +#define WAIT() cgetc() +#else +#define WAIT() +#endif + +#include +#include +#include +#include + +#include <_float.h> + +float fp1 = 12.34f; +float fp2; // non initialized +float fp3, fp4 = 55.55f; + +char buf[0x20]; +char buf2[0x20]; +char buf3[0x20]; + +unsigned long l1,l2; + +signed char var_schar; +unsigned char var_uchar; +signed int var_sint; +unsigned int var_uint; +signed long var_slong; +unsigned long var_ulong; + +int result = 0; + +// returns 1 if value in f matches the string +// the string is a hex value without leading "0x" +int compare(float f, char *str) +{ + char temp[12]; + sprintf(temp, "%08lx", *((uint32_t*)&f)); + return (strcmp(temp, str) == 0) ? 1 : 0; +} + +void test1(float f, char *str) +{ + if (compare(f, str)) { +// printf("(ok)"); + printf("\n"); + } else { + printf(" (failed)\n"); + result++; + } +} + +void test2(long n, long val) +{ + if (n == val) { +// printf("(ok)"); + printf("\n"); + } else { + printf(" (failed)\n"); + result++; + } +} + +int main(void) +{ + float fp2 = 43.21f; + + printf("float-binary negate (not)\n"); + printf("fp1:0x%08lx [0x414570a4] %s (12.340000)\n", *((uint32_t*)&fp1), _ftostr(buf, fp1)); + printf("fp2:0x%08lx [0x422cd70a] %s (43.209999)\n", *((uint32_t*)&fp2), _ftostr(buf, fp2)); + + fp1 = 0.0f; + fp2 = !fp1; + var_sint = !fp1; + fp3 = !fp2; + printf("fp2 0x%08lx [0x3f800000] %s (!0=1) %d", *((uint32_t*)&fp2), _ftostr(buf, fp2), var_sint); + test1(fp2, "3f800000"); + printf("fp3 0x%08lx [0x00000000] %s (!1=0)", *((uint32_t*)&fp3), _ftostr(buf, fp3)); + test1(fp3, "00000000"); + + fp1 = 12.6f; + fp2 = !fp1; + var_sint = !fp1; + fp3 = !fp2; + printf("fp2 0x%08lx [0x00000000] %s (!12.6f=0) %d", *((uint32_t*)&fp2), _ftostr(buf, fp2), var_sint); + test1(fp2, "00000000"); + printf("fp3 0x%08lx [0x3f800000] %s (!0=1)", *((uint32_t*)&fp3), _ftostr(buf, fp3)); + test1(fp3, "3f800000"); + + fp1 = -12.6f; + fp2 = !fp1; + var_sint = !fp1; + fp3 = !fp2; + printf("fp2 0x%08lx [0x00000000] %s (!-12.6f=0) %d", *((uint32_t*)&fp2), _ftostr(buf, fp2), var_sint); + test1(fp2, "00000000"); + printf("fp3 0x%08lx [0x3f800000] %s (!0=1)", *((uint32_t*)&fp3), _ftostr(buf, fp3)); + test1(fp3, "3f800000"); + + printf("float-binary negate (res:%d)\n", result); + return result; +} diff --git a/test/val/float-negate.c b/test/val/float-negate.c index 67690d18e..04b8cf65e 100644 --- a/test/val/float-negate.c +++ b/test/val/float-negate.c @@ -16,9 +16,10 @@ #include <_float.h> -float fp1 = 12.34f; -float fp2; // non initialized -float fp3, fp4 = 55.55f; +float fp1 = 1.0f; +float fp2 = 200.0f; // aliased by variable in main +float fp3 = 3.0f; +float fp4 = 4.0f; char buf[0x20]; char buf2[0x20]; @@ -68,39 +69,41 @@ void test2(long n, long val) int main(void) { - float fp2 = 43.21f; + float fp2 = 2.00f; - printf("float-binary negate (not)\n"); - printf("fp1:0x%08lx [0x414570a4] %s (12.340000)\n", *((uint32_t*)&fp1), _ftostr(buf, fp1)); - printf("fp2:0x%08lx [0x422cd70a] %s (43.209999)\n", *((uint32_t*)&fp2), _ftostr(buf, fp2)); + printf("float negate (minus)\n"); - fp1 = 0.0f; - fp2 = !fp1; - var_sint = !fp1; - fp3 = !fp2; - printf("fp2 0x%08lx [0x3f800000] %s (!0=1) %d", *((uint32_t*)&fp2), _ftostr(buf, fp2), var_sint); - test1(fp2, "3f800000"); - printf("fp3 0x%08lx [0x00000000] %s (!1=0)", *((uint32_t*)&fp3), _ftostr(buf, fp3)); - test1(fp3, "00000000"); + printf("fp1:0x%08lx [0x3f800000] %s (1.0)", *((uint32_t*)&fp1), _ftostr(buf, fp1)); + test1(fp1, "3f800000"); + printf("fp2:0x%08lx [0x40000000] %s (2.0)", *((uint32_t*)&fp2), _ftostr(buf, fp2)); + test1(fp2, "40000000"); + + var_sint = -fp1; + fp3 = -fp2; + fp2 = -fp1; + printf("fp2 0x%08lx [0xbf800000] %s (-1.0) %d", *((uint32_t*)&fp2), _ftostr(buf, fp2), var_sint); + test1(fp2, "bf800000"); + printf("fp3 0x%08lx [0xc0000000] %s (-2.0)", *((uint32_t*)&fp3), _ftostr(buf, fp3)); + test1(fp3, "c0000000"); fp1 = 12.6f; - fp2 = !fp1; - var_sint = !fp1; - fp3 = !fp2; - printf("fp2 0x%08lx [0x00000000] %s (!12.6f=0) %d", *((uint32_t*)&fp2), _ftostr(buf, fp2), var_sint); - test1(fp2, "00000000"); - printf("fp3 0x%08lx [0x3f800000] %s (!0=1)", *((uint32_t*)&fp3), _ftostr(buf, fp3)); - test1(fp3, "3f800000"); + fp2 = -fp1; + var_sint = -fp1; + fp3 = -fp2; + printf("fp2 0x%08lx [0xc149999a] %s (-12.6) %d", *((uint32_t*)&fp2), _ftostr(buf, fp2), var_sint); + test1(fp2, "c149999a"); + printf("fp3 0x%08lx [0x4149999a] %s (12.6)", *((uint32_t*)&fp3), _ftostr(buf, fp3)); + test1(fp3, "4149999a"); fp1 = -12.6f; - fp2 = !fp1; - var_sint = !fp1; - fp3 = !fp2; - printf("fp2 0x%08lx [0x00000000] %s (!-12.6f=0) %d", *((uint32_t*)&fp2), _ftostr(buf, fp2), var_sint); - test1(fp2, "00000000"); - printf("fp3 0x%08lx [0x3f800000] %s (!0=1)", *((uint32_t*)&fp3), _ftostr(buf, fp3)); - test1(fp3, "3f800000"); + fp2 = -fp1; + var_sint = -fp1; + fp3 = -fp2; + printf("fp2 0x%08lx [0x4149999a] %s (12.6) %d", *((uint32_t*)&fp2), _ftostr(buf, fp2), var_sint); + test1(fp2, "4149999a"); + printf("fp3 0x%08lx [0xc149999a] %s (-12.6)", *((uint32_t*)&fp3), _ftostr(buf, fp3)); + test1(fp3, "c149999a"); - printf("float-misc (res:%d)\n", result); + printf("float minus (res:%d)\n", result); return result; }