The following content is based on 2015-7-10 version of Chisel 2.2 Tutorial Finishing
We can define some repetitive logic as functions and then use them in multiple places, for example: a simple function is defined as follows:
def CLB (A:uint, B:uint, C:uint, d:uint) = (A & B) | (~c & D)
The function CLB has four parameters a,b,c,D, where the def is a keyword defined in Scala that defines a function, followed by a colon after each argument, followed by a data type. The return type is defined after the parameter, or it canbe undefined, andchisel automatically guesses that the return type is not defined in the previous example. After the equals sign is the function body. After the function definition, it uses the following method:
Val out = CLB (A, B, C, D)
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Chisel Tutorial (Iv.)--function