Expressions¶
Hidet script supports the following expressions:
Literals¶
The literal expressions are the expressions that represent constant values. An integer literal (e.g., 1)
has data type i32 by default. A floating point literal (e.g., 1.0) has data type float32 by default.
A boolean literal (i.e., True and False) has data type bool by default. To define a literal with a
specific data type, we can use the form <data type>(<value>) like f16(1.0) in the hidet script.
Variables¶
A variable is an expression that represents a memory location. A variable has a name and a data type. A variable can be defined in 1) the function parameters, 2) the variable declaration statement, 3) the for loop statement, 4) the for-mapping statement.
Unary expressions¶
A unary expression is an expression that applies a unary operator to a single operand. The unary operators supported in hidet script are:
+e: unary plus-e: unary minus~e: get the address ofebitwise_not(e): bitwise not, wherebitwise_notrefers tohidet.lang.bitwise_notnot cond: logical not
Binary expressions¶
A binary expression is an expression that applies a binary operator to two operands. The binary operators supported in hidet script are:
e1 + e2: additione1 - e2: subtractione1 * e2: multiplicatione1 / e2: division (we follow the semantics of c/c++ instead of python)e1 % e2: remaindere1 ** e2: powere1 << e2: left shifte1 >> e2: right shifte1 & e2: bitwise ande1 | e2: bitwise ore1 ^ e2: bitwise xore1 and e2: logical ande1 or e2: logical ore1 == e2: equale1 != e2: not equale1 < e2: less thane1 <= e2: less than or equale1 > e2: greater thane1 >= e2: greater than or equal
Note on division: in python, the division operator / will produce a floating point result even if the
operands are integers. However, in hidet script, we follow the semantics of c/c++: if the operands are integers,
the division operator / will produce an integer result with floor(a / b) value; if the operands are floating
point numbers, the division operator / will produce a floating point result.
Ternary expressions¶
A ternary expression is an expression that applies a ternary operator to three operands. The ternary operator supported in hidet script is:
true_expr if cond else false_expr: conditional expression
This operator has the same semantics as the conditional expression in c/c++: cond ? true_expr : false_expr.
Subscript and slice expressions¶
For a tensor t or tensor pointer
e1[p1, p2, ..., pn]: subscript expressione1[p1, p2:q2, p3:, :p4, :, p5]: slice expressionfunc(e1, e2, ..., en): function call expressionaddress(e): get the address ofe, whereaddressrefers tohidet.lang.address