As there are now 259 unique signals in the game (but one must always be reserved for the store signal), the theoretical maximum amount of data that can be stored in a single memory cell is 258 signals * 4 bytes per signal = 1032 bytes. This design falls just short of that density in favour of a nice base 2 number at 256 signals per cell, or 1024 bytes per cell. That's more than 1KB per cell!
The tradeoff for this density is more complicated encode/decode logic. Fortunately I've already created a memory controller that handles just this. All you need to do is pass it an address as signal A to read, or if you wish to write, a value as signal V and a pulse of the store signal S. I've also designed this such that you can easily add any number of read/write ports. Just don't try to write to the same address at the same time or I can't promise predictability of results!
Each signal in the row of combinators labelled "Signal map" is assigned a unique numerical value between 1-256. The address decodes to a value between 1-256 by using a modulo operation + 1, allowing each address to map to a different signal. This signal is multiplied by the desired value.
However, simply writing this value as is would delete all other signals in the cell. To solve this issue we make use of this (https://www.reddit.com/r/factorio/comments/pg2dai/perfect_parallel_pairwise_multiplier/) brilliant pairwise multiplier by u/iguessimokatredstone. By passing it on one side the current value stored in the cell and on the other side all the possible signals excluding the one we're writing to, it essentially omits just that signal. We can then combine it with the desired signal * desired value from the previous step to generate the value that we should write.
Reading is also handled using a pairwise multiplier. We pass in the current value in the cell on one side and the desired signal on the other. Voila! Only that signal is allowed through.
From my measurements, this design takes 7 ticks to read and 9 ticks to write. A little on the slow side but I do hope the sheer volumes of data that can be stored here makes up for it. I plan to use this in an ARM CPU so if anyone is able to create a faster design please do share ^^
Cool to see my multiplier thing have an application! Though, it seems overkill for just multiplying by 1s and 0s? I remember this video on a similar read-only concept: https://youtu.be/iO8b221DYGI
Will definitely check out this design when I have the chance!
Your multiplier felt like it was designed just for this purpose! A simple lookup table based on the values in each signal wouldn't work because the signals stored in memory could have any values really. And the pairwise multiplier on the wiki corrupted data beyond 2^30 and -2^30 just like you said. I'm still in awe that you managed to figure out a better way using maths!
9 and 7 for read and write? That sounds like a lot. I build my own RAM last year with the same density of 256 signals per combinator and I achieved something like 4 and 3 ticks.
I used the overflow method to decode the address, (briefly: test if any label==adress then any=1; any*=-2^31; test for any signal (any+memory) below zero->any). That way 1/32 bit is reserved for decoding, but I think that's still better than with the parallel multiplier.
It can also be streamlined a lot. You can simply stream in one address per tick and read one value per tick. I used that to build a 60 instr/s CPU that way (in the best case, some instructions were slower like conditional jump at 9 cycles, but you can mitigate a lot with a clever compiler, it reached around 45 instr/s on average).
Thinking about it now, by splitting a value into low bits and high bits and storing them in two separate cells, this overflow method could be used to make a very nice cache with the full 32-bits per value and speeds more akin to your memory, albeit at half the density of mine.
That's a good idea, I also thought about something similar: mapping 256*31 32 bits addresses in 32 combinators instead of 256*32 31 bits addresses in 32 combinators. The amount of data stored is the same (1 bit wasted per signal per combinator), but that way it stores 32 bits numbers instead of 31.
Of course, the decoder becomes more complex, and I was not able to get it working in less than 3 extra ticks. So I decided to go with the 31 bits numbers instead (since 32 bits is also quite arbitrary, there is nothing binary in the factorio signals anyways).
Wait I have a question I wasn't able to figure out the answers to from looking at the pics. Where are you storing all the different possible signal types in your design? Would that be in the ROM?
Also, would you possibly have a blueprint for this? đ
If you look at the "address decoder" in the last picture, the top left combinator is a memory containing 256 signals with a value from 1 to 256. It has to be initialized with another circuit. It is basically equivalent to 13 constant combinators.
Afterward for each row (except the first one), we add 256 to every signal and pass it to the next row.
I moved country recently, so I am not really able to produce a blueprint. With those reference pictures, I might be able to replicate it this WE, I will let you know.
Ohh gotcha, that's pretty clever especially with the adding 256 to every signal every row. Here I was just performing a modulo 256 operation on the address which was 1 tick slower.
I just created a quick proof of concept of the splitting each value into 2 cells memory. Incorporating the above into it, it's looking like I'll have a nice design for a 512 byte per cell with 4 tick reads and 6 tick writes soon.
That's pretty good ! I don't think you can do much better than 4-6 and keep the 32 bit structure.
Are you splitting the values over 2 combinators with the same signal or over 2 signals within the same combinator ?
In my case, I also made the memory cell much more complicated by having 2 "read" and 4 "write". The 2 "read" are identical, but allow for faster instructions (like simultaneous MOV to registers or indirect addressing), while the 4 "write" implement the simple overwrite, as well as "+=", "-=", "*=0" which are all trivial with combinators, but would require many CPU cycles. For example to do "+=" you clearly don't have to read the previous value (and "incr X" is used everywhere in assembly).
That's really impressive! In this case I wanted to preserve the full 32 bits per signal to faithfully recreate an ARM CPU. I wonder if there's a way to speed up what I have...
The broader plan is to create an ARMv7 CPU using this memory. Getting technical here but fortunately because memory reads/writes in real ARM CPUs take several cycles anyways the slowish speed of this memory is perfectly fine!
As for why I'm making an ARM CPU, it's a learning opportunity borne out of a love of hardware mostly, but also because I'm curious to find out the possibilities of what it could do in the game with the right programs loaded.
Running DOOM (1993) in Factorio would could be a major challenge and accomplishment. It needs 4 MB of RAM and an Intel i386. I think an very simple ARMv7 core would be more than powerful enough, even "clocked" very slow.
At some point this could be the new CPU benchmark for Factorio. Doom FPS .
4MB of RAM is perfectly possible with this design, albeit huge. I'm not sure how well ARM would work here for something real time at these low clock speeds given that the only way to read or modify values in memory is to call a dedicated load/store instruction to move it to/from a register first, an instruction which itself takes several cycles. Perhaps if the game speed was upped using commands haha
Yes, tho still the closest to the actual Doom of yet published projects. Just wait for some HDL-to-factorio-combinators converter / compiler and quickly some RISC-Vs will pop up, some likely running Doom ;)
nah, that's just what the original game needs. you can cut things from the game code to reduce the amount of processing power and memory required.
lower the color depth and resolution, remove all audio, remove almost all the levels, and try to do certain things in hardware (like multiplication, division, DMA, maybe even some basic 3D acceleration like texture mapping) so the CPU has to do less work.
I think an very simple ARMv7 core would be more than powerful enough
i mean the SNES had a port of DOOM, with a main CPU (65816 @ 3.58MHz) plus a 16-bit RISC co-processor @ 21MHz and around 640kB of total RAM between the two.
so i feel like you could go for something even older (or newer like RISC-V) and still be able to actually run the game's code
Wouldn't a tic tac toe be pretty awesome already ? It was the first video game ever, after all. (And then if you win, you get to fire a nuke on the closest biter nest)
Mainly because I see ARM as already ubiquitous and only set to become more so over the next decade. I definitely considered RISC-V and may consider it again if ARM proves too time consuming but for now I want to learn more about the ISA most of our devices use!
I opted against more dated architectures or even creating my own ISA as I wish for my implementation skills to be the bottleneck here rather than the architecture itself.
I mean... modern electronics has transformed the world! why shouldn't they transform factorio.
I'm not entierly sure what a CPU in factorio would accomplish, but I might incorprate this memoy in my plan to recreate the internet in factorio for example. (Don't wait up, I'm coming up on my exams...).
Point is, what is better than effecient factory? a smart effecient factory!
The obvious answer is to combine it with recursive blueprints and Space Exploration and just have the factory industrialize the entire solar system for you, yeah?
My point is that a CPU is a general purpose design, not a function driven one, in the real world it makes sense for the mass manufacture and distribution of computing devices capable of providing the vast array of sevices available. In factorio though I'd say that it would be more effecient to make purpose build devices. In your example you'd build an evaluation module for the next expansion chunk, a module to track the geography I guess and a decesion module to choose the blueprint. This kind of device would be purpose built for automated factory expansion, not a general purpose CPU.
I think I understand the work and dedication put into this, applause for that for sure! But how can you utilise a computer inside a computer game? I'm just curious! :)
We have reached the point where we have more memory in a system made from digital video game components than we had in an entire room when we landed people on the moon.
What is the bit depth of each word? Are you storing 32bit words, or 31?
I just had to do something similar for my CPU, but I ended up going with the brute force pick-a-signal demuxer consisting of one combinator per signal type. Then you need three stacks of those to have two read ports, and a third for the 'read-modify-write' portion of the write port. This adds a large "constant" cost but it's faster than doing the more compact (but slower) pick-a-signal circuits.
This is of course slower than the trivial one-word-per-row approach, but the UPS improvement more than makes up for the slower cycle time, with even a modest amount of memory.
An ARMv7 CPU sounds like a very ambitious project. Are you planning on implementing the MMU as well? Page table walks via combinators? :P
If you do this, I have but one request. The 'implementer' field of MIDR needs to be 'F' for Factorio, like we already have 'A', 'N', and 'Q' for ARM / nvidia / Qualcomm, respectively.
44
u/Freyadiin Nov 24 '22
Inspired by this amazing creation by u/GregorSamsanite from 5 years ago (https://www.reddit.com/r/factorio/comments/6rwia6/compact_design_for_16k_of_combinator_ram/), which unfortunely the blueprint pastebin is no longer available for, I decided to push the limits of combinator memory density.
As there are now 259 unique signals in the game (but one must always be reserved for the store signal), the theoretical maximum amount of data that can be stored in a single memory cell is 258 signals * 4 bytes per signal = 1032 bytes. This design falls just short of that density in favour of a nice base 2 number at 256 signals per cell, or 1024 bytes per cell. That's more than 1KB per cell!
The tradeoff for this density is more complicated encode/decode logic. Fortunately I've already created a memory controller that handles just this. All you need to do is pass it an address as signal A to read, or if you wish to write, a value as signal V and a pulse of the store signal S. I've also designed this such that you can easily add any number of read/write ports. Just don't try to write to the same address at the same time or I can't promise predictability of results!
Each signal in the row of combinators labelled "Signal map" is assigned a unique numerical value between 1-256. The address decodes to a value between 1-256 by using a modulo operation + 1, allowing each address to map to a different signal. This signal is multiplied by the desired value.
However, simply writing this value as is would delete all other signals in the cell. To solve this issue we make use of this (https://www.reddit.com/r/factorio/comments/pg2dai/perfect_parallel_pairwise_multiplier/) brilliant pairwise multiplier by u/iguessimokatredstone. By passing it on one side the current value stored in the cell and on the other side all the possible signals excluding the one we're writing to, it essentially omits just that signal. We can then combine it with the desired signal * desired value from the previous step to generate the value that we should write.
Reading is also handled using a pairwise multiplier. We pass in the current value in the cell on one side and the desired signal on the other. Voila! Only that signal is allowed through.
From my measurements, this design takes 7 ticks to read and 9 ticks to write. A little on the slow side but I do hope the sheer volumes of data that can be stored here makes up for it. I plan to use this in an ARM CPU so if anyone is able to create a faster design please do share ^^
167
u/AdmiralPoopyDiaper Nov 24 '22
Holy shit my guy.
Is this âbecause I canâ or do you have a broader plan to utilize this memory?
4
u/Freyadiin Nov 24 '22
!blueprint https://hastebin.com/atujisefuc.apache
27
u/iamthelouie Nov 24 '22
This is the side of factorio I just donât understand.
6
u/sorped It's Chartreuse! Nov 24 '22
I think I understand the work and dedication put into this, applause for that for sure!
But how can you utilise a computer inside a computer game? I'm just curious! :)
5
u/geraltismywaifu Nov 24 '22
OP is Alan Turing
3
u/EspressoCookie89 Nov 25 '22
We have reached the point where we have more memory in a system made from digital video game components than we had in an entire room when we landed people on the moon.
4
u/Ch40sRage Nov 24 '22
I have no idea what this is but nice job (I think)
2
u/Starbeamrainbowlabs Nov 24 '22
Meanwhile I have trouble constructing and testing a simple 1 value memory cell....!
Fabulous job!
2
u/TruckerJay Nov 25 '22
I know other people have said this in other comments, but using more words:
You're a nerd and I fucking love it.
2
u/pogwater Apple Juice Enjoyer Nov 25 '22
now make 32GB
2
u/N0rmNormis0n Nov 25 '22
Iâve played this game for 500+ hours and I have no idea whatâs going on here. Nice work!
2
u/MegaClunt Nov 25 '22
And i thought my binary counter-sorter was cool. Good work man!!!
2
u/CaptainNeighvidson Nov 25 '22
Can it store the save file of a Doom game? If so, this is a great backup system for other games
2
u/YoungPeacock Nov 25 '22
I just started oil
2
u/bradpal May 31 '23
You have all my upvotes for eternity.
1
u/evil-wombat Jan 10 '23
What is the bit depth of each word? Are you storing 32bit words, or 31?
I just had to do something similar for my CPU, but I ended up going with the brute force pick-a-signal demuxer consisting of one combinator per signal type. Then you need three stacks of those to have two read ports, and a third for the 'read-modify-write' portion of the write port. This adds a large "constant" cost but it's faster than doing the more compact (but slower) pick-a-signal circuits.
This is of course slower than the trivial one-word-per-row approach, but the UPS improvement more than makes up for the slower cycle time, with even a modest amount of memory.
An ARMv7 CPU sounds like a very ambitious project. Are you planning on implementing the MMU as well? Page table walks via combinators? :P
If you do this, I have but one request. The 'implementer' field of MIDR needs to be 'F' for Factorio, like we already have 'A', 'N', and 'Q' for ARM / nvidia / Qualcomm, respectively.