Ankur 🕉️
Ankur 🕉️

@GaikwadAnkur

10 تغريدة 1 قراءة Jun 11, 2023
1)
#Thread on a top-down journey of how programming languages work with the bare metal i.e. the transistor circuits on your computer.
We'll begin by taking Python code’s interaction with the circuits as an example.
#Engineering #SoftwareEngineering #Electronics
2)
Python is a dynamically typed language - you don’t need to specify types of variables when you declare them in Python code.
This is because the Python interpreter (C compiler under the hood) has type-checking algorithms at runtime to infer the data types.
3)
Why is type inference/specification important? - There are dedicated electronic circuits which work with the specific data types, be it 'float', (floating-pt/decimal nos.) 'char' (characters), or 'int' (integers), etc.
E.g. There are adder, subtractor, comparator circuits.
4)
These circuits are organized into chunks, where a single chunk can perform a single operation (a “micro-operation” in chip architecture terms) at any given time.
Not all circuits are available in all chunks – some chunks are dedicated to handling data storage, others..
5)
.. specialise in handling the logical statements (comparisons), while the rest handle the mathematical operations according to the data type. E.g. An integer-add circuit is different from integer-vector (collection of integers if I understand it correctly) addition circuit.
6)
To decide which circuit to use, a scheduler allocates these chunks to processing the appropriate data types and operations.
The scheduler receives instructions from the prior decoder circuits (pic 2). They decode the instructions i.e. the programmer’s code in binary form.
7)
The binary form contains the information on the data types which the C compiler inferred from the Python code. When a variable is accessed in Python code repeatedly, the compiler has to check the type of the same variable repeatedly, resulting in large performance overheads.
8)
This is the reason why it’s generally advised to avoid operations in large loops in Python - instead delegating the looped/repetitive tasks to the statically-typed languages like C through C-APIs like ctypes, cython, etc.
9)
In statically-typed languages, the programmer specifies the type of variable.
Hence it becomes straightforward for the scheduler circuit in the chip to make optimal decision to allocate the processing chunks to the appropriate parts of code/micro-operation.
10)
I'll continue the engineering exploration of the electronics in further threads. I welcome your comments on these types of threads. 😊🧑‍💻🧑‍💻#Engineering #Electronics

جاري تحميل الاقتراحات...