I am wondering if it is possible to have a program that interprets programming code and is capable of turning that code into an optimized circuit. Is this possible, and if so, does it exist?

  • $\begingroup$ At present I think the question is too broad and thus not likely to yield an answer that is useful to you. Can you narrow down your question? Why do you ask? What problem do you face that has prompted this question? Is there a specific program you want to compile in this way? A specific programming language? Why do you want a circuit, and what do you plan to do with the circuit? $\endgroup$ – D.W. Jul 31 '14 at 23:48
  • 1
    $\begingroup$ I was looking for a way to make specialized hardware for simple programs that do heavy calculations. A good example would be a raytracer or hash algorithm. $\endgroup$ – Tyler Scott Aug 1 '14 at 4:46
  • 1
    $\begingroup$ The Wikipedia article "C to HDL" might be of interest. $\endgroup$ – Paul A. Clayton Aug 1 '14 at 13:11
  • $\begingroup$ Ahhh. Yes, Paul Clayton's suggestion is a good one. You can also find work on compiling systems code (e.g., C code) into a form that can be executed on a FGPA, which is in a very similar vein. However, you might find that you get better performance by implementing the algorithm by hand in AHDL/VHDL, than by compiling from C code -- you'd have to experiment to be sure, but that's my guess. $\endgroup$ – D.W. Aug 1 '14 at 17:20

Yes, it is certainly possible.

There are compilers that will compile from code to circuits. Classic examples would be VHDL or AHDL compilers, but you can certainly do this for any other language, to the extent that you have an upper bound on the running time of the program or that you have an upper bound on the memory use of the program and are willing to have a circuit that contains stateful elements.

In fact, you can walk down to Fry's and buy something that basically has the form you asked for: it's called a computer. That's more or less what a computer does: it takes code written in a programming language and executes it efficiently, using an optimized circuit. The circuit is fixed (it is the gates in the processor) and part of its input is data that depends upon the program you are executing (which is stored in the RAM of the computer). However, you could consider this a larger circuit where part of it is hardcoded (i.e., the program part of the input is hardcoded); then you can view a computer running a program as a big circuit with part that is universal and identical for all programs (the gates of the processor) and part that depends on the program (the hardcoded input), and this immediately gives a mapping from programs to circuits. The mapping is implemented by a compiler.

  • $\begingroup$ Part of the circuit is data? Sorry but this answer does not make any sense to me. A circuit's inputs are certainly not a part of it. $\endgroup$ – Shashank V M Feb 27 at 14:45
  • 1
    $\begingroup$ @ShashankVM, you're right, that wording was poor. I tried an edit; see if you think it is any better or not. Maybe you can help me express this more clearly. $\endgroup$ – D.W. Feb 28 at 7:59

there are different ways to interpret your question but based on comments (incl yours) some of this may be helpful. there is a lot of research in converting higher level programming constructs into FPGAs, field programmable gate arrays, basically hardware where circuits are dynamically reconfigurable. (aka reconfigurable computing).

there is also a special language eg "C for FPGAs", a subset of full C, that is customized for this purpose.

as for getting efficient circuits for particular programs, that is another area of research/ optimization eg circuit optimization/ minimization/ compression. there are also optimization heuristics built as input preprocessors into most SAT solvers. more generally this is known as logic optimization and there are various techniques/ tools for that. also the general theory/ application of optimizing compilers has some overlap with circuit optimization. one simple, near "toy" example or model of a compiler optimization in some cases is short circuit evaluation. the general area you refer to is also an active area of research both theoretical/ applied & there are many related papers on the subject.


No, it is not possible. You certainly can't convert arbitrary programming code to circuits.

How will you convert a print("Hello World!") command in Python 3, or a program to print Hello World in C to hardware?

There is a software tool called a synthesizer, which recognizes patterns in Hardware Description Language (HDL) code (a textual, formal description of circuits that is both human and machine readable) and then generates a circuit. The patterns that the software tool recognizes are limited. The circuits generated are also limited. Usually, the circuit is also routed by hand if the software routing is not good enough for the application.

In the semiconductor industry, hardware description languages (HDL) like SystemVerilog and VHDL are used to model both combinational logic and sequential logic. Code written in these languages must contain an explicit clock signal for a synchronous sequential circuit. Programming code which executes sequentially on a computer usually uses an implicit clock signal.

High Level Synthesis tools generate hardware description language code from code written in programming languages, however this code is a Domain Specific Language and will be a subset of the programming language used. Some programming constructs have no corresponding hardware elements, so these constructs cannot be used.

The mindset of programming and hardware design cannot be more different:

  • Hardware exists all the time so you can't "delete" something if you don't need it, so you need to design carefully and optimize for speed and power consumption.

  • Software design, on the other hand, requires managing of limited hardware resources like memory and CPU, so we (or the machine) can deallocate memory when it is not required.

  • A design mistake in hardware is very difficult (if not impossible) to fix, so verification of the design is a very important part of the hardware design process. Verification takes more time than designing hardware, due to the astronomical number of testcases.

  • In software, a mistake can be easily corrected by updating the software.

HDL code is used only for synthesizing digital circuits. Analog circuits are usually designed using schematic capture. Software tools are used for simulating circuits.

Another option you might want to consider is to design an Application-specific instruction-set processor (ASIP), this combines the performance of the ASIC with the programmability of a processor. For this, special ASIP (Hardware / Software Co-Design) design tools are used.

We can also print to the console in SystemVerilog using $display or $monitor or other compiler directives, but that cannot be synthesized to a circuit.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.