Code Monkey home page Code Monkey logo

hls's Introduction

/---------------------------------------------------------------------------------------------------------------------------------------------------/

//part 1
int adder(int a,int b){

	return a+b;
}

// now go to solutions/syn/verilog to see corresponding verilog


/*---------------------------------------------------------------------------------------------------------------------------------------------------*/

/---------------------------------------------------------------------------------------------------------------------------------------------------/

//part 2

// design
#include <ap_int.h>

ap_uint<3> ALU(ap_uint<3> a ,ap_uint<3> b ,ap_uint<2> c ) {

	if(c==0) {
		return a+b;
	}
	elseif(c==1) {
		return a-b;
	}
	elseif(c==2) {
		return a&b;
	}
	elseif(c==3) {
		return a^b;
	}
}

// testbench

#include <stdio.h>
#include <ap_int.h>

//instantiation
ap_uint<3> ALU(ap_uint<3> a, ap_uint<3> b, ap_uint<2> c);

int main() {
    ap_uint<3> a = 5; // 5 in 3-bit unsigned integer is 101
    ap_uint<3> b = 3; // 3 in 3-bit unsigned integer is 011
    ap_uint<2> c;
    ap_uint<3> result;

    // Test addition (c = 0)
    c = 0;
    result = ALU(a, b, c);

    printf("Addition: %d + %d = %d\n", (int)a, (int)b, (int)result);

    if (result != (a + b)) {
        printf("Error in addition\n");
    }

    // Test subtraction (c = 1)
    c = 1;
    result = ALU(a, b, c);

    printf("Subtraction: %d - %d = %d\n", (int)a, (int)b, (int)result);

    if (result != (a - b)) {
        printf("Error in subtraction\n");
    }
}

/---------------------------------------------------------------------------------------------------------------------------------------------------/

// part 3 <using pragmas> for faster execution

	
// interfaces 1.axis(axi stream) 2. m_axi(axi master port) 2.bram and fifo when parameters are arrays
//#pragma HLS INTERFACE ap_none port=a
//#pragma HLS INTERFACE s_axilite port=a
//#pragma HLS INTERFACE AP_MEMORY or FIFO port=in_vec






#include <hls_stream.h>
#include <ap_int.h>

#define VECTOR_SIZE 1024

void vector_add(const int *a, const int *b, int *c, int size) {

//#pragma HLS PIPELINE II=1 II stands for initialization interval
//#pragma HLS UNROLL factor=4 this makes 4 iterations of the for loop run in parallel
    for (int i = 0; i < size; i++) {
        c[i] = a[i] + b[i];
    }
}




/---------------------------------------------------------------------------------------------------------------------------------------------------/

// part 4 math stuff
#include "hls_math.h"
#include "ap_fixed.h"

#include <hls_math.h>

typedef struct {
  float x;
  float y;
} Point;

float distance(Point p1, Point p2) {
  #pragma HLS INTERFACE ap_none port=p1
  #pragma HLS INTERFACE ap_none port=p2
  float dx = p2.x - p1.x;
  float dy = p2.y - p1.y;
  // Use hls::sqrt for hardware-friendly implementation
  return hls::sqrt(hls::square(dx) + hls::square(dy)); 
}

}


hls's People

Contributors

jiteshnayak2004 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.