Expressions and Operators

Arx does not differ much from other mainstream languages in the way it deals with expressions and operators. Parentheses ( and ) can be used to override default precedence when grouping operands (“multiplication binds stronger than addition”, etc.).

The operators supported by Arx are listed on this page, grouped by the data types of their operands or results. Next to the operators mentioned here, function calls can also be part of an expression.

Arithmetic Operators

Arithmetic operators operate on data types that represent numeric data, such as integers, reals or fixed-point numbers. The following binary infix operators are supported:

Operator Explanation
+ addition
- subtraction
* multiplication
max maximum
min minimum
/ division
mod modulo
>> arithmetic shift right
<< arithmetic shift left

Remark: Division and is only supported for integers and reals; modulo only for integers. Arx does not support these operators for VHDL generation. The shift operators are only allowed for fixed-point data types.

Arx knows two unary operators:

Operator Explanation
+ plus
- minus

Arx has the following built-in functions:

Function Explanation
abs absolute value
log2 base-2 logarithm
pow2 base-2 exponentiation
ceil ceiling
floor floor

The functions log2, pow2, floor and ceil cannot be used to specify computations in the hardware. They are meant for the specification of sizes of vectors and arrays expressed in generics. They can also be used to express the value of constants in terms of generics.

The example below illustrates several of the functions just mentioned.

multi_max.arx
component top 
  word_length : generic integer = 8
  memory_depth: generic integer = 10
  T_IO        : generic type = bitvector(word_length)
  data_in     : in T_IO
  data_out    : out T_IO
 
type 
  T_num : signed(word_length)
 
constant 
  addr_bits: integer = ceil(log2(memory_depth))
 
register
  storage: array [memory_depth] of T_num = 0
  addr_counter: unsigned(addr_bits) = memory_depth - 1
 
begin
  if addr_counter == 0
     addr_counter = memory_depth - 1
  else
     addr_counter = addr_counter - 1
  end
 
  storage[addr_counter] = reinterpret(T_num, data_in) max storage[addr_counter]
  data_out = storage[addr_counter]
end

Logic Operators

Logic operators operate on bits, bitvectors and booleans. The following operators exist:

Operator Explanation
and bitwise AND
or bitwise OR
xor bitwise exclusive OR
not bitwise NOT

All operators are binary infix, except for not which is unary prefix. The line below shows an expression with logic operators:

c = (not b) xor a

Relational Operators

Relational operators operate on numeric values and return a boolean. These are the relational operators supported by Arx:

Operator Explanation
< less than
> more than
== equal
!= not equal
>= more than or equal
<= less than or equal
 
arx/expressions.txt · Last modified: 2023/07/17 22:40 by 127.0.0.1