05 February 2021, 19:07 | #1 |
<optimized out>
Join Date: Sep 2020
Location: <optimized out>
Posts: 321
|
Could someone please sense check this assembly code?
It's taken me the best part of a day to make something that agrees with my calculator, which just enforces the fact that assembler and me will never be friends.
Could someone please look at this and tell me how sh_t it is? All I'm trying to do is multiply a word (that is a 1:15 fixed point number) by a long, then divide by two and remove the digits after the point, taking advantage of 15 + 1 = 16, and saving the long result. Code:
void CalculateDynamicPressure(Aircraft * this_Aircraft) { UWORD airDensity = AirDensity_15(this_Aircraft->position3D.up); ULONG velocitySquared = this_Aircraft->deltaPosition3D.east * this_Aircraft->deltaPosition3D.east + this_Aircraft->deltaPosition3D.north * this_Aircraft->deltaPosition3D.north + this_Aircraft->deltaPosition3D.up * this_Aircraft->deltaPosition3D.up; KPrintF("Dynamic pressure = 1/2 * air density * velocity squared = 1/2 * %ld * %ld", airDensity, velocitySquared); ULONG t0, t1; asm ( " move.l %[velocitySquared], %[t0] \n" " move.l %[t0], %[t1] \n" " swap %[t0] \n" " mulu.w %[airDensity], %[t0] \n" " mulu.w %[airDensity], %[t1] \n" " clr.w %[t1] \n" " swap %[t1] \n" " add.l %[t1], %[t0] \n" " move.l %[t0], %[dynamicPressure] \n" : // outputs [dynamicPressure] "=g" (this_Aircraft->dynamicPressure), [t0] "=d" (t0), [t1] "=d" (t1) : // inputs [airDensity] "g" (airDensity), [velocitySquared] "g" (velocitySquared) : // clobbers "cc" ); KPrintF("Dynamic pressure = 1/2 * air density * velocity squared = 1/2 * %ld * %ld = %ld", airDensity, velocitySquared, this_Aircraft->dynamicPressure); } |
05 February 2021, 21:58 | #2 |
This cat is no more
Join Date: Dec 2004
Location: FRANCE
Age: 52
Posts: 8,163
|
where do you divide by 2 ?
|
05 February 2021, 22:52 | #3 |
Registered User
Join Date: Jun 2016
Location: europe
Posts: 1,039
|
You have to mul by 2 to convert from 1:15 after a swap.
Code:
AAAAAAAAAAAAAAAA Aaaaaaaaaaaaaaaa 0000000000000000 = t0 + BBBBBBBBBBBBBBBB Bbbbbbbbbbbbbbbb = t1 = CCCCCCCCCCCCCCCC Cccccccccccccccc = 15-bit fraction, so 1 bit owed because of early t0 swap |
06 February 2021, 07:43 | #4 |
<optimized out>
Join Date: Sep 2020
Location: <optimized out>
Posts: 321
|
By shifting by 16 (swapping) rather than by 15.
Edit: You're right, I've lost a swap. Edit 2: Or have I?... Testing: Code:
air_density velocity^2 me excel 39197 181476 108540 108540 38673 37889 22358 22358 39659 271133 164075 164075 Last edited by Ernst Blofeld; 06 February 2021 at 09:24. |
06 February 2021, 15:26 | #5 |
Registered User
Join Date: Jun 2016
Location: europe
Posts: 1,039
|
Ah, you wanted to additionally divide the result by two. I missed that part, was looking at the asm code only (late hour ><). In that case, that's it. The extra *2 you needed to compensate for a swap is annulated.
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Amiga Assembly extension for Visual Studio Code | prb28 | Coders. Asm / Hardware | 342 | 15 December 2023 21:22 |
Amiga Assembly exension for Visual Studio Code 0.19 released | prb28 | Coders. General | 2 | 02 January 2020 18:34 |
assembly code to test for assign (2.0+) | jotd | Coders. System | 2 | 27 December 2017 23:16 |
Beneath a steel sky, code word check | Djay | support.Games | 1 | 20 February 2011 00:52 |
No sense error | Exodus | support.WinUAE | 6 | 26 June 2003 04:29 |
|
|