Author Topic: [3.7.2-ARM] Unaligned Memory Access at modeloctant.cpp:28 (title edited)  (Read 10101 times)

0 Members and 1 Guest are viewing this topic.

Offline taylor

  • Super SCP/Linux Guru
  • Moderator
  • 212
    • http://www.icculus.org/~taylor
Re: [3.7.2-ARM] Unaligned Memory Access at modeloctant.cpp:28 (title edited)
That looks good, but you should also check to see if the frontlist, etc. variables are divisible by 4.  That could cause the same issue.
I'm not looking at the code, but those are just offsets of p, right? In which case chunk_size alignment will determine alignment of the rest.

 

Offline ShivanSpS

  • 210
Re: [3.7.2-ARM] Unaligned Memory Access at modeloctant.cpp:28 (title edited)
-removed-
« Last Edit: August 25, 2020, 11:14:28 am by ShivanSpS »

 

Offline ShivanSpS

  • 210
Re: [3.7.2-ARM] Unaligned Memory Access at modeloctant.cpp:28 (title edited)
-removed-
« Last Edit: August 25, 2020, 11:14:39 am by ShivanSpS »

 

Offline Goober5000

  • HLP Loremaster
  • Moderator
  • 214
    • Goober5000 Productions
Re: [3.7.2-ARM] Unaligned Memory Access at modeloctant.cpp:28 (title edited)
That looks good, but you should also check to see if the frontlist, etc. variables are divisible by 4.  That could cause the same issue.
I'm not looking at the code, but those are just offsets of p, right? In which case chunk_size alignment will determine alignment of the rest.

If I understand the code correctly, they are byte offsets of p.  The model_octant_find_faces_sub function is passed a pointer which is p plus a number, and p is of type ubyte.

 

Offline ShivanSpS

  • 210
Re: [3.7.2-ARM] Unaligned Memory Access at modeloctant.cpp:28 (title edited)
-removed-
« Last Edit: August 25, 2020, 11:14:53 am by ShivanSpS »

 

Offline Goober5000

  • HLP Loremaster
  • Moderator
  • 214
    • Goober5000 Productions
Re: [3.7.2-ARM] Unaligned Memory Access at modeloctant.cpp:28 (title edited)
Err, don't replace the BSP data with the aligned version.  Try just copying the bad chunk, aligning it, and passing it to the next function.  Then when the function returns, free the copy.  Don't touch the underlying bsp tree.

This implies the function will create and maintain recursive copies of sub-trees if the sub-trees are also unaligned, but as long as the copies aren't too large, this should be fine.  The tree is finite.

 

Offline ShivanSpS

  • 210
Re: [3.7.2-ARM] Unaligned Memory Access at modeloctant.cpp:28 (title edited)
-removed-
« Last Edit: August 25, 2020, 11:15:07 am by ShivanSpS »

  

Offline Goober5000

  • HLP Loremaster
  • Moderator
  • 214
    • Goober5000 Productions
Re: [3.7.2-ARM] Unaligned Memory Access at modeloctant.cpp:28 (title edited)
It would be better to implement a proper fix, rather than a hack.  The reason Release builds still aren't working is probably because of the remaining unaligned calls.

I've asked chief1983 to tag the appropriate revision for 3.7.2.

 

Offline ShivanSpS

  • 210
Re: [3.7.2-ARM] Unaligned Memory Access at modeloctant.cpp:28 (title edited)
-removed-
« Last Edit: August 25, 2020, 11:15:22 am by ShivanSpS »

 

Offline mjn.mixael

  • Cutscene Master
  • 212
  • Chopped liver
    • Steam
    • Twitter
Re: [3.7.2-ARM] Unaligned Memory Access at modeloctant.cpp:28 (title edited)
Wtf. Is this thread serious? Amazing.
Cutscene Upgrade Project - Mainhall Remakes - Between the Ashes
Youtube Channel - P3D Model Box
Between the Ashes is looking for committed testers, PM me for details.
Freespace Upgrade Project See what's happening.

 
Re: [3.7.2-ARM] Unaligned Memory Access at modeloctant.cpp:28 (title edited)
Broadly speaking, x86 CPUs only incur a significant performance penalty for unaligned accesses when they straddle a cacheline boundary.  That's because software using unaligned accesses is so common in the x86 world that the hardware has been optimised to accommodate it.  This wasn't quite so true when Freespace was first released, but at worst you would incur a one-cycle delay per unaligned access.

Conversely, ARM CPUs are mostly still designed to be efficient first and fast second, on the grounds that an efficiently designed CPU might run fast anyway if the software is written properly.  The circuitry to handle unaligned accesses is therefore considered an unnecessary complexity, given that well-written software should avoid it; unaligned executable code is outright forbidden (as ARM instructions are all 4 bytes long).  This goes so far that unaligned accesses are not merely unoptimised, but totally unsupported in hardware.  To work around this when an unaligned access happens anyway, it is possible to handle the exception in software by replacing the single access with multiple byte-wide accesses, but of course this is slower and requires an extra temporary register; a single 32-bit load becomes a 7-instruction sequence (load byte 0, load byte 1, combine bytes, load byte 2…) that is difficult to run in parallel.  And that's ignoring the major overhead of taking the exception in the first place.

