• 2 Posts
  • 15 Comments
Joined 2 years ago
cake
Cake day: June 10th, 2023

help-circle

  • I believe the optimization came because the denominator was a power of two. In my memory, the function counted up all of the bytes being sent and checked to see that the sum was a power of 16 (I think 16 bytes made a single USB endpoint or something; I still don’t fully understand USB).

    For starters, you can split up a larger modulo into smaller ones:

    X = (A + B); X % n = (A % n + B % n) % n

    So our 16 bit number X can be split into an upper and lower byte:

    X = (X & 0xFF) + (X >> 8)

    so

    X % 16 = ((X & 0xFF) % 16 + (X >>8) % 16) % 16

    This is probably what the compiler was doing in the background anyway, but the real magic came from this neat trick:

    x % 2^n = x & (2^n - 1).

    so

    x % 16 = x & 15

    So a 16 bit modulo just became three bitwise ANDs.

    Edit: and before anybody thinks I’m good a math, I’m pretty sure I found a forum post where someone was solving exactly my problem, and I just copy/pasted it in.

    Edit2: I’m pretty sure I left it here, but I think you can further optimize by just ignoring the upper byte entirely. Again, only because 16 is a power of 2 and works nicely with bitwise arithmatic.












  • Thanks for the tips!

    To clarify, by “x99,” do you mean LGA2011-3? That’s the socket wikipedia associates with the hardware.

    And as for Arc, it looks like they’re a great option for video encoding. I’m actually using QuickSync already on my Celeron processor which has helped. From what I can understand, it looks like QuickSync is basically the same processor on all of the Arc cards, so I can just go with the cheapest card if I don’t plan to use much of the other features? Looking like an A380 can be had for $100 or so.





  • I can kind of see the logic.

    Like book piracy was never a huge thing because you’d need a hell of a set up to make a book from scratch. Music piracy however…

    I’m sure a decently skilled craftsman could make a decent firearm with a short trip to Home Depot, but the average Joe can’t make that happen too easily. With a 3D printer, you could have a gun with next to zero skill. Like a decently motivated person is going to find a gun anyway, but this maybe addresses the less motivated people/crimes of passion, etc.

    That being said, if these are the same people advocating for a waiting period, they obviously don’t know how long 3D printing a gun takes.

    Edit: for those downvoting, I’m not saying this is a good idea. I think the same result could be had by going after whoever is hosting the design files. Like at least keep them off thingiverse and make them slightly hard to find.