1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Dismiss Notice

[Solved] Same C code, different result on x86 and ARM

Discussion in 'C /C ++' started by Linux-SWAT, Apr 9, 2018.

  1. Linux-SWAT

    Linux-SWAT Hardcore Member

    Joined:
    Feb 13, 2010
    Messages:
    8,002
    Hi,

    this is a Sobel filter.
    It compiles on x86_64 and ARM 32 and 64, and must be used with a 8bit grayscale .bmp .

    The problem is that the execution on ARM 32 and 64 produces a garbage image, and I have absolutely no idea why.

    I tried GCC 5 and 7 on ARM64.

    Any thoughts ?
     

    Attached Files:

    Tags:
    Gremblo likes this.
  2. elvissteinjr

    elvissteinjr Very Active Member

    Joined:
    Aug 23, 2013
    Messages:
    322
    Location:
    Germany
    I didn't test the code, but to me it looks like the unaligned memory access you do with the short pointers may be the culprit. You can get away with that on x86, but not ARM iirc.
     
    levi likes this.
  3. ptitSeb

    ptitSeb Serial Porter

    Joined:
    Aug 15, 2012
    Messages:
    7,906
    Location:
    France, near Lyon
    Maybe it's just the structure that need packing.
    try to add
    Code:
    #pragma pack(push, 1)
    
    befor the definition of the struct in the .h
    and
    Code:
    #pragma pack(pop)
    
    aftrer the definition
     
  4. Linux-SWAT

    Linux-SWAT Hardcore Member

    Joined:
    Feb 13, 2010
    Messages:
    8,002
    Pragma didn't help.
     
  5. PokeParadox

    PokeParadox Founder of Pirate Games - Penjin Coder Staff Member

    Joined:
    Dec 8, 2005
    Messages:
    6,488
    Location:
    UK
    It could be a different signedness of the bytes between x86/ARM?
     
    alxm, Gremblo, ptitSeb and 1 other person like this.
  6. ptitSeb

    ptitSeb Serial Porter

    Joined:
    Aug 15, 2012
    Messages:
    7,906
    Location:
    France, near Lyon
    Ah yes, it's important to build with "-fsigned-char" on ARM...
     
    Gremblo likes this.
  7. Linux-SWAT

    Linux-SWAT Hardcore Member

    Joined:
    Feb 13, 2010
    Messages:
    8,002
    Bingo !

    Thanks everyone for the help.
     

Share This Page

Loading...