• Wilzax@lemmy.world
    link
    fedilink
    English
    arrow-up
    0
    ·
    1 day ago

    Your game will actually likely be more efficient if written in C. The gcc compiler has become ridiculously optimized and probably knows more tricks than you do.

    • s_s@lemm.ee
      link
      fedilink
      English
      arrow-up
      0
      ·
      1 day ago

      Write it in Rust, and it’ll never even leak memory.

      • Wilzax@lemmy.world
        link
        fedilink
        English
        arrow-up
        0
        ·
        1 day ago

        If you’re writing sloppy C code your assembly code probably won’t work either

          • calcopiritus@lemmy.world
            link
            fedilink
            English
            arrow-up
            0
            ·
            8 hours ago

            I recently came across a rust book on how pointers aren’t just ints, because of UB.

            fn main() {
                a = &1
                b = &2
                a++
                if a == b {
                    *a = 3
                    print(b)
                }
            }
            

            This may either: not print anything, print 3 or print 2.

            Depending on the compiler, since b isn’t changed at all, it might optimize the print for print(2) instead of print(b). Even though everyone can agree that it should either not print anything or 3, but never 2.

          • Buddahriffic@lemmy.world
            link
            fedilink
            English
            arrow-up
            0
            ·
            11 hours ago

            A compiler making assumptions like that about undefined behaviour sounds just like a bug. Maybe the bug is in the spec rather than the compiler, but I can’t think of any time it would be better to optimize that code out entirely because UB is detected rather than just throwing an error or warning and otherwise ignoring the edge cases where the behaviour might break. It sounds like the worst possible option exactly for the reasons listed in that blog.

    • dejected_warp_core@lemmy.world
      link
      fedilink
      English
      arrow-up
      0
      ·
      1 day ago

      Especially these days. Current-gen x86 architecture has all kinds of insane optimizations and special instruction sets that the Pentium I never had (e.g. SSE). You really do need a higher-level compiler at your back to make the most of it these days. And even then, there are cases where you have to resort to inline ASM or processor-specific intrinsics to optimize to the level that Roller Coaster Tycoon is/was. (original system specs)

      • KubeRoot@discuss.tchncs.de
        link
        fedilink
        English
        arrow-up
        0
        ·
        15 hours ago

        I might be wrong, but doesn’t SSE require you to explicitly use it in C/C++? Laying out your data as arrays and specifically calling the SIMD operations on them?

        • acockworkorange@mander.xyz
          link
          fedilink
          English
          arrow-up
          0
          ·
          14 hours ago

          There’s absolutely nothing you can do in C that you can’t also do in assembly. Because assembly is just the bunch of bits that the compiler generates.

          That said, you’d have to be insane to write a game featuring SIMD instructions these days in assembly.

          • Wilzax@lemmy.world
            link
            fedilink
            English
            arrow-up
            0
            ·
            6 hours ago

            Technically assembly is a human-readable, paper-thin abstraction of the machine code. It really only implements one additional feature over raw machine code and that’s labels, which prevents you from having to rewrite jump and goto instructions EVERY TIME you refactor upstream code to have a different number of instructions.

            So not strictly the bunch of bits. But very close to it.

          • Buddahriffic@lemmy.world
            link
            fedilink
            English
            arrow-up
            0
            ·
            11 hours ago

            I think they meant the other way around, that if you wanted to use it in C/C++, you’d have to either use assembly or some specific SSE construct otherwise the compiler wouldn’t bother.

            That probably was the case at one point, but I’d be surprised if it’s still the case. Though maybe that’s part of the reason why the Intel compiler can generate faster code. But I suspect it’s more of a case of better optimization by people who have a better understanding of how it works under the hood, and maybe better utilization of newer instruction set extensions.

            SSE has been around for a long time and is present in most (all?) x86 chips these days and I’d be very surprised if gcc and other popular compilers don’t use it effectively today. Some of the other extensions might be different though.