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

[minor] Add Property primitive operations, starting with integer addition. #168

Merged
merged 4 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions revision-history.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ revisionHistory:
- Define "Storable Type".
- Change the minimum width of the result of "Shift Right" on UInt to 0-bit.
- Allow assert and assume statements to have a format string
- Add Property primitive operations, starting with integer addition
abi:
- Add ABI for public modules and filelist output.
- Changed ABI for group and ref generated files.
Expand Down
48 changes: 47 additions & 1 deletion spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -2450,6 +2450,26 @@ asClock(x)

[@sec:primitive-operations] will describe the format and semantics of each primitive operation.

## Primitive Property Operations {#sec:expressions:primitive-property-operations}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's kind of unfortunate that the PR has to go through this just because two different subsections have the same name. I should see if there is a pandoc option to do this automatically.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I just sort of followed how HW primitives do it--both naming the subsection the same as the section, and using these anchors to disambiguate. If there is a better option with pandoc, happy to use that.


All fundamental operations on property types are expressed as a FIRRTL primitive operation.
In general, each operation takes some number of property type expressions as arguments.

The general form of a primitive property operation is expressed as follows:

``` firrtl
op(arg0, arg1, ..., argn)
```

The following examples of primitive property operations demonstrate adding two property expressions, `a` and `b`, and adding an integer property literal to expression `a`.

``` firrtl
integer_add(a, b)
integer_add(a, Integer(2))
```

[@sec:primitive-property-operations] will describe the format and semantics of each primitive property operation.

## Reading Probe References

Probes are read using the `read`{.firrtl} operation.
Expand Down Expand Up @@ -3070,6 +3090,24 @@ n must be non-negative and less than or equal to the bit width of e.
The tail operation truncates the n most significant bits from e.
n must be non-negative and less than or equal to the bit width of e.

# Primitive Property Operations {#primitive-property-operations}

The arguments of all primitive property operations must be expressions with property types.
Each specific operation can place additional restrictions on the number and types of their arguments.
In general, primitive property operations are named with a prefix indicating the property type on which they operate.

## Integer Arthmetic

Integer arithmetic operations take `Integer`{.firrtl} property type expressions as arguments and return an `Integer`{.firrtl} property type result.

### Integer Add Operation

Name Arguments Arg Types Result Type
------------- ----------- ------------------- -------------
integer_add (e1,e2) (Integer,Integer) Integer

The add operation result is the arbitrary precision signed integer arithmetic sum of e1 and e2.

# Notes on Syntax

FIRRTL's syntax is designed to be human-readable but easily algorithmically parsed.
Expand Down Expand Up @@ -3411,7 +3449,8 @@ expr_probe =
| reference_static ;

property_literal_expr = "Integer", "(", int, ")" ;
property_expr = reference_static | property_literal_expr ;
property_expr = reference_static | property_literal_expr | property_expr_primop ;
property_expr_primop = property_primop_2expr ;
expr_primop = primop_2expr | primop_1expr | primop_1expr1int | primop_1expr2int ;

(* Types *)
Expand Down Expand Up @@ -3459,6 +3498,10 @@ primop_1expr = primop_1expr_keyword , "(" , expr , ")" ;
primop_1expr1int = primop_1expr1int_keyword , "(", expr , "," , int , ")" ;
primop_1expr2int = primop_1expr2int_keyword , "(" , expr , "," , int , "," , int , ")" ;

(* Primitive Property Operations *)
property_primop_2expr = property_primop_2expr_keyword ,
"(" , property_expr , "," , property_expr ")" ;

(* Tokens: Annotations *)
annotations = "%" , "[" , json_array , "]" ;

Expand Down Expand Up @@ -3525,6 +3568,9 @@ primop_1expr1int_keyword =
"pad" | "shl" | "shr" | "head" | "tail" ;

primop_1expr2int_keyword = "bits" ;

property_primop_2expr_keyword =
"integer_add" ;
```

# Versioning Scheme of this Document
Expand Down
Loading