• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: When is an unaligned memory access illegal on ARM?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: When is an unaligned memory access illegal on ARM?


  • Subject: Re: When is an unaligned memory access illegal on ARM?
  • From: Jens Alfke <email@hidden>
  • Date: Sun, 22 Jun 2014 19:18:31 -0700


On Jun 22, 2014, at 4:22 PM, Roland King <email@hidden> wrote:

LDR supports unaligned access on newer hardware (as long as the correct bit is set in the CPU/coprocessor?). LDRD doesn't support it and the address needs to be 8-byte aligned. 

Then the optimizer seems to have made a mistake by being overly eager to use ldrd. Here’s the function in question. At the point of the crash the optimizer noticed that two consecutive uint32_t values were being read from the pointer ‘cur’, so ldrd would be an efficient way to read them; except that there’s no guarantee in the code that ‘cur’ is 8-byte aligned. The input is an arbitrary unaligned pointer.

—Jens


uint32_t crc32_8(void* data, size_t len, uint32_t prev_value)
{
    uint32_t *cur = (uint32_t*) data;
    uint32_t crc = ~prev_value;

    while (len >= 8) {
        uint32_t _one_ = *cur++ ^ crc;    // <---CRASHES
        uint32_t two = *cur++;
        crc =
            crc_lookup[7][(one    ) & 0xFF] ^
            crc_lookup[6][(one>> 8) & 0xFF] ^
            crc_lookup[5][(one>>16) & 0xFF] ^
            crc_lookup[4][(one>>24) & 0xFF] ^
            crc_lookup[3][(two    ) & 0xFF] ^
            crc_lookup[2][(two>> 8) & 0xFF] ^
            crc_lookup[1][(two>>16) & 0xFF] ^
            crc_lookup[0][(two>>24) & 0xFF];
        len -= 8;
    }

    unsigned char *cur_byte = (unsigned char*) cur;
    while (len--)
        crc = (crc >> 8) ^ crc_lookup[0][(crc & 0xFF) ^ *cur_byte++];

    return ~crc;
}


—Jens
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: When is an unaligned memory access illegal on ARM?
      • From: Roland King <email@hidden>
References: 
 >When is an unaligned memory access illegal on ARM? (From: Jens Alfke <email@hidden>)
 >Re: When is an unaligned memory access illegal on ARM? (From: Roland King <email@hidden>)

  • Prev by Date: Re: When is an unaligned memory access illegal on ARM?
  • Next by Date: Re: When is an unaligned memory access illegal on ARM?
  • Previous by thread: Re: When is an unaligned memory access illegal on ARM?
  • Next by thread: Re: When is an unaligned memory access illegal on ARM?
  • Index(es):
    • Date
    • Thread