I think it would be wise to at least process all the mods in Knossos to ensure they have proper alignment, as well as patching the tools to make them produce aligned output in the first place.  But to allow the apparently large corpus of misaligned mods to run on ARM, an alignment workaround does need to be added to the loader.

 

Offline chief1983

  • Still lacks a custom title
  • Moderator
  • 212
  • ⬇️⬆️⬅️⬅️🅰➡️⬇️
    • Minecraft
    • Skype
    • Steam
    • Twitter
    • Fate of the Galaxy
Re: [3.7.2-ARM] Unaligned Memory Access at modeloctant.cpp:28 (title edited)
My god what have we done

As for the tag for 3.7.2, it doesn't exist because we weren't even on Git yet.  The quote from the release post concerns me though:  "It is an export of 3.7.2 branch r11329".  I don't see a 3.7.2 branch in our git even though most of the older branches were created.  Someone got too aggressive with branch pruning I think and deleted it.  Either way, I found the git commit was still on my fork and pushed a branch and tag for 3.7.2 up to the main repository.  Enjoy.
Fate of the Galaxy - Now Hiring!  Apply within | Diaspora | SCP Home | Collada Importer for PCS2
Karajorma's 'How to report bugs' | Mantis
#freespace | #scp-swc | #diaspora | #SCP | #hard-light on EsperNet

"You may not sell or otherwise commercially exploit the source or things you created based on the source." -- Excerpt from FSO license, for reference

Nuclear1:  Jesus Christ zack you're a little too hamyurger for HLP right now...
iamzack:  i dont have hamynerge i just want ptatoc hips D:
redsniper:  Platonic hips?!
iamzack:  lays

 

Offline ShivanSpS

  • 210
Re: [3.7.2-ARM] Unaligned Memory Access at modeloctant.cpp:28 (title edited)
-removed-
« Last Edit: August 25, 2020, 11:15:43 am by ShivanSpS »

 

Offline ShivanSpS

  • 210
Re: [3.7.2-ARM] Unaligned Memory Access at modeloctant.cpp:28 (title edited)
-removed-
« Last Edit: August 25, 2020, 11:15:58 am by ShivanSpS »

 

Offline Goober5000

  • HLP Loremaster
  • Moderator
  • 214
    • Goober5000 Productions
Re: [3.7.2-ARM] Unaligned Memory Access at modeloctant.cpp:28 (title edited)
By all means, update the wiki where it needs updating.  I have created an account for you using your HLP email.

 

Offline ShivanSpS

  • 210
Re: [3.7.2-ARM] Unaligned Memory Access at modeloctant.cpp:28 (title edited)
Thanks Goober, i will update the wiki once im done with this.

Question: Does someone know what information is used in modelcollide.cpp, void model_collide_parse_bsp(bsp_collision_tree *tree, void *model_ptr, int version)? Because i managed to fix the pofs enoght to make them load on 3.7.2 Debug whiout any code modifications, but release still crashes on that function with a bus error, most likely on those vec3d i mentioned earlier.
« Last Edit: December 01, 2019, 09:11:18 pm by ShivanSpS »

 

Offline Goober5000

  • HLP Loremaster
  • Moderator
  • 214
    • Goober5000 Productions
Re: [3.7.2-ARM] Unaligned Memory Access at modeloctant.cpp:28 (title edited)
You can browse the code on GitHub:
https://github.com/scp-fs2open/fs2open.github.com/blob/master/code/model/modelcollide.cpp#L733

EDIT: Actually you would have had to have the code to make modifications.  What do you mean, does anyone know what information is used?

 

Offline ShivanSpS

  • 210
Re: [3.7.2-ARM] Unaligned Memory Access at modeloctant.cpp:28 (title edited)
-removed-
« Last Edit: August 25, 2020, 11:16:15 am by ShivanSpS »

 

Offline Goober5000

  • HLP Loremaster
  • Moderator
  • 214
    • Goober5000 Productions
Re: [3.7.2-ARM] Unaligned Memory Access at modeloctant.cpp:28 (title edited)
¯\_(ツ)_/¯

Honestly, I think you are the person who understands this the most - certainly the person who has studied this to this level of detail in the past 10 years.

All I can say is to break down the problem into manageable tasks, take things one at a time, take baby steps, and try to squash the problems one by one.  Feel free to keep posting your progress in this thread though; if we have any insight to offer, we will certainly chime in.

 

Offline ShivanSpS

  • 210
Re: [3.7.2-ARM] Unaligned Memory Access at modeloctant.cpp:28 (title edited)
-removed-
« Last Edit: August 25, 2020, 11:16:28 am by ShivanSpS »