Skip to content

Commit 4832414

Browse files
committed
sail_sv_backend: swap element ordering for unpacked array
In SystemVerilog, unpacked arrays are typically in the form of `[0:LEN-1]` instead of `[LEN-1:0]` (which is the convention for packed arrays). In fact, commonly people just use `[LEN]` and this is a shorthand for `[0:LEN-1]`. Currently sail_sv_backend always use `[LEN-1:0]` even for unpacked arrays; this causes the whole array to be flipped even the user passed in an array declared with `[LEN]`.
1 parent 3f31706 commit 4832414

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

src/sail_sv_backend/jib_sv.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ module Make (Config : CONFIG) = struct
162162
ksprintf simple_type "logic [%d:0]" (width - 1)
163163
| CT_ref ctyp -> ksprintf simple_type "sail_reg_%s" (Util.zencode_string (string_of_ctyp ctyp))
164164
| CT_fvector (len, ctyp) ->
165-
let outer_index = sprintf "[%d:0]" (len - 1) in
165+
let outer_index = sprintf "[%d]" len in
166166
begin
167167
match sv_ctyp ctyp with
168168
| ty, Some inner_index -> (ty, Some (inner_index ^ outer_index))

src/sail_sv_backend/sail_plugin_sv.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ let verilog_target _ default_sail_dir out_opt ast effect_info env =
469469
) ^^ hardline ^^ string "end" ^^ hardline
470470
in
471471
let fun_body = concat (List.init slots fun_body_slot) ^^ string "sail_reached_unreachable = 1;" in
472-
let slot_ranges = string ("[" ^ string_of_int (slots - 1) ^ ":0]") in
472+
let slot_ranges = string ("[" ^ string_of_int slots ^ "]") in
473473
( sv_fundef_with ctx real_name arg_nms arg_typs ret_ty fun_body ^^ twice hardline,
474474
separate space [string "output"; string "bit"; invoke_flag ^^ slot_ranges]
475475
:: separate space [string "input"; string (fst (sv_ctyp ret_ty)); result ^^ slot_ranges]

0 commit comments

Comments
 (0)