Update
parent
99e8181bdc
commit
671c98ff3a
@ -0,0 +1,130 @@
|
||||
# Bytecode
|
||||
|
||||
TODO
|
||||
|
||||
## Example
|
||||
|
||||
Let's consider a simple algorithm that tests the [Collatz conjecture](collatz_conjecture.md) (which says that applying a simple operation from any starting number over and over will always lead to number 1). The algorithm in [C](c.md) would look as follows:
|
||||
|
||||
```
|
||||
// Collatz conjecture
|
||||
#include <stdio.h>
|
||||
|
||||
int next(int n)
|
||||
{
|
||||
return n % 2 ? // is odd?
|
||||
3 * n + 1 :
|
||||
n / 2;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int n = getchar() - '0'; // read input ASCII digit
|
||||
|
||||
while (1)
|
||||
{
|
||||
printf("%d\n",n);
|
||||
|
||||
if (n == 1)
|
||||
break;
|
||||
|
||||
n = next(n);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
|
||||
The program reads a number (one digit for simplicity) and then prints the sequence until reaching the final number 1. Now let's rewrite the same algorithm in [comun](comun.md), a language which will allow us to produce bytecode:
|
||||
|
||||
```
|
||||
# Collatz conjecture
|
||||
|
||||
next:
|
||||
$0 2 % ? # is odd?
|
||||
3 * 1 +
|
||||
;
|
||||
2 /
|
||||
.
|
||||
.
|
||||
|
||||
<- # read input ASCII digit
|
||||
"0" - # convert it to number
|
||||
|
||||
@@
|
||||
# print:
|
||||
$0 10 / "0" + ->
|
||||
$0 10 % "0" + ->
|
||||
10 ->
|
||||
|
||||
$0 1 = ?
|
||||
!@
|
||||
.
|
||||
|
||||
next
|
||||
.
|
||||
```
|
||||
|
||||
The bytecode this compiles to is following:
|
||||
|
||||
```
|
||||
000000: DES 00 0111 # func
|
||||
000001: JMA 00 0100... # 20 (#14)
|
||||
000002: COC 00 0001
|
||||
000003: MGE 00 0000
|
||||
000004: CON' 00 0010 # 2 (#2)
|
||||
000005: MOX 00 0000
|
||||
000006: DES 00 0001 # if
|
||||
000007: JNA 00 0000... # 16 (#10)
|
||||
000008: COC 00 0001
|
||||
000009: CON' 00 0011 # 3 (#3)
|
||||
00000a: MUX 00 0000
|
||||
00000b: CON' 00 0001 # 1 (#1)
|
||||
00000c: ADX 00 0000
|
||||
00000d: DES 00 0010 # else
|
||||
00000e: JMA 00 0011... # 19 (#13)
|
||||
00000f: COC 00 0001
|
||||
000010: CON' 00 0010 # 2 (#2)
|
||||
000011: DIX 00 0000
|
||||
000012: DES 00 0011 # end if
|
||||
000013: RET 00 0000
|
||||
000014: INI 00 0000
|
||||
000015: INP 00 0000
|
||||
000016: CON' 00 0000... # 48 (#30)
|
||||
000017: COC 00 0011
|
||||
000018: SUX 00 0000
|
||||
000019: DES 00 0100 # loop
|
||||
00001a: MGE 00 0000
|
||||
00001b: CON' 00 1010 # 10 (#a)
|
||||
00001c: DIX 00 0000
|
||||
00001d: CON' 00 0000... # 48 (#30)
|
||||
00001e: COC 00 0011
|
||||
00001f: ADX 00 0000
|
||||
000020: OUT 00 0000
|
||||
000021: MGE 00 0000
|
||||
000022: CON' 00 1010 # 10 (#a)
|
||||
000023: MOX 00 0000
|
||||
000024: CON' 00 0000... # 48 (#30)
|
||||
000025: COC 00 0011
|
||||
000026: ADX 00 0000
|
||||
000027: OUT 00 0000
|
||||
000028: CON' 00 1010 # 10 (#a)
|
||||
000029: OUT 00 0000
|
||||
00002a: MGE 00 0000
|
||||
00002b: CON' 00 0001 # 1 (#1)
|
||||
00002c: EQX 00 0000
|
||||
00002d: DES 00 0001 # if
|
||||
00002e: JNA 00 0100... # 52 (#34)
|
||||
00002f: COC 00 0011
|
||||
000030: DES 00 0101 # break
|
||||
000031: JMA 00 1000... # 56 (#38)
|
||||
000032: COC 00 0011
|
||||
000033: DES 00 0011 # end if
|
||||
000034: CAL 00 0011 # 3 (#3)
|
||||
000035: DES 00 0110 # end loop
|
||||
000036: JMA 00 1010... # 26 (#1a)
|
||||
000037: COC 00 0001
|
||||
000038: END 00 0000
|
||||
```
|
||||
|
||||
TODO: analyze the above, show other bytecodes (python, java, ...)
|
@ -1,7 +1,12 @@
|
||||
# Deep Blue
|
||||
|
||||
TODO
|
||||
Deep Blue was a legendary [chess](chess.md) playing [IBM](ibm.md) [supercomputer](supercomputer.md), which in 1997 made [history](history.md) by being the first ever [computer](computer.md) to beat the human world chess champion at the time (Garry Kasparov), marking a moment which many consider that at which "computers finally outsmarted humans". Since then computers really did continue to surpass humans at chess by much greater margins; nowadays a mere cellphone running [stockfish](stockfish.md) can easily rape the world chess champion.
|
||||
|
||||
Fun fact: Deep Blue was firstly named Deep Thought, after the computer in [Hitchhiker's Guide to the Galaxy](hgttg.md), however it had to be renamed because the name too much resembled [deep throat](deep_throat.md).
|
||||
History: it all started around 1985 as a program called ChipTest by some Taiwanese guy with unpronounceable name. It went on to win some computer chess tournaments and when multiple people were already working on it as a part of IBM research, it was renamed to Deep Thought after the computer in [Hitchhiker's Guide to the Galaxy](hgttg.md), however **it had to be later renamed to Deep Blue because the name too much resembled [deep throat](deep_throat.md)** :D By 1990 it has already played the world champion, Kasparov, but lost. In 1996 Deep Blue played him again, this time losing the match again but already having won a game, showing the potential was there. In May 1997, after upgrade both in hardware and software, it finally beat Kasparov with 3 wins, 2 losses and 1 draw.
|
||||
|
||||
{ Lol, according to Wikipedoa it trolled Kasparov in the first game by making a completely random move due to a bug once, it scared him because he thought it was some deeply calculated threat while it was just some completely dumb move. ~drummyfish }
|
||||
|
||||
It's important to see that Deep Blue wasn't really a general chess engine like [stockfish](stockfish.md), it was a single purpose supercomputer, a combination of [hardware](hw.md) and [software](sw.md) engineered from the ground up with the single purpose: win the match against Garry Kasparov. It was being fine tuned in between the games with assistance of grandmasters. A team of experts on computers and chess focused their efforts on this single opponent at the specific time controls and match set up, rather than trying to make a generally usable chess computer. They studied Kasparov's play and made Deep Blue ready for it; they even employed psychological tricks -- for example it had preprogrammed instant responses to some Kasparov's expected moves, so as to make him more nervous.
|
||||
|
||||
Technical details: Deep Blue was mainly relying on massively parallel [brute force](brute_force.md), i.e. looking many moves ahead and consulting stored databases of games; in 1997 it had some 11 [GFLOPS](flops.md). The base computer was IBM RS/6000 SP, using 32 [PowerPC](ppc.md) processors and 480 specialized "chess chips". It had evaluation function implemented in hardware. All in all the whole system could search hundreds of millions positions per second. Non-extended search was performed to a depth of about 12 plies, extended search went even over 40 plies deep. It had an opening book with about 4000 positions and endgame tablebases for up to 6 pieces. It was programmed in [C](c.md). { Sources seems to sometimes give different numbers and specs, so not exactly sure about this. ~drummyfish }
|
||||
|
||||
It wasn't really a general chess engine like [stockfish](stockfish.md), it was really programmed specifically for winning the match against Kasparov, it focused on his play and employed even psychological tricks -- for example it had preprogrammed instant responses to some Kasparov's expected moves, so as to make him more nervous.
|
Loading…
Reference in New Issue