Skip to content
View VachanVY's full-sized avatar
🖖
if (in_matrix) break;
🖖
if (in_matrix) break;

Block or report VachanVY

Block user

Prevent this user from interacting with your repositories and sending you notifications. Learn more about blocking users.

You must be logged in to block users.

Maximum 250 characters. Please don't include any personal information such as legal names or email addresses. Markdown supported. This note will be visible to only you.
Report abuse

Contact GitHub support about this user’s behavior. Learn more about reporting abuse.

Report abuse
VachanVY/README.md

Hi, I'm Vachan!

Description

image
  • A minimal implementation of a tiny subset of the C language in C and C++23

nanocc progress

// examples/linkage_fact.c
int num_times = 10;
int factorial(int n) {
    int ret;
    if (n <= 1) {
        ret = 1;
    } else {
        ret = n * factorial(n - 1);
    }
    return ret;
}
assembly output
      .globl factorial
    .text
factorial:
    pushq %rbp
    movq %rsp, %rbp
    subq $32, %rsp
    movl %edi, -4(%rbp)
    cmpl $1, -4(%rbp)
    movl $0, -8(%rbp)
    setle -8(%rbp)
    cmpl $0, -8(%rbp)
    je else.0
    movl $1, -12(%rbp)
    jmp end.1
  else.0:
    movl -4(%rbp), %r10d
    movl %r10d, -16(%rbp)
    subl $1, -16(%rbp)
    movl -16(%rbp), %edi
    call factorial
    movl %eax, -20(%rbp)
    movl -4(%rbp), %r10d
    movl %r10d, -24(%rbp)
    movl -24(%rbp), %r11d
    imull -20(%rbp), %r11d
    movl %r11d, -24(%rbp)
    movl -24(%rbp), %r10d
    movl %r10d, -12(%rbp)
  end.1:
    movl -12(%rbp), %eax
    movq %rbp, %rsp
    popq %rbp
    ret

    movl $0, %eax
    movq %rbp, %rsp
    popq %rbp
    ret

    .globl num_times
    .data
    .align 4
num_times:
    .long 10

    .section .note.GNU-stack, "",@progbits
// examples/linkage_utils.c
int putchar(int c);

int putint(int x) {
    if (x < 0) {
        putchar(45);  // ASCII '-'
        x = -x;
    }

    if (x >= 10)
        putint(x / 10);

    putchar(48 + (x % 10));  // ASCII '0' = 48
}

int hello_world(void) {
    // "Hello, World!" using only integers
    putchar(72);    putchar(101);    putchar(108);    
    putchar(108);    putchar(111);    putchar(44);
    putchar(32);    putchar(87);    putchar(111);    
    putchar(114);    putchar(108);    putchar(100);
    putchar(33);    putchar(10);
}

int init_sys(void) {
    static int initialized = 0;

    if (initialized == 1)
        return 0;

    hello_world();

    putchar(73);   // 'I'
    putchar(78);   // 'N'
    putchar(73);   // 'I'
    putchar(84);   // 'T'
    putchar(10);   // '\n'

    initialized = 1;
    return 1;
}
assembly output
    .globl putint
    .text
putint:
    pushq %rbp
    movq %rsp, %rbp
    subq $48, %rsp
    movl %edi, -4(%rbp)
    cmpl $0, -4(%rbp)
    movl $0, -8(%rbp)
    setl -8(%rbp)
    cmpl $0, -8(%rbp)
    je end.0
    movl $45, %edi
    call putchar@PLT
    movl %eax, -12(%rbp)
    movl -4(%rbp), %r10d
    movl %r10d, -16(%rbp)
    negl -16(%rbp)
    movl -16(%rbp), %r10d
    movl %r10d, -4(%rbp)
  end.0:
    cmpl $10, -4(%rbp)
    movl $0, -20(%rbp)
    setge -20(%rbp)
    cmpl $0, -20(%rbp)
    je end.1
    movl -4(%rbp), %eax
    cdq
    movl $10, %r10d
    idivl %r10d
    movl %eax, -24(%rbp)
    movl -24(%rbp), %edi
    call putint
    movl %eax, -28(%rbp)
  end.1:
    movl -4(%rbp), %eax
    cdq
    movl $10, %r10d
    idivl %r10d
    movl %edx, -32(%rbp)
    movl $48, -36(%rbp)
    movl -32(%rbp), %r10d
    addl %r10d, -36(%rbp)
    movl -36(%rbp), %edi
    call putchar@PLT
    movl %eax, -40(%rbp)
    movl $0, %eax
    movq %rbp, %rsp
    popq %rbp
    ret

    .globl hello_world
    .text
