Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
language:expressions [2024/03/20 07:07]
rajit [Expressions in CHP]
language:expressions [2024/03/20 07:19] (current)
rajit [External circuit functions]
Line 19: Line 19:
    * ''bool(x)'': ''x'' must be an integer expression. This returns false if the integer is zero, and true otherwise.    * ''bool(x)'': ''x'' must be an integer expression. This returns false if the integer is zero, and true otherwise.
  
 +Syntactic replication is also supported for the operators ''&'', ''|'', ''^'', ''+'', and ''*''. This means the following expression is valid
 +<code act>
 +  (+ i : 3 : p[i] + 2*i)
 +</code>
 +and is equivalent to
 +<code act>
 +  p[0] + 2*0 + p[1] + 2*1 + p[2] + 2*2
 +</code>
  
 ===== Parameters and constant expressions ===== ===== Parameters and constant expressions =====
Line 95: Line 103:
 </code> </code>
  
-Now the right hand side of the first assignment takes ''x'' and ''1'' and does the subtraction that was expected. The second assignment, on the other hand, takes the bit-pattern for ''-1'' (which is ''1''), and adds it to ''y''!+Now the right hand side of the first assignment takes ''x'' and ''1'' and does the subtraction that was expected. The second assignment, on the other hand, takes the bit-pattern for ''-1'' (this turns out to be ''1''), and adds it to ''y''In other words, ''x-1'' and ''x+(-1)'' are not the same because of the way the bit-width rules operate. If you have any doubts, the ''int(...)'' operator can be used to specify the bit-width.
  
  
Line 240: Line 248:
  
 An example of file I/O implemented with external functions can be found in the ''actsim'' [[https://github.com/asyncvlsi/actsim|git repository]] in the ''simlib/'' directory. An example of file I/O implemented with external functions can be found in the ''actsim'' [[https://github.com/asyncvlsi/actsim|git repository]] in the ''simlib/'' directory.
 +
 +===== Operator Precedence =====
 +
 +The operators have the following precedence, from the highest to lowest:
 +   - ''~'', ''!''
 +   - ''*'', ''/'', ''%''
 +   - ''+'', ''-''
 +   - ''<<'', ''>>'', ''>>>'', ''<'', ''>'', ''<='', ''>='', ''='', ''!=''
 +   - ''&''
 +   - ''^''
 +   - ''|''
 +   - ''?''