6 ms·
Mandelbrot in x86 Assembly by Claude
- piker 1y agoI actually expected the struggle to continue based on experience. Though these things can produce some magical results sometimes.
- askl 1y agoAscii art mandelbrot seems like the perfect toy example with tons of examples to copy from. That's what LLMs are really good at.
- pixelpoet 1y agoNot to be confused with the excellent Mandelbook[0] and related work on the Mandelbrot[1] by Claude Heiland-Allen :) [0]: https://mathr.co.uk/mandelbrot/book-draft-2017-11-10.pdf https://mathr.co.uk/mandelbrot/book-draft-2017-11-10.pdf [1]: https://mathr.co.uk/web/mandelbrot.html https://mathr.co.uk/web/mandelbrot.html
- 0x000xca0xfe 1y agoThis is great, thank you!
- pixelpoet 1y agoYeah it's an excellent resource, ditto all of mathr.co.uk :) If you'd like to join our great little fractal community, here's a Discord invite link: https://discord.gg/beKyJ8HSk5 https://discord.gg/beKyJ8HSk5
- suddenlybananas 1y agoGoogling "Mandelbrot set in assembly" returns a bunch of examples of this.
- pinoy420 1y ago[dead]
- djaychela 1y agoIt does.... I was just surprised that it turned up as terminal output - for some reason I was expecting something in some form of GUI window for some OS or other but I guess that's orders of magnitude more complex and more likely to not work. But he did actually ask for ASCII output, so that does make sense - unlike my assumption!
- ale42 1y agoI think that opening a window and rendering something inside it using the native Win32 API from assembly code on Windows would not be so terrifyingly complex. It's just more code as it needs to call the appropriate GUI APIs (not just syscalls), and it's OS-specific... but such code is anyway always OS-specific (the one mentioned here seems to be for Linux, given the used syscalls). No idea how complex it would be with X or on Mac, as I don't know their low-level GUI APIs.
- userbinator 1y agoI wonder how many demoscene productions it was trained on. Probably not many, because stuff like this sticks out like a sore thumb: xor eax, eax ; z_real = 0 xor ebx, ebx ; z_imag = 0 mov ecx, 0 ; iteration counter
- 01HNNWZ0MV43FF 1y agoI haven't done much asm - I'm guessing that a human would do `xor ecx, ecx` as well?
- 6mian 1y agoYes.
- iamflimflam1 1y agoYeah - this is pretty standard code.
- varispeed 1y agoIt's supposed to be faster than mov ecx, 0.
- rep_lodsb 1y agoCould have done worse: loop $
- johnisgood 1y agoHave you found anything else? If so, could you provide rationale?
- Jare 1y agoMight be interesting to try this in ARM assembly where it's a lot less likely to be existing code in the training set.
- noone_youknow 1y agoI’ve been trying out various LLMs for working on assembly code in my toy OS kernel for a few months now. It’s mostly low-level device setup and bootstrap code, and I’ve found they’re pretty terrible at it generally. They’ll often generate code that won’t quite assemble, they’ll hallucinate details like hardware registers etc, and very often they’ll come up with inefficient code. The LLM attempt at an AP bootstrap (real-mode to long) was almost comical. All that said, I’ve recently started a RISC-V port, and I’ve found that porting bits of low-level init code from x86 (NASM) to RISC-V (GAS) is actually quite good - I guess because it’s largely a simple translation job and it already has the logic to work from.
- LtdJorge 1y agoA bit tangential, but I've found 4 Sonnet to be much, much better at SIMD intrinsics (in my case, in Rust) than Sonnet 3.5 and 3.7, which were kind of atrocious. For example, 3.7 would write a scalar for loop and tell you "I've vectorized...", when I explicitly asked to do the operations with x86 intrinsics and gave it the capabilities of the hardware. Also, telling it to use AVX2 as supported would not make it use SSE or it would make conditionals to use them, which makes no sense. Seems Claude 4 solves most of that. Edit: that -> than
- noone_youknow 1y agoThis fits my experience. I’m definitely getting considerably better results with 4 than previous Claudes. I’d essentially dropped sonnet from my rotation before 4 became available, but now it’s a go-to for this sort of thing.
- vidarh 1y agoSimilar experience - they seem to generally have a lot more problems with ASM than structured languages. I don't know if this reflects less training data, or difficulty.
- 73kl4453dz 1y agoAs far as i can tell they have trouble with sustained satisfaction of multiple constraints, and asm has more of that than higher level languages. (An old Boss once said his record for bug density was in asm: he'd written 3 bugs in a single opcode)
- horsellama 1y agoOP may want to test this setup here [0]. This is a bit more challenging than replacing a google query with a LLMs pipeline [0] https://code.golf/mandelbrot#assembly https://code.golf/mandelbrot#assembly
- worldsayshi 1y agoGiven the price of Claude Code I'm surprised that not more people go the route of using claude through aider with copilot or something like that. Is Claude Code the tool worth the extra expense?
- petercooper 1y agoIt's a lot more agentic. I'm an Aider fan and use it the most because I prefer its simplicity, but it tends to require you be more "involved" in development and decision making than tools like Claude Code which can cycle around more on their own to figure things out and make decisions (which might not be the ones you want).
- wiz21c 1y ago> which might not be the ones you want And in your experience, how often is that ?
- petercooper 1y agoHard to quantify, but as an opinionated developer I've found that AI systems with too much leash will often head off in directions I don't appreciate and have to undo. This is desirable in areas where I have less knowledge or want more velocity, though, but a tighter cycle with smaller steps enables me to maintain more of my taste through making more concrete decisions rather than merely pointing a direction.
- ur-whale 1y agoThe code seem to be doing calculations with integers instead of floats. If so, why?
- danbruc 1y agoFloating point calculations used to be a lot slower than integer calculations so it was very common to use fixed point numbers. Also for good performance, you would usually not do what this code does, calculate the coordinates for each pixel explicitly. Instead you would calculate the coordinates of the starting corner and the delta between adjacent pixels and then just add the delta each time you move to the next pixel. That is also generally easier to do with fixed point numbers as adding 0.1 with floating point numbers a 1000 times will not yield 100 because 0.1 is not exactly representable with base 2 floating point numbers. For this visualization this probably does not matter too much, but if you care that you are not slightly off and you want to calculate stuff incrementally, then doing it in fixed point might make things easier. I have no clue about the first point on current hardware, if floating point calculations are still notably less performant, if there is a relevant difference in the number of execution units and so on.
- adrian_b 1y agoIn very old CPUs and in many microcontrollers, floating-point operations are slower than integer operations. However, in many old but not very old CPUs, e.g. in many from the last decade of the 20th century and from the first decade of this century, floating-point multiplication and division were much faster than integer multiplication and division. So for those CPUs, which include models like Pentium 4, or even the first Intel Core models (those older than Nehalem, which got a dedicated integer multiplier), there were many cases when converting an integer computation into a floating-point computation could increase the speed many times.
- egil 1y agoMaybe it would have generated with floats if it was prompted for a generator in x87 assembly? It did originate as an extension to x86 on a separate chip, so it could explain the AI sticking to integers.
- sipsi 1y agoIt can also do a pretty good 3d star field: https://godbolt.org/z/a7v4xnbef https://godbolt.org/z/a7v4xnbef First try worked but didn't use correct terminal size.
- aargh_aargh 1y agoTangent: godbolt.org greeted me with a popup but boy, I have never seen a clearer privacy notice, minimal possible data retention, including a diff with the last version. Great job, Matt!
- revskill 1y agoLlm is useless in real world codebase. Tons of hallucination and nonsense. Garbagd everywhere. The danger thing is they messed things up rdomly, o consistence at all. It is fine to treat it as a better autocompletion tool.
- broken_broken_ 1y agoThe x64 assembly would probably work natively on the Mac, no need for docker, provided the 2 syscall numbers (write and exit) are adjusted. Which llms can likely do. If it’s an ARM Mac, under Rosetta. Otherwise directly.
- abujazar 1y agoDeepSeek actually does this is one go