hello_world:
    pushq %rbp
    movq %rsp, %rbp
    subq $64, %rsp
    movl $72, %edi
    call putchar@PLT
    movl %eax, -4(%rbp)
    movl $101, %edi
    call putchar@PLT
    movl %eax, -8(%rbp)
    movl $108, %edi
    call putchar@PLT
    movl %eax, -12(%rbp)
    movl $108, %edi
    call putchar@PLT
    movl %eax, -16(%rbp)
    movl $111, %edi
    call putchar@PLT
    movl %eax, -20(%rbp)
    movl $44, %edi
    call putchar@PLT
    movl %eax, -24(%rbp)
    movl $32, %edi
    call putchar@PLT
    movl %eax, -28(%rbp)
    movl $87, %edi
    call putchar@PLT
    movl %eax, -32(%rbp)
    movl $111, %edi
    call putchar@PLT
    movl %eax, -36(%rbp)
    movl $114, %edi
    call putchar@PLT
    movl %eax, -40(%rbp)
    movl $108, %edi
    call putchar@PLT
    movl %eax, -44(%rbp)
    movl $100, %edi
    call putchar@PLT
    movl %eax, -48(%rbp)
    movl $33, %edi
    call putchar@PLT
    movl %eax, -52(%rbp)
    movl $10, %edi
    call putchar@PLT
    movl %eax, -56(%rbp)
    movl $0, %eax
    movq %rbp, %rsp
    popq %rbp
    ret

    .globl init_sys
    .text
init_sys:
    pushq %rbp
    movq %rsp, %rbp
    subq $32, %rsp
    cmpl $1, initialized.2(%rip)
    movl $0, -4(%rbp)
    sete -4(%rbp)
    cmpl $0, -4(%rbp)
    je end.2
    movl $0, %eax
    movq %rbp, %rsp
    popq %rbp
    ret

  end.2:
    call hello_world
    movl %eax, -8(%rbp)
    movl $73, %edi
    call putchar@PLT
    movl %eax, -12(%rbp)
    movl $78, %edi
    call putchar@PLT
    movl %eax, -16(%rbp)
    movl $73, %edi
    call putchar@PLT
    movl %eax, -20(%rbp)
    movl $84, %edi
    call putchar@PLT
    movl %eax, -24(%rbp)
    movl $10, %edi
    call putchar@PLT
    movl %eax, -28(%rbp)
    movl $1, initialized.2(%rip)
    movl $1, %eax
    movq %rbp, %rsp
    popq %rbp
    ret

    movl $0, %eax
    movq %rbp, %rsp
    popq %rbp
    ret

    .bss
    .align 4
initialized.2:
    .zero 4

    .section .note.GNU-stack, "",@progbits
// defined in linkage_utils.c
int init_sys(void);

int putchar(int c);
int putint(int x);

// defined in linkage_fact.c
extern int num_times;
int factorial(int n);

int main(void){
    init_sys();
    init_sys(); // WON'T PRINT "INIT" AGAIN
    init_sys(); // WON'T PRINT "INIT" AGAIN

    for (int i = 1; i <= num_times; i = i + 1) {
        int fact = factorial(i);
        putint(i); /*space*/ putchar(32); 
        putint(fact); /*newline*/ putchar(10);
    }
    return 0;
}
assembly output
    .globl main
    .text
main:
    pushq %rbp
    movq %rsp, %rbp
    subq $48, %rsp
    call init_sys@PLT
    movl %eax, -4(%rbp)
    call init_sys@PLT
    movl %eax, -8(%rbp)
    call init_sys@PLT
    movl %eax, -12(%rbp)
    movl $1, -16(%rbp)
  start_for.0:
    movl num_times(%rip), %r10d
    cmpl %r10d, -16(%rbp)
    movl $0, -20(%rbp)
    setle -20(%rbp)
    cmpl $0, -20(%rbp)
    je break_for.0
    movl -16(%rbp), %edi
    call factorial@PLT
    movl %eax, -24(%rbp)
    movl -24(%rbp), %r10d
    movl %r10d, -28(%rbp)
    movl -16(%rbp), %edi
    call putint@PLT
    movl %eax, -32(%rbp)
    movl $32, %edi
    call putchar@PLT
    movl %eax, -36(%rbp)
    movl -28(%rbp), %edi
    call putint@PLT
    movl %eax, -40(%rbp)
    movl $10, %edi
    call putchar@PLT
    movl %eax, -44(%rbp)
  continue_for.0:
    movl -16(%rbp), %r10d
    movl %r10d, -48(%rbp)
    addl $1, -48(%rbp)
    movl -48(%rbp), %r10d
    movl %r10d, -16(%rbp)
    jmp start_for.0
  break_for.0:
    movl $0, %eax
    movq %rbp, %rsp
    popq %rbp
    ret

    movl $0, %eax
    movq %rbp, %rsp
    popq %rbp
    ret


    .section .note.GNU-stack, "",@progbits

