0 Members and 1 Guest are viewing this topic.
Thanks!Also, just want to make sure, am I doing multiplication right?product = (a >> * (b >>
But the way I did it would prevent overflows, because I am only using 32 bit integers the whole time.Yes, I'm using signed numbers. Will that introduce problems?Also, am I understanding the division correctly? a / b in fixed point is [integer part of a]/b?
Apparently ARM7 does not natively support long long integers. So that means I would get odd results if I tried division with any number with an absolute value of over 1. Would (a << 8 ) / (b >> 8 ) work? I would still get an overflow if I used anything over 65536 in fixed point, but I don't think I will get to numbers that high.Also, is there a tag to disable smileys?
@ int fixed_mul(int, int);.global fixed_mulfixed_mul: @ Multiply 32x32->64 and shift right by 16 smull r0,r2,r1,r0 mov r0,r0,lsr #16 orr r0,r0,r2,lsl #16 @ Overflow check start teq r2,r0,asr #16 movne r0,#0x7FFFFFFF eorne r0,r0,r2,asr #31 @ Overflow check end bx lr
@ int fixed_div(int, int);.global fixed_divfixed_div: @ r2 = abs(r0) eors r2,r0,r0,asr #32 adc r2,r2,#0 @ r3 = abs(r1) eors r3,r1,r1,asr #32 adc r3,r3,#0 @ Get sign of result eor r1,r1,r0 @ Initialize result mov r0,#0x7FFFFFFF @ Check for overflow cmp r3,r2,lsr #15 bls fixed_div_end .irp shift,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0 cmp r3,r2,lsr #\shift subls r2,r2,r3,lsl #\shift bichi r0,r0,#0x10000 << \shift .endr .irp shift,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0 rsbs r2,r3,r2,lsl #1 addlo r2,r2,r3 biclo r0,r0,#1 << \shift .endr fixed_div_end: @ Adjust sign eors r0,r0,r1,asr #32 adc r0,r0,#0 bx lr
$ makenspire-gcc -Os -Wall -W -c main.cmain.c: In function 'main':main.c:52:7: warning: unused variable 'oldtime'main.c:51:7: warning: unused variable 'time'main.c:46:8: warning: unused variable 'timer'nspire-gcc -Os -Wall -W -c utils.cutils.c: In function 'filesize':utils.c:129:3: warning: passing argument 2 of 'stat' from incompatible pointer typec:/ndless-v2.0/sdk/include/os.h:288:1: note: expected 'struct stat *' but argument is of type 'char *'nspire-gcc -Os -Wall -W -c graphics.cnspire-gcc -Os -Wall -W -c math.cnspire-ld main.o utils.o graphics.o math.o -o raycaster.elfc:/program files/yagarto/bin/../lib/gcc/arm-none-eabi/4.5.1\libgcc.a(unwind-arm.o): In function `get_eit_entry':C:\msys\1.0\home\yagarto\gcc-build\arm-none-eabi\libgcc/../../../gcc-4.5.1/libgcc/../gcc/config/arm/unwind-arm.c:614: undefined reference to `__exidx_start'C:\msys\1.0\home\yagarto\gcc-build\arm-none-eabi\libgcc/../../../gcc-4.5.1/libgcc/../gcc/config/arm/unwind-arm.c:614: undefined reference to `__exidx_end'c:/program files/yagarto/bin/../lib/gcc/arm-none-eabi/4.5.1/../../../../arm-none-eabi/lib\libc.a(lib_a-abort.o): In function `abort':C:\msys\1.0\home\yagarto\newlib-build\arm-none-eabi\newlib\libc\stdlib/../../../../../newlib-1.18.0/newlib/libc/stdlib/abort.c:63: undefined reference to `_exit'c:/program files/yagarto/bin/../lib/gcc/arm-none-eabi/4.5.1/../../../../arm-none-eabi/lib\libc.a(lib_a-signalr.o): In function `_kill_r':C:\msys\1.0\home\yagarto\newlib-build\arm-none-eabi\newlib\libc\reent/../../../../../newlib-1.18.0/newlib/libc/reent/signalr.c:61: undefined reference to `_kill'c:/program files/yagarto/bin/../lib/gcc/arm-none-eabi/4.5.1/../../../../arm-none-eabi/lib\libc.a(lib_a-signalr.o): In function `_getpid_r':C:\msys\1.0\home\yagarto\newlib-build\arm-none-eabi\newlib\libc\reent/../../../../../newlib-1.18.0/newlib/libc/reent/signalr.c:96: undefined reference to `_getpid'collect2: ld returned 1 exit statusmake: *** [raycaster.tns] Error 1
inline long div(long a, long b) { long a1; a1 = a >> 16; a = (a << 16) / b; a1 = (a1 << 16) / b; return (a1 << 16) + a;}
inline long mul(long a, long b) { long a1 = a >> 16; long a2 = a & 0x0000FFFF; long b1 = b >> 16; long b2 = b & 0x0000FFFF; return ((a1 * b1) << 16) + (a1 * b2) + (a2 * b1) + ((a2 + b2) << 16);}
inline long mul(long a, long b) { signed short a1 = a >> 16; unsigned short a2 = a; signed short b1 = b >> 16; unsigned short b2 = b; return ((a1 * b1) << 16) + (a1 * b2) + (a2 * b1) + ((a2 * b2) >> 16);}