HW

9
SOURAV SAMANTA (1207860455) ANKIT MITRA (1207332369) SHAIL J. DAVE (1207827175) Solution 1.a) Case A: Source Code // case A class Test; rand logic [2:0] num1, num2; logic [2:0] num2_a [] = '{4, 5, 6}; logic [2:0] num2_b [] = '{0, 1, 2, 3, 7, 8, 9, 10, 11, 12, 13, 14, 15}; constraint c { if (num1 > 3) { num2 dist { num2_a :/30, num2_b :/70 }; } else { num2 inside { [2:4] }; } } endclass P (A|B) = 0.3 P (B) = 0.75. P (A|B) = 3/16 P (B) = 0.25. Therefore, the probability is = 0.3*0.75 + 3/16 * 0.25 = 0.271875 Case B: Source Code // case B class Test; rand logic [2:0] num1, num2; logic [2:0] num2_a [] = '{1, 2, 3}; logic [2:0] num2_b [] = '{0, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; constraint c { if (num1 > 3) { num2 dist { num2_a :/50, num2_b :/50 }; } else { num2 inside { [2:4] }; } } endclass P (A|B) = 0.5 P (B) = 0.75. P (A|B) = 3/16 P (B) = 0.25. Therefore, the probability is = 0.5*0.75 + 3/16 * 0.25 = 0.421875 Solution 1.b)

description

System

Transcript of HW

SOURAV SAMANTA (1207860455)ANKIT MITRA (1207332369)SHAIL J. DAVE (1207827175)Solution 1.a)Case A: Source Code// case Aclass Test;rand logic [2:0] num1, num2;logic [2:0] num2_a [] = '{4, 5, 6}; logic [2:0] num2_b [] = '{0, 1, 2, 3, 7, 8, 9, 10, 11, 12, 13, 14, 15}; constraint c{ if (num1 > 3) {num2 dist { num2_a :/30, num2_b :/70 };}else {num2 inside { [2:4] };}}endclass

P (A|B) = 0.3 P (B) = 0.75. P (A|B) = 3/16 P (B) = 0.25.Therefore, the probability is = 0.3*0.75 + 3/16 * 0.25 = 0.271875

Case B: Source Code// case Bclass Test;rand logic [2:0] num1, num2;logic [2:0] num2_a [] = '{1, 2, 3}; logic [2:0] num2_b [] = '{0, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; constraint c{ if (num1 > 3) {num2 dist { num2_a :/50, num2_b :/50 };}else {num2 inside { [2:4] };}}endclass

P (A|B) = 0.5 P (B) = 0.75. P (A|B) = 3/16 P (B) = 0.25.Therefore, the probability is = 0.5*0.75 + 3/16 * 0.25 = 0.421875

Solution 1.b)Case A: The probability of s being true is 1/(2^23)Case B: The probability of s being true is 1/2Solution 2.a) Source Codeprogram automatic test;int q[$] = {1, 2, 3, 4, 5};int b[$] = {3, 4, 4, 5};int tq[$] = {};int j,k;initial beginrepeat (2) beginrepeat (2) begink = b.pop_front;q.push_front(k);$write ("\nk = %0d", k);$write ("\nb = ");foreach (b[i])$write ("%0d ", b[i]);$write ("\nq = ");foreach (q[i])$write ("%0d ", q[i]);endk = q.pop_back;b.push_back(k);$write ("\nk = %0d", k);$write ("\nb = ");foreach (b[i])$write ("%0d ", b[i]);$write ("\nq = ");foreach (q[i])$write ("%0d ", q[i]);endendendprogram : test

Output

Final values: k = 4, b = {5, 4} and q = {5, 4, 4, 3, 1, 2, 3}

Solution 2.b) Source Codeprogram automatic test;int q[$] = {1, 2, 3, 4, 5};//int b[$] = {2{6}, 2{7}, 1{8}};// {6, 6, 7, 7, 8};int b[$] = {6, 6, 7, 7, 8};int tq[$] = {};int j,k;initial beginrepeat(5) beginj = q.pop_front;b.push_front(j);j = b.pop_back;q.push_back(j);end$write ("\nq = ");foreach (q[i])$write ("%0d ", q[i]);$write ("\nb = ");foreach (b[i])$write ("%0d ", b[i]);endendprogram : test

Outputq = {8, 7, 7, 6, 6} and b = {5, 4, 3, 2, 1}

Solution 2.c) Source Codeprogram automatic test;int q[$] = {1, 2, 3, 4, 5};//int b[$] = {2{6}, 2{7}, 1{8}};// {6, 6, 7, 7, 8};int b[$] = {6, 6, 7, 7, 8};int tq[$] = {};int j,k;initial beginrepeat(5) beginj = q.pop_front;b.push_front(j);j = b.pop_back;q.push_back(j);endrepeat(5) begink = q.pop_back;b.push_front(k);k = b.pop_back;q.push_front(k);end$write ("\nq = ");foreach (q[i])$write ("%0d ", q[i]);$write ("\nb = ");foreach (b[i])$write ("%0d ", b[i]);endendprogram : test

Output: q = {5, 4, 3, 2, 1} and b = {8, 7, 7, 6, 6}

Solution 2.d) Source Codeprogram automatic test;int q[$] = {1, 2, 3, 4, 5};int b[$] = {6, 6, 7, 7, 8};int tq[$] = {};int j;initial begin$write ("\ntq = ");tq = q.find_index with (item < 4); //[1]foreach (tq[i])$write ("%0d ", tq[i]); j = b.sum(item) with (item == 8); //[2] $display("\nj = %0d", j);tq.delete(j); //[1] foreach (tq[i])$write ("%0d ", tq[i]); b.insert(tq[1], tq[0]); //[2] $write ("\nb = "); foreach (b[i]) $write ("%0d ", b[i]);endendprogram : test

Output[1] -> tq = {0, 1, 2}[2] -> j = 1

[1] -> tq = {0, 2}.[2] -> b = {6, 6, 0, 7, 7, 8}

Solution 3.a) For a declaration of type bit [7:0] Instr [2][2]; by designer A, the memory required (in bits) to store 1 instruction in the Cache is = 4*8 = 32 bits (Largest accessible unit is packed 8 bits)Instr [0][0][0]Instr [0][1][0]

Instr [0][0][1]Instr [0][1][1]

Instr [0][0][2]Instr [0][1][2]

Instr [0][0][3]Instr [0][1][3]

Instr [0][0][4]Instr [0][1][4]

Instr [0][0][5]Instr [0][1][5]

Instr [0][0][6]Instr [0][1][6]

Instr [0][0][7]Instr [0][1][7]

Instr [1][0][0]Instr [1][1][0]

Instr [1][0][1]Instr [1][1][1]

Instr [1][0][2]Instr [1][1][2]

Instr [1][0][3]Instr [1][1][3]

Instr [1][0][4]Instr [1][1][4]

Instr [1][0][5]Instr [1][1][5]

Instr [1][0][6]Instr [1][1][6]

Instr [1][0][7]Instr [1][1][7]

Solution 3.b) For a declaration of type bit [1:0] [7:0] Instr [2]; by designer B, the memory required (in bits) to store 1 instruction in the Cache is = 2*16 = 32 bits (Largest accessible unit is packed 16 bits)

Instr [0][1][7:0]Instr [0][0][7:0]

Instr [1][1][7:0]Instr [1][0][7:0]

Solution 3.c) Designer Bs declaration of array is more compact in terms of memory consumption since there are more number of bits allocated in the packed portion of the array as compared to designer A. Number of packed bits in Bs design is = 16 bits as compared to A (indicated by same colours in the above memory representation).

Yes, there is a more efficient way to declare Instruction with minimum memory consumption if it can be declared in the following way: bit [1:0] [1:0] [7:0] Instruction;Instruction[1][1][7:0]Instruction [1][0][7:0]Instruction [0][1][7:0]Instruction [0][0][7:0]

Here, the largest accessible unit is packed 32 bits.

Solution 3.d) Setting the value of most significant 3 bits of OPCODE 2 in the first Instruction to 101 (using declaration in part c) is by: Instruction [0][1][7:5] = 'b101; OPCODE 1DATAOPCODE 2DATA

Solution 3.e) Setting the value of least significant 4 bits of OPCODE 1 in the first Instruction to 1110 (using the declaration in part a) is by: Instr [0][0][3:0] = 'b1110;

Source Codeprogram automatic test;bit [7:0] Instr [2][2]; initial beginInstr [0][0][3:0] = 'b1110;$display ("%0d", Instr [0][0][3]);$display ("%0d", Instr [0][0][2]);$display ("%0d", Instr [0][0][1]);$display ("%0d", Instr [0][0][0]); endendprogram : test

Solution 3.f) If the size of the instruction cache is not known at run time, then we can go for Dynamic array allocation. This can be declared in the following way: bit [31:0] Instr[];

Solution 3.g)Source Codeprogram automatic test;bit [31:0] Instr[]; initial begin Instr = new[10]; endendprogram : test

Solution 3.h) Source Codeprogram automatic test; bit [31:0] Instr[]; initial begin Instr = new[10]; foreach (Instr[i]) begin Instr[i][31:24] = 8'h42; $display("%0h", Instr[i]); end end endprogram : test

Solution 4)Source Codemodule Solution4;bit [1:0][3:0] Mem [6][8][10];// Solution 4.a Mem[y][x][z]parameter a = 1,b = 2,c = 4;initial begin// Solution 4.b : Array initialised to the Sum of the dimension of the arrayforeach(Mem[i,j,k]) beginMem[i][j][k] = i + j + k;end$display("Mem[1][1][3] = %0d", Mem[1][1][3]);$display("Mem[3][4][5] = %0d", Mem[3][4][5]);// Solution 4.c : Display the contents of the memory at the location marked in grey.$display("Mem[2][7][0] = %0d", Mem[2][7][0]);// Solution 4.d: a:- Byte b:- Nibble c:- Bitfor ( int x = 0; x < 2; x++ ) beginfor ( int i = 0; i < a; i++ ) begin$write ("\nBYTE: a = %0d\n",Mem[4][6+x][4]);for ( int j = 0; j < b; j++ ) begin$write ("NIBBLE: b[%0d] = %0b ", j, Mem[4][6+x][4][j]);for ( int k = 0; k < c; k++ ) begin$write ("BIT: c[%0d] = %0b ", (4*j+k), Mem[4][6+x][4][j][k]);end$display();end$display();endendendendmodule

Output