Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better blackbox operation for vindex #12

Closed
BosJ opened this issue May 13, 2014 · 1 comment
Closed

Better blackbox operation for vindex #12

BosJ opened this issue May 13, 2014 · 1 comment
Assignees
Milestone

Comments

@BosJ
Copy link
Contributor

BosJ commented May 13, 2014

Solves wrong integer initialization when an integer is used as array-index, it is by default initialized as "Integer 'LOW" (-1). The simulator (Questa Sim) reports after a few delta cycles: Fatal error #_#_vindex_integer at <file>

[
{ "BlackBox" :
    { "name"      : "CLaSH.Sized.Vector.vindex_integer"
    , "templateD" :
"~SYM[0]_vindex_integer : block
  signal ~SYM[1] : ~TYP[1];
begin
  ~SYM[1] <= ~ARG[1];
  -- pragma translate_off
  ~SYM[2]_proc : process (~SYM[1],~ARG[2]) is
  begin
    if ~ARG[2] < 0 then
       ~RESULT <= ~SYM[1](0);
    else
    -- pragma translate_on
    ~RESULT <= ~SYM[1](~ARG[2]);
    -- pragma translate_off
    end if;
  end process;
  -- pragma translate_on
end block;"
    }
  }
]

EDIT: the above goes still wrong with constants in the second argument, maybe the code below is better?

[
{ "BlackBox" :
    { "name"      : "CLaSH.Sized.Vector.vindex_integer"
    , "templateD" :
"~SYM[0]_vindex_integer : block
  signal ~SYM[1] : ~TYP[1];
  signal ~SYM[2] : ~TYP[2] := 0;
begin
  ~SYM[1] <= ~ARG[1];
  ~SYM[2] <= ~ARG[2];
  -- pragma translate_off
  ~SYM[2]_proc : process (~SYM[1],~SYM[2]) is
  begin
    if ~ARG[2] < 0 then
       ~RESULT <= ~SYM[1](0);
    else
    -- pragma translate_on
    ~RESULT <= ~SYM[1](~SYM[2]);
    -- pragma translate_off
    end if;
  end process;
  -- pragma translate_on
end block;"
    }
  }
]
@christiaanb
Copy link
Member

You are indeed right that constants might end up in the sensitivity list with the old version. Here is the final improvement that I made, although I still have to actually test it:

[ { "BlackBox" :
    { "name"      : "CLaSH.Sized.Vector.vindex_integer"
    , "templateD" :
"~SYM[0]_vindex_integer : block
  signal ~SYM[1] : ~TYP[1];
  signal ~SYM[2] : ~TYP[2];
begin
  ~SYM[1] <= ~ARG[1];
  ~SYM[2] <= ~ARG[2];
  -- pragma translate_off
  process (~SYM[1],~SYM[2])
  begin
    if ~SYM[2] < ~SYM[1]'low or ~SYM[2] > ~SYM[1]'high then
      assert true report (\"Index: \" & integer'image(~SYM[2]) & \" is out of bounds:\" & integer'image(~SYM[1]'low) & \"-\" & integer'image(~SYM[1]'high)) severity warning;
      ~RESULT <= ~DEFAULTO;
    else
    -- pragma translate_on
      ~RESULT <= ~SYM[1](~SYM[2]);
    -- pragma translate_off
    end if;
  end process;
  -- pragma translate_on
end block;"
    }
  }
, { "BlackBox" :
    { "name"      : "CLaSH.Sized.Vector.vreplace_integer"
    , "templateD" :
"~SYM[0]_vreplace_integer : block
  signal ~SYM[1] : ~TYP[1];
  signal ~SYM[2] : ~TYP[2];
  signal ~SYM[3] : ~TYP[3];
begin
  ~SYM[1] <= ~ARG[1];
  ~SYM[2] <= ~ARG[2];
  ~SYM[3] <= ~ARG[3];
  process(~SYM[1],~SYM[2],~SYM[3])
    variable ~SYM[4] : ~TYP[1];
  begin
    ~SYM[4] := ~SYM[1];
    -- pragma translate_off
    if ~SYM[2] < ~SYM[4]'low or ~SYM[2] > ~SYM[4]'high then
      assert true report (\"Index: \" & integer'image(~SYM[2]) & \" is out of bounds:\" & integer'image(~SYM[1]'low) & \"-\" & integer'image(~SYM[1]'high)) severity warning;
    else
      -- pragma translate_on
      ~SYM[4](~SYM[2]) := ~SYM[3];
      -- pragma translate_off
    end if;
    -- pragma translate_on
    ~RESULT <= ~SYM[4];
  end process;
end block;"
    }
  }
]

@christiaanb christiaanb modified the milestone: 0.3.1 May 14, 2014
leonschoorl pushed a commit that referenced this issue Jul 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants