Results 1 to 3 of 3

Thread: Curious case of !sudden! AVs on ARM due to packed records

  1. #1

    Curious case of !sudden! AVs on ARM due to packed records

    In this particular case, Raspberry Pi 2 (ARMv7l / fpc 2.6.4).
    I always had my application-wide data organized in a tree of records. *Packed* records.
    It always worked.
    Then, on RPi2, I loaded GLES2... and suddenly got hit in my face with an AV at the first attempt of float division of two longints.
    I was stumped.
    I was frustrated.
    The cause...? GLES obviously changed some flags and float math stopped working on *unaligned* data.
    Comrades @ freepascal.ru looked at me like I was nuts (unaligned records? on ARM? That couldn't work even in theory!)
    And yet it was working. At least until... Yeah.
    So I solved it using {$packrecords 4} and {$ifndef cpuarm}packed{$endif}

  2. #2
    If there's any padding between record's fields because of differently sized datatypes, you could also try reordering the fields. For example, if you mix booleans with integers (which misaligns them if the record is packed), put the integer fields before all the booleans, etc.

  3. #3
    PGD Staff / News Reporter phibermon's Avatar
    Join Date
    Sep 2009
    Location
    England
    Posts
    524
    You're essentially dealing with two devices, the CPU and the GPU - both access structured/ordered data in their own way - so when transferring data between the two? a factor such as record byte alignment can't be assumed in any case where the GPU and CPU could potentially differ. So in all cases on any platform - I would recommend that knowing and managing data alignment be considered part of standard best practice as is knowing and managing platform endiness.
    When the moon hits your eye like a big pizza pie - that's an extinction level impact event.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •