‹ BackHN Continuity

Thread

Dirty Optimization Secrets (C for Playdate)

69 points · 8 comments · ibobev

Loading the complete thread in the background. This saved snapshot is available now. Refresh

  1. Joker_vD · · focus · HN ↗
    ...you know, that reads somewhat like "The Case for Complex Instruction Set Computer". In fact, it straight up demolishes the very first of the core premises of the famous "Case for RISC" paper: that the memory speed has finally caught up with the CPU speed. Nope, it hasn't. The same goes for its "Code Density" argument: nope, code density is very important.

    Then again, the original "Case for RISC" paper was misnamed; it's really "Case Against CISC": Patterson and Ditzel are very careful to never state what, exactly, do they mean by "RISC" they're supposedly advocating for, nor do they actually advocate for it — they mostly just criticize the current ISAs and the overall design approach to them.

    1. pjmlp · · focus · HN ↗
      For me it reads more like, this is why most 8 and 16 bit home computer games that aimed for top performance were fully written in Assembly.
    2. throwawayk7h · · focus · HN ↗
      Well, the Playdate doesn't have the best hardware. The advice might not be relevant if coding for a mobile device or laptop.
  2. boricj · · focus · HN ↗
    That reminds me of some of the tricks I've used while tinkering with a voxel space rendering tech demo on the PlayStation.

    The quirks of that console for this is that the CPU takes a 6 cycle stall on any read from main RAM (it's not even stall-on-use) and doesn't have a data cache. That would make it a very poor fit for this, so I had to improvise a bunch of tricks to reclaim performance:

    - Made all of my hot loop fit within one function, so that it fits entirely in the 4 KiB direct-mapped instruction cache (so less than 1024 instructions)

    - Wrote a C++ template that can trampoline a function call into the 2 KiB scratchpad

    - Used the rest of the scratchpad for a CLUT table because it doesn't stall on read

    - Used the GTE to transform the N set of coordinates while the CPU stalls fetching the N+1 set of heightmap data

    - Figured ways to abuse the GTE into transforming more points per instructions than it theoretically can, taking advantage of simplified formulas compared to real 3D work

    - Write the rectangle primitives straight to the GPU registers instead of going through a display list

    It's such an abuse of the PlayStation that PCSX-Redux and DuckStation disagree on its performance by up to a factor of two. I should finish it someday and see how it runs on real hardware...

  3. nxobject · · focus · HN ↗
    The tips about laying out and carefully segmenting code are a blast from the past!
    1. ahartmetz · · focus · HN ↗
      The tips about mitigating unpredictable performance due to minor layout changes are unfortunately up to date.
  4. mococa · · focus · HN ↗
    Rembers me - <a href="https:&#x2F;&#x2F;graphics.stanford.edu&#x2F;~seander&#x2F;bithacks.html" rel="nofollow">https:&#x2F;&#x2F;graphics.stanford.edu&#x2F;~seander&#x2F;bithacks.html
  5. omoikane · · focus · HN ↗
    These optimizations are part of what makes Playdate development fun, since they are more rewarding on the Playdate than on other platforms with higher specs.

    (If you are the kind of person that finds optimizations fun, of course. There is a puzzle solving element of optimizing code that I really enjoy.)

  6. maxlin · · focus · HN ↗
    I just wish someone released a clone. The &quot;computer&quot; is worth like 5$. I&#x27;ve enjoyed programming and porting my 3D game engine to 20$ ESP32 devkits among others, and am looking for more &quot;crazy&quot; platforms. But I don&#x27;t even want to touch playdate due to its pricing stance, even though my office has an unused one in the store room.
    1. Wowfunhappy · · focus · HN ↗
      Do you mean the SOC costs $5? The Playdate has a screen, buttons, and comes with 24 (admittedly small-ish) games.

      I haven&#x27;t looked into how that all nets out, but when I think about how much a Raspberry Pi costs by itself vs the Pi + a case, screen, and peripherals... I don&#x27;t know, I can see how you&#x27;d end up around $230.

      1. maxlin · · focus · HN ↗
        Your math is off ~10x. The devkits I&#x27;ve developed for are literally 20$, both in 3.5 inch screen format, or smartwatch format, with a case, touchscreen, buttons, battery, realtime OS, RTC, wifi, tons of GPIO&#x27;s etc. Only hardware things playdate has on top is marginally higher build quality, the swivel (that most games don&#x27;t use) 10-20MB more RAM. Their decision to have a greyscale screen also saves them money, instead of a common full color one like those 20$ devkits have

        So it is beyond obvious that Playdate&#x27;s price does not even closely match their bill of materials.

        Even if you went up in power to a full Linux machine with 1GB+ of ram, there are obvious examples of devices like that like the RG3588 class. I have one, and it works nicely as a linux box running any software one can get running on aarch64 linux. Mine is relatively fancy and with postage cost me ~100$, but you can get a more &quot;basic&quot; one that is still way beyond Playdate on a hardware level, for about 40$.

        What playdate has is a walled garden. I don&#x27;t like walled gardens. Especially this far from release.

        You comparing to Nintendo&#x27;s first-party joycon pricing, I&#x27;m not sure you understand how deep walled gardens can be.

        1. Wowfunhappy · · focus · HN ↗
          &gt; the swivel (that most games don&#x27;t use)

          Most games I&#x27;ve played do use it, actually, even when I wish they hadn&#x27;t. (I really like the crank in many games, but some games go out of their way to use it when they should have stuck to buttons.)

          &gt; Their decision to have a greyscale screen also saves them money, instead of a common full color one like those 30$ devkits have.

          ...but the PlayDate&#x27;s screen doesn&#x27;t look like a typical LCD. It looks much closer to e-ink. (E-ink is even better, but the Playdate is maybe ~60% of the way there.)

          I did some very quick Googling and it looks like this type of screen, at the PlayDate&#x27;s size and resolution, costs about $30[1]. If the SOC is indeed $5 we&#x27;re now at $35 from just those two parts, before assembly or anything.

          &gt; You comparing to Nintendo&#x27;s first-party joycon pricing, I&#x27;m not sure you understand how deep walled gardens can be.

          But Nintendo also has economies of scale to work with that Panic does not. I&#x27;ve used third party Switch controllers, and they don&#x27;t feel as nice—I&#x27;m paying for quality. (Admittedly I don&#x27;t love how the PlayDate buttons feel either, they&#x27;re fine, not Nintendo quality!)

          I do agree that the Playdate is a game console, and when you buy a game console you&#x27;re paying for the cohesive ecosystem. PC gaming is better in basically every way but requires more work. Not much work, to be clear, but some.

          I&#x27;m not entirely satisfied with my Playdate btw, because I don&#x27;t love the game library. But it&#x27;s cute and I really like the software (not the games specifically), I&#x27;m a sucker for UIs that are polished to an extreme level.

          1: <a href="https:&#x2F;&#x2F;www.digikey.com&#x2F;en&#x2F;products&#x2F;detail&#x2F;sharp-microelectronics&#x2F;LS027B7DH01A&#x2F;5054067" rel="nofollow">https:&#x2F;&#x2F;www.digikey.com&#x2F;en&#x2F;products&#x2F;detail&#x2F;sharp-microelectr...

Open on Hacker News to reply ↗

Unofficial Hacker News client; not affiliated with Y Combinator.