Reinforcement Learning

Algorithms from Reinforcement Learning: An Introduction by Andrew Barto and Richard S. Sutton

Algorithms Environment (Name & Goal) Environment GIF Plots
Policy Iteration Frozen Lake: The player makes moves until they reach the goal or fall in a hole. The lake is slippery (unless disabled) so the player may move perpendicular to the intended direction sometimes. pol pol -
Value Iteration Taxi-v3: The taxi starts at a random location within the grid. The passenger starts at one of the designated pick-up locations. The passenger also has a randomly assigned destination (one of the four designated locations). Gridworld Gridworld Gridworld -
Monte Carlo Exploring Starts Blackjack-v1: a card game where the goal is to beat the dealer by obtaining cards that sum to closer to 21 (without going over 21) than the dealer's cards Blackjack Graph Graph
Sarsa CliffWalking-v0: Reach goal without falling CliffWalking Graph Sarsa: Orange
Q-learning CliffWalking-v0: Reach goal without falling CliffWalking Graph Q-learning: Blue
Expected Sarsa CliffWalking-v0: Reach goal without falling CliffWalking Graph Expected Sarsa: Green
Double Q-learning CliffWalking-v0: Reach goal without falling CliffWalking Graph Double Q-learning: Red
Dyna-Q ShortcutMazeEnv (custom made env): Reach the goal dodging obstacles maze0 maze compare by steps
Prioritized Sweeping ShortcutMazeEnv (custom made env): Reach the goal dodging obstacles maze0 steps sum rewards
Monte-Carlo Policy-Gradient CartPole-v1: goal is to balance the pole by applying forces in the left and right direction on the cart. CartPole Graph
One-Step Actor-Critic CartPole-v1: goal is to balance the pole by applying forces in the left and right direction on the cart. CartPole Graph

Deep Reinforcement Learning: Paper Implementations

Year Paper Environment (Name & Goal) Environment GIF Plots
2013 Playing Atari with Deep Reinforcement Learning ALE/Pong-v5 - You control the right paddle, you compete against the left paddle controlled by the computer. You each try to keep deflecting the ball away from your goal and into your opponent’s goal.
2014 Deep Deterministic Policy Gradient (DDPG) Pendulum-v1 - The pendulum starts in a random position and the goal is to apply torque on the free end to swing it into an upright position, with its center of gravity right above the fixed point. Pendulum Plot
2017 Proximal Policy Optimization (PPO) -- Discrete Action Space LunarLander-v3: This environment is a classic rocket trajectory optimization problem. According to Pontryagin’s maximum principle, it is optimal to fire the engine at full throttle or turn it off opaos Plot
2017 Proximal Policy Optimization (PPO) -- Continuous Action Space HalfCheetah-v5: The goal is to apply torque to the joints to make the cheetah run forward (right) as fast as possible, with a positive reward based on the distance moved forward and a negative reward for moving backward. opaos Plot Plot
2018 Soft Actor-Critic (SAC) InvertedDoublePendulum-v5: The cart can be pushed left or right, and the goal is to balance the second pole on top of the first pole, which is in turn on top of the cart, by applying continuous forces to the cart. Plot Plot

Pinned Loading

  1. nanocc nanocc Public

    The Nano C Compiler (nanocc)

    C++

  2. gpt.jax gpt.jax Public archive

    Generative Pretrained Model (GPT) in JAX. A step by step guide to train LLMs on large datasets from scratch

    Python 4 1

  3. Reinforcement-Learning Reinforcement-Learning Public archive

    PyTorch implementations of algorithms from "Reinforcement Learning: An Introduction by Sutton and Barto", along with various RL research papers.

    Python 205 14

  4. gpu-programming gpu-programming Public

    Some Triton & Cuda kernels

    Python

  5. NeuroForge NeuroForge Public

    Unveiling the Layers: Neural Networks from first principles

    Jupyter Notebook 10

  6. llvm-project llvm-project Public

    Forked from llvm/llvm-project

    The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.

    LLVM