Posts

Project Stage 3 : Part 2

 This part is to cover up for the things that i may have missed in the previous stages. So i extracted both the tar zip files (spo600-gcc-pass-demo and spo600-gcc-pass-demo-2) which extracted 4 files each: The tar file had everything I needed to modify GCC. My professor provided details about which files to change, and I updated four of them: passes.def: Added NEXT_PASS (pass_ctyler); tree-ctyler.cc: Contained the actual pass code. tree-pass.h: Added extern gimple_opt_pass *make_pass_ctyler (gcc::context *ctxt); Makefile.in: Added tree-ctyler.o to the OBJS definition. Both zip files have same files and same code except the execute function in tree-ctyler.cc as shown below; spo600-gcc-pass-demo: unsigned int pass_ctyler :: execute ( function * fun )   {     basic_block bb ;     int bb_cnt = 0 , stmt_cnt = 0 ;     FOR_EACH_BB_FN ( bb , fun )       {         bb_cnt ++ ;         if ( du...

Wrapping Up Project : Stage 3

With the final stage of the SPO600 project, my journey into the GCC compiler comes to a close. This stage was all about tying up loose ends from Stage 2, testing the Clone-Pruning Analysis Pass, and reflecting on what I’ve learned throughout the project. Progress Overview The focus of Stage 3 was to finalize the work I started in Stage 2. Building on my earlier implementation, I managed to create a pass that iterates through functions, analyzes their GIMPLE representations, and outputs information to a dump file. Here's what my custom GCC pass can now do: Print Function Names : The pass successfully identifies and prints the names of all functions. Output GIMPLE Statements : It iterates through the GIMPLE representation of each function, printing the statements to the dump file. Count Statements : The pass tracks and stores the number of GIMPLE statements for each function. A snippet of my pass code from tree-ctyler.cc demonstrates the approach: unsigned int pass_ctyler::execute(fu...

Lab 3

This lab was about creating a program for the 6502 Emulator that outputs to both character and graphics screens, accepts user input, and performs arithmetic operations. I decided to write a simple Number Guessing Game.  Objective The program generates a random number between 1 and 100, and the player guesses the number. It provides feedback like "Too High" or "Too Low" and indicates correct guesses visuals. Features Character Screen: Displays instructions and feedback messages. Graphics Screen: Changes colors based on the result: Green: Correct guess. Red: Too low. Yellow: Too high. Operations: Compares the user’s guess with the random number. Code Here is the code below; ; Number Guessing Game for 6502 Emulator ; Constants RANDOM_NUMBER = $42 ; Replace this with a random number generator CHAR_SCREEN = $0400 GRAPHICS_SCREEN = $2000 GREEN = $1 RED = $2 YELLOW = $3 ; Initialize program     LDX #$00        ; Clear X register     STX CHAR_SCREEN ...

Lab 2

  6502 Math Lab Introduction This lab involved creating a diagonal-moving graphic in the 6502 emulator, ensuring the object bounces when it reaches the edges of the screen. The provided code initializes a graphic on a bitmapped display and uses subroutines to animate it. The program also detects when the object reaches the screen's boundaries and reverses its direction accordingly. Here's a breakdown: ; ; draw-image-subroutine.6502 ; ; This is a routine that can place an arbitrary ; rectangular image on to the screen at given ; coordinates. ; ; Chris Tyler 2024-09-17 ; Licensed under GPLv2+ ; ; ; The subroutine is below starting at the ; label "DRAW:" ; ; Test code for our subroutine ; Moves an image diagonally across the screen ; Zero-page variables define XPOS $20 define YPOS $21 ; Set up the data structure ; The syntax #<LABEL returns the low byte of LABEL ; The syntax #>LABEL returns the high byte of LABEL LDA #<G_X ; POINTER TO GRAPHIC STA $10...

Lab 1

Image
  6502 Assembly Language Lab In this lab, I explored the 6502 Emulator to manipulate the bitmapped display using assembly language. The goal was to fill the screen with colors, experiment with random pixel values, and optimize execution time. Task 1: Filling the Screen with Yellow The initial code filled the screen with a solid yellow color. Here's the snippet: lda #$00 ; Set a pointer in memory location $40 to point to $0200 sta $40 ; Low byte ($00) in address $40 lda #$02 sta $41 ; High byte ($02) in address $41 lda #$07 ; Yellow color code ldy #$00 ; Set index to 0 loop: sta ($40),y ; Set pixel color at address (pointer)+Y iny ; Increment index bne loop ; Continue until the page is filled inc $41 ; Increment page ldx $41 ; Get current page number cpx #$06 ; Compare with 6 bne loop ; Continue until all pages are filled Execution Time Calculation Each pixel requires 11 cycles (6 cycles for sta , 2 cyc...

Building GCC Part 2

This is my attempt to learn and work with GCC as part of my SPO600 course. I’m working on Stage 2 of the project, where I have to create and test a Clone-Pruning Analysis Pass. You can find the first part in my blog page. Creating the Dummy Pass I started by creating a basic pass that should iterates through the program functions and output their names to a dump file.  Iterating Through GIMPLE Statements Next, I added logic to traverse the GIMPLE representation of each function. GIMPLE is an intermediate language used by GCC, and understanding it was crucial for the project. By iterating over the GIMPLE statements within each basic block, I could analyze the structure of functions. This step highlighted the importance of diagnostic dumps, as they provided a detailed view of what the pass was processing. While the GIMPLE code initially felt overwhelming, breaking it down into smaller sections made it easier. Setting Up The first step was to get the provided files into my working dir...
Image
  Automatic Function Multi-Versioning for GCC Introduction: For this project, I will be working with the GCC compiler and learning how it works by building it from scratch on an AArch64 platform (which is 64-Bit). Setting up GCC like this lets me dig into how it compiles code and optimizes functions for different CPUs, especially as the goal is to experiment with Automatic Function Multi-Versioning (AFMV). Guide to Building GCC for AArch64 Step 1: Cloning the Source Code To get started, I needed the GCC source code. Cloning from the official GCC repository keeps things organized and up to date. Here’s the command to clone it: git clone git://gcc.gnu.org/git/gcc.git ~/gcc This creates a directory called ~/gcc , where all the source files are stored. The cloning process might take a few minutes, depending on your internet speed. Step 2: Setting Up a Build Directory It’s recommended to create a separate directory for building GCC instead of doing it directly in the source directory. ...