-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmatmult.adb
79 lines (65 loc) · 1.98 KB
/
matmult.adb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
-- =======================================================
-- Ada WCET Benchmark v.1.0
-- University of Padua
-- =======================================================
-- Porting to Ada of C WCET becnhmark from:
--
-- Mälardalen WCET research group:
-- http://www.mrtc.mdh.se/projects/wcet/benchmarks.html
--
-- SNU-RT Benchmark Suite for Worst Case Timing Analysis
-- Real-Time Research Group, Seoul National University
-- S.-S. Lim ([email protected])
-- =======================================================
package body Matmult is
Seed : Integer := 0;
ArrayA, ArrayB, ResultArray : Matrix (20, 20);
Matrix_Mismatch : exception;
procedure Init_Seed is
begin
Seed := 0;
end Init_Seed;
procedure MM_Test (A : in out Matrix; B : in out Matrix) is
begin
MM_Initialize (A);
MM_Initialize (B);
ResultArray := MM_Multiply (A, B);
end MM_Test;
function MM_Multiply (A : in Matrix; B : in Matrix) return Matrix is
result : Matrix (A.Rows, B.Cols);
begin
if A.Rows /= B.Cols then
raise Matrix_Mismatch;
end if;
for i in 1 .. A.Rows loop
for j in 1 .. B.Cols loop
result.Mat (i, j) := 0;
for k in 1 .. A.Cols loop
result.Mat (i, j) :=
result.Mat (i, j) + (A.Mat(i,k) * B.Mat(k,j));
end loop;
end loop;
end loop;
return result;
end MM_Multiply;
procedure MM_Initialize (A : in out Matrix) is
-- r, c : Integer;
begin
for i in 1 .. A.Rows loop
for j in 1 .. A.Cols loop
A.Mat (i, j) := MM_RandomInteger;
end loop;
end loop;
end MM_Initialize;
function MM_RandomInteger return Integer is
begin
Seed := (((Seed * 133) + 81) mod 8095);
return Seed;
end MM_RandomInteger;
procedure Matmult_main is
begin
Init_Seed;
MM_Test (ArrayA, ArrayB);
end Matmult_main;
end Matmult;