aboutsummaryrefslogtreecommitdiffstats
path: root/riscV/OpWeights.ml
blob: 637f29048ab5fb88fb5756002f3ec7db781bfb6a (plain)
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
open Op;;

(* Attempt at modeling the Rocket core *)

let resource_bounds = [| 1 |];;
let nr_non_pipelined_units = 1;; (* divider *)

let latency_of_op (op : operation) (nargs : int) =
  match op with
    | Omul  | Omulhs  | Omulhu
    | Omull | Omullhs | Omullhu -> 4

  | Onegf -> 1               (*r [rd = - r1] *)
  | Oabsf                    (*r [rd = abs(r1)] *)
  | Oaddf                    (*r [rd = r1 + r2] *)
  | Osubf                    (*r [rd = r1 - r2] *)
  | Omulf -> 6               (*r [rd = r1 * r2] *)
  | Onegfs -> 1              (*r [rd = - r1] *)
  | Oabsfs                   (*r [rd = abs(r1)] *)
  | Oaddfs                   (*r [rd = r1 + r2] *)
  | Osubfs                   (*r [rd = r1 - r2] *)
  | Omulfs -> 4              (*r [rd = r1 * r2] *)
  | Osingleoffloat           (*r [rd] is [r1] truncated to single-precision float *)
  | Ofloatofsingle -> 4      (*r [rd] is [r1] extended to double-precision float *)
(*c Conversions between int and float: *)
  | Ointoffloat              (*r [rd = signed_int_of_float64(r1)] *)
  | Ointuoffloat             (*r [rd = unsigned_int_of_float64(r1)] *)
  | Ofloatofint              (*r [rd = float64_of_signed_int(r1)] *)
  | Ofloatofintu -> 6        (*r [rd = float64_of_unsigned_int(r1)] *)
  | Ointofsingle             (*r [rd = signed_int_of_float32(r1)] *)
  | Ointuofsingle            (*r [rd = unsigned_int_of_float32(r1)] *)
  | Osingleofint             (*r [rd = float32_of_signed_int(r1)] *)
  | Osingleofintu -> 4       (*r [rd = float32_of_unsigned_int(r1)] *)
  | Olongoffloat             (*r [rd = signed_long_of_float64(r1)] *)
  | Olonguoffloat            (*r [rd = unsigned_long_of_float64(r1)] *)
  | Ofloatoflong             (*r [rd = float64_of_signed_long(r1)] *)
  | Ofloatoflongu -> 6       (*r [rd = float64_of_unsigned_long(r1)] *)
  | Olongofsingle            (*r [rd = signed_long_of_float32(r1)] *)
  | Olonguofsingle           (*r [rd = unsigned_long_of_float32(r1)] *)
  | Osingleoflong            (*r [rd = float32_of_signed_long(r1)] *)
  | Osingleoflongu -> 4      (*r [rd = float32_of_unsigned_int(r1)] *)
                                 
  | Odiv | Odivu | Odivl | Odivlu -> 16  
  | Odivfs -> 35
  | Odivf -> 50

  | Ocmp cond ->
     (match cond with
      | Ccomp _
      | Ccompu _
      | Ccompimm _
      | Ccompuimm _
      | Ccompl _
      | Ccomplu _
      | Ccomplimm _
      | Ccompluimm _ -> 1
      | Ccompf _
      | Cnotcompf _ -> 6
      | Ccompfs _
      | Cnotcompfs _ -> 4)
  | _ -> 1;;

let resources_of_op (op : operation) (nargs : int) = resource_bounds;;
  
let non_pipelined_resources_of_op (op : operation) (nargs : int) =
  match op with
  | Odiv | Odivu -> [| 29 |]
  | Odivfs -> [| 20 |]
  | Odivl | Odivlu | Odivf -> [| 50 |]
  | _ -> [| -1 |];;

let resources_of_cond (cond : condition) (nargs : int) = resource_bounds;;

let latency_of_load trap chunk (addr : addressing) (nargs : int) = 3;;
let latency_of_call _ _ = 6;;

let resources_of_load trap chunk addressing nargs = resource_bounds;;

let resources_of_store chunk addressing nargs = resource_bounds;;

let resources_of_call _ _ = resource_bounds;;
let resources_of_builtin _ = resource_bounds;;

(*
(* Attempt at modeling SweRV EH1
[| issues ; LSU ; multiplier |] *)
let resource_bounds = [| 2 ; 1; 1 |];;
let nr_non_pipelined_units = 1;; (* divider *)

let latency_of_op (op : operation) (nargs : int) =
  match op with
    | Omul  | Omulhs  | Omulhu
    | Omull | Omullhs | Omullhu -> 3
    | Odiv | Odivu | Odivl | Odivlu -> 16  
    | _ -> 1;;

let resources_of_op (op : operation) (nargs : int) = 
  match op with
    | Omul  | Omulhs  | Omulhu
    | Omull | Omullhs | Omullhu -> [| 1 ; 0 ; 1 |]
    | Odiv | Odivu | Odivl | Odivlu -> [| 0 ; 0; 0 |]                        
    | _ -> [| 1; 0; 0; 0 |];;
  
let non_pipelined_resources_of_op (op : operation) (nargs : int) =
  match op with
  | Odiv | Odivu -> [| 29 |]
  | Odivfs -> [| 20 |]
  | Odivl | Odivlu | Odivf -> [| 50 |]
  | _ -> [| -1 |];;

let resources_of_cond (cond : condition) (nargs : int) = [| 1; 0; 0 |];;

let latency_of_load trap chunk (addr : addressing) (nargs : int) = 3;;
let latency_of_call _ _ = 6;;

let resources_of_load trap chunk addressing nargs = [| 1; 1; 0 |];;

let resources_of_store chunk addressing nargs = [| 1; 1; 0 |];;

let resources_of_call _ _ = resource_bounds;;
let resources_of_builtin _ = resource_bounds;;
 *)