GNU social JP
  • FAQ
  • Login
GNU social JPは日本のGNU socialサーバーです。
Usage/ToS/admin/test/Pleroma FE
  • Public

    • Public
    • Network
    • Groups
    • Featured
    • Popular
    • People

Conversation

Notices

  1. Embed this notice
    :umu: :umu: (a1ba@suya.place)'s status on Friday, 11-Apr-2025 01:14:20 JST :umu: :umu: :umu: :umu:
    big indian
    little indian

    sir please swap bytes
    In conversation about 2 months ago from suya.place permalink
    • Haelwenn /элвэн/ :triskell: likes this.
    • Embed this notice
      Haelwenn /элвэн/ :triskell: (lanodan@queer.hacktivis.me)'s status on Friday, 11-Apr-2025 01:31:01 JST Haelwenn /элвэн/ :triskell: Haelwenn /элвэн/ :triskell:
      in reply to
      @a1ba Meanwhile me who's read https://commandcenter.blogspot.com/2012/04/byte-order-fallacy.html

      DO NOT SWAP
      It's just encoding/decoding, and you're using a high-level language wtf.
      In conversation about 2 months ago permalink

      Attachments

      1. No result found on File_thumbnail lookup.
        The byte order fallacy
        Whenever I see code that asks what the native byte order is, it's almost certain the code is either wrong or misguided. And if the native b...
    • Embed this notice
      :umu: :umu: (a1ba@suya.place)'s status on Friday, 11-Apr-2025 01:31:02 JST :umu: :umu: :umu: :umu:
      in reply to
      DO NOT MEMCPY
      In conversation about 2 months ago permalink
    • Embed this notice
      Haelwenn /элвэн/ :triskell: (lanodan@queer.hacktivis.me)'s status on Friday, 11-Apr-2025 02:30:35 JST Haelwenn /элвэн/ :triskell: Haelwenn /элвэн/ :triskell:
      in reply to
      • [SUYA] ひみつ :blabcatverified:
      @ivesen @a1ba Nothing wrong with that one, it's decoding.
      And BSD got {be,le}{16,32,64}{dec,enc} as well.

      The one that's wrong is swapping, specially mindlessly because then instead of just "okay, it happens here" you end up having to hope for even/odd amounts of swapping.
      In conversation about 2 months ago permalink
    • Embed this notice
      [SUYA] ひみつ :blabcatverified: (ivesen@miniwa.moe)'s status on Friday, 11-Apr-2025 02:30:36 JST [SUYA] ひみつ :blabcatverified: [SUYA] ひみつ :blabcatverified:
      in reply to
      • Haelwenn /элвэн/ :triskell:
      @lanodan @a1ba me, looking at that blog post:
      what's wrong with ntohl()? (granted, I'm not sure a 64bit equivalent exists)
      In conversation about 2 months ago permalink
    • Embed this notice
      Haelwenn /элвэн/ :triskell: (lanodan@queer.hacktivis.me)'s status on Friday, 11-Apr-2025 02:45:24 JST Haelwenn /элвэн/ :triskell: Haelwenn /элвэн/ :triskell:
      in reply to
      • [SUYA] ひみつ :blabcatverified:
      @a1ba @ivesen Yeah compiler will optimise it, that said even just defining a macro for it is probably a good idea so the code is more readable and less chances of making a typo/off-by-one (at least doing it ifdef-free makes it easy to test).

      And well if compiler doesn't optimises it… I feel like modern CPUs will :D
      In conversation about 2 months ago permalink
    • Embed this notice
      :umu: :umu: (a1ba@suya.place)'s status on Friday, 11-Apr-2025 02:45:25 JST :umu: :umu: :umu: :umu:
      in reply to
      • Haelwenn /элвэн/ :triskell:
      • [SUYA] ひみつ :blabcatverified:
      @lanodan @ivesen there is always code that already exists and there is code that has to be written. For the first, swapping bytes in place is the way to go (especially that there aren't many big endian systems these days, anyway). For the latter... just do byte shifting thing, compiler will optimize it into single load anyway (though some people claim not all compilers do this)
      In conversation about 2 months ago permalink
    • Embed this notice
      Haelwenn /элвэн/ :triskell: (lanodan@queer.hacktivis.me)'s status on Friday, 11-Apr-2025 03:15:18 JST Haelwenn /элвэн/ :triskell: Haelwenn /элвэн/ :triskell:
      in reply to
      • [SUYA] ひみつ :blabcatverified:
      @ivesen @a1ba Huh.
      Meanwhile here it's optimising it: https://godbolt.org/z/Tfsqe4jc8
      In conversation about 2 months ago permalink

      Attachments

      1. Domain not in remote thumbnail source whitelist: raw.githubusercontent.com
        Compiler Explorer - C++ (x86-64 gcc 13.2)
        from Matt Godbolt
        int main() { uint8_t data[4]; ssize_t got = read(1, data, sizeof(data)); assert(got > 0); uint32_t little = (data[0]<<0) | (data[1]<<8) | (data[2]<<16) | (data[3]<<24); uint32_t big = (data[3]<<0) | (data[2]<<8) | (data[1]<<16) | (data[0]<<24); printf("little:%d big:%d", little, big); }
    • Embed this notice
      [SUYA] ひみつ :blabcatverified: (ivesen@miniwa.moe)'s status on Friday, 11-Apr-2025 03:15:20 JST [SUYA] ひみつ :blabcatverified: [SUYA] ひみつ :blabcatverified:
      in reply to
      • Haelwenn /элвэн/ :triskell:
      @lanodan @a1ba seems the BE->LE method suggested by the blog in question isn't optimized, while the byteswap that's argued against is.
      will this ever matter? :blobshrug:

      https://godbolt.org/z/bYcvcvMvh
      In conversation about 2 months ago permalink

      Attachments

      1. Domain not in remote thumbnail source whitelist: raw.githubusercontent.com
        Compiler Explorer - C
        from Matt Godbolt
        int func(char *data){ int i = (data[3]<<0) | (data[2]<<8) | (data[1]<<16) | (data[0]<<24); return i; } int func2(char *data) { int i = *((int*)data); /* swap the bytes */ i = ((i&0xFF)<<24) | (((i>>8)&0xFF)<<16) | (((i>>16)&0xFF)<<8) | (((i>>24)&0xFF)<<0); return i; } int func3(char *data) { int i = *((int*)data); return ntohl(i); }

Feeds

  • Activity Streams
  • RSS 2.0
  • Atom
  • Help
  • About
  • FAQ
  • TOS
  • Privacy
  • Source
  • Version
  • Contact

GNU social JP is a social network, courtesy of GNU social JP管理人. It runs on GNU social, version 2.0.2-dev, available under the GNU Affero General Public License.

Creative Commons Attribution 3.0 All GNU social JP content and data are available under the Creative Commons Attribution 3.0 license.