radiance32
Member
- Joined
- Jan 3, 2022
- Messages
- 17
Hi all,
I'm optimizing a mostly C program with some inline assembly for my fixed point math routines. (16 bit fixed point, 6.10 format)
I have hardly any experience with 8086 assembly programming at all, but I did find a working routine from a friend to do my multiplications,
but none for division.
Here's the code, the F_REAL type (short for Fixed Real number) is an alias for an int16.
The C functions work, and the assembly language routine works too (the multiplication one) using it improves my speed from ~0.6 to ~0.75.
All good.
But, I also need the equivalent for my divisions,
and I've tried to modify the assembly language from the multiply routine above but it fails...
Can someone help ?
Here's the working division C function and my broken assembly language attempt:
I am using the Watcom C/C++ 1.9 compiler for compilation with a 8086 target with FPU emulation (I don't use much floats in my code since I switched to fixed point) and testing on DOSBOX (8086 CPU, no FPU).
If someone can fix this, I would be very grateful.
I am a visual learner, so a small sample of code is better for me to understand than a discussion...
Also, if someone knows of any ways to optimize the multiplication (and division) function even more (maybe with no loops), I'm all ears
Thanks,
Terrence
I'm optimizing a mostly C program with some inline assembly for my fixed point math routines. (16 bit fixed point, 6.10 format)
I have hardly any experience with 8086 assembly programming at all, but I did find a working routine from a friend to do my multiplications,
but none for division.
Here's the code, the F_REAL type (short for Fixed Real number) is an alias for an int16.
The C functions work, and the assembly language routine works too (the multiplication one) using it improves my speed from ~0.6 to ~0.75.
All good.
Code:
#define FIXED_POINT_FRACTIONAL_BITS 10
// Multiplication of two fixed-point numbers
//inline F_REAL F_REAL_MUL(F_REAL a, F_REAL b) {
// return (F_REAL)(((long)a * b) >> FIXED_POINT_FRACTIONAL_BITS);
//}
inline F_REAL F_REAL_MUL(F_REAL a, F_REAL b);
#pragma aux F_REAL_MUL = \
"imul bx" \
"mov cx, 10" \
"shrd_loop:" \
" shr dx, 1" \
" rcr ax, 1" \
"loop shrd_loop" \
parm [ax] [bx] \
modify [ax bx cx dx] \
value [ax];
But, I also need the equivalent for my divisions,
and I've tried to modify the assembly language from the multiply routine above but it fails...
Can someone help ?
Here's the working division C function and my broken assembly language attempt:
Code:
// Division of two fixed-point numbers
// inline F_REAL F_REAL_DIV(F_REAL a, F_REAL b) {
// return (F_REAL)(((long)a << FIXED_POINT_FRACTIONAL_BITS) / b);
//}
inline F_REAL F_REAL_DIV(F_REAL a, F_REAL b);
#pragma aux F_REAL_DIV = \
"idiv bx" \
"mov cx, 10" \
"shld_loop:" \
" shl dx, 1" \
" rcl ax, 1" \
"loop shld_loop" \
parm [ax] [bx] \
modify [ax bx cx dx] \
value [ax];
I am using the Watcom C/C++ 1.9 compiler for compilation with a 8086 target with FPU emulation (I don't use much floats in my code since I switched to fixed point) and testing on DOSBOX (8086 CPU, no FPU).
If someone can fix this, I would be very grateful.
I am a visual learner, so a small sample of code is better for me to understand than a discussion...
Also, if someone knows of any ways to optimize the multiplication (and division) function even more (maybe with no loops), I'm all ears
Thanks,
Terrence