Hacker Newsnew | past | comments | ask | show | jobs | submit | windenntw's commentslogin

Correct, but also beside the point.

To do it in almost-plain C, you'd need fairly complex macros that are more difficult to write correctly.

To do it in plain C without macros, or plain C++ without templates... you'd need to work out the combination of the template expansion yourself and write down a piece of code that is more likely to have bugs and more difficult to understand.


I'm not quite sure: you could probably use plain C functions, and a reasonably smart compiler could see through it all and inline and duplicate and merge the code as necessary.

EDIT: I just had an AI agent run the experiment. At least for my version of clang, they produce the same assembly for x86_64 (modulo using slightly different registers).


This is called template-based compile-time programming.

By making 3 instances of linear_feedback_shift_engine class template ( and 2 of xor_combine_engine ), you are forcing the compiler to expand the code exactly as-is 3 times, each with different parameters.

The parameters to the template are constant, therefore the compiler can easily look at how they are used and you are guaranteed ( even in a 1999 c++ compiler ) that the compiler will look at the copies of the code and merge them as much as possible into a single piece of code... which is the one that you see when you decompile the code.

So in summary, it means that you get to write fairly readable code while the final binary is fully optimized as-if you had spent the time merging all the variants as needed for the specific constants.


My point is that the straight-line non-templated function presented later in the article is significantly more readable, it’s like 8 lines of code with a few shifts and xors.

You could get something similar from CPP macros. But the compiler wouldn't be able to help you as much.

This is essentially the way many 8 bit games did 3d rendering ( for example the world famous Elite )... you just need two tables, one linear2log and another log2linear, with careful measurement of the ranges and number of elements needed in you application ( which is easy for inference ).

ps. Also used in the original circuits of the Yamaha DX7 synthetiser ( https://www.righto.com/2021/11/reverse-engineering-yamaha-dx... ).


Greetings from Spain!

We somehow got a copy of Defy diskmag, started swapping with Cro^Cydonia and got to enjoy Satisfaction Guaranteed by Pearl :)

I always did all my small tools and stuff in blitz basic 2, would dump binary file and incbin them in Devpac.

-- winden^TNC^Network

[ https://www.pouet.net/prod.php?which=14404 and https://www.pouet.net/prod.php?which=7645 ]


Can confirm all sceners call it sinus in Spain :)


Thats an excellent idea. I've created https://gemini.google.com/gem/17xMogBqRSc2AtdCC-WRfObgHcceD0... and tested it with a couple conversations and it works great :)


Nice, it works for discussing concepts baked into the LLM but fails when you want it to read contents of an article or do web search. ChatGPT Live doesn’t have this limitation. Their Voice mode did have this limitation, but the Live mode released a couple weeks ago works exactly as you’d want, with link-following and web search


Protip: all modern monitors and TVs can still run at 50HZ and you can configure Linux to use it all the time --> zero vsync micro jumps when running european software under ZX, Amiga or C64 emulators :)


The memory requirement is actually not a problem, because you may be able to stream the mp3 from a harddisk ( easily 159 KB per second from a 2.5 inch ide disk when used on a 7mhz 68000 of amiga 600) or maybe even from a floppy ( 10 KB per second on a double density floppy ).

The actual problem is that mp3 decoding requires lots of math, and the total cpu usage to decode at 22Khz mono is the equivalent of a 68030 running at 50mhz, which is more or less 5 times as much CPU as a 68000 running at 16mhz.


For me: January = up, April = left, July = down, October = right.

Never sure why I did this association, maybe it comes from a drawing in a book I read when I was six or somthn?


Here is one in plain 68000 assembler.

  move.b #200,d0
  move.b #100,d1
  add.b  d0,d1   ; 8th bit goes to X flag
  subx.b d0,d0   ; d0 = $00 or $ff depending on X flag
  or.b   d0,d1   ; d1 = 255 if there was saturation
You can do the same with all others that somehow store the 8th bit carry somewhere then allow using it for substraction.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: