Repository navigation
Description
Problem
The same kind of declaration is written two ways. Outside the Std:: library, 123
function signatures give a parameter a set type, e.g. Calculate_Bit_Offset
(implicit operand_size : {16, 32, 64}), and most of their bodies do not repeat it. Other helpers declare the parameter Integer and restrict
it with assert statements at the start of the body, e.g. Mem_Fetch:
function Mem_Fetch?(rip : Bits(64), size : Integer) -> Bits(size)
begin
assert size in {8, 16, 32, 64};
In these 15 helpers, the leading asserts are the first statements, are pure, and check the
parameters in parameter order:
| helper | parameter: set |
|---|---|
Calculate_Offset |
address_size : {16, 32, 64} |
Compress_Mask |
size : {128, 256, 512}, element_size : {8, 16, 32, 64} |
Create_Physical_Address |
size : {8, 16, 32, 64, 128, 256, 384, 512, 1024} |
Is_Linear_Aligned |
size : {8, 16, 32, 64, 80, 128, 256, 384, 512, 1024} |
Linear_Mem_Read? |
size : {8, 16, 32, 64, 128, 256, 384, 512, 1024} |
Linear_Mem_Write? |
size : {8, 16, 32, 64, 128, 256, 384, 512, 1024} |
Logical_Mem_Read? |
size : {8, 16, 32, 64, 80, 112, 128, 224, 256, 384, 512, 1024} |
Masked_Vector_Mem_Read? |
size : {16, 32, 64, 128, 256, 512}, element_size : {8, 16, 32, 64} |
Masked_Vector_Mem_Write? |
size : {16, 32, 64, 128, 256, 512}, element_size : {8, 16, 32, 64} |
Mem_Fetch? |
size : {8, 16, 32, 64} |
Packed_Vector_Mem_Read? |
size : {128, 256, 512}, element_size : {8, 16, 32, 64} |
Packed_Vector_Mem_Write? |
size : {16, 32, 64, 128, 256, 512}, element_size : {8, 16, 32, 64} |
Pop_Stack? |
size : {16, 32, 64}, pop_size : {16, 32, 64} |
Push_Stack? |
size : {16, 32, 64}, push_size : {16, 32, 64} |
Vector_Mem_Read? |
size : {128, 256, 512}, element_size : {8, 16, 32, 64} |
Seventeen helpers do both: they declare the set type and then repeat it as the first
statement, e.g. Dot_Product(implicit N : {16, 32, 64}, …) followed by
assert N in {16, 32, 64};. They are Dot_Product, FP::Arithmetic, FP::Class,
FP::Compare, FP::Compare5, FP::FMA, FP::Get_Exponent, FP::Get_Mantissa,
FP::Min_Max, FP::Reciprocal, FP::Reciprocal_14, FP::Reciprocal_Sqrt,
FP::Reciprocal_Sqrt_14, FP::Reduce, FP::Round_To_Fraction, FP::Scale and FP::Sqrt.
The manual says "checking of set types is performed dynamically", but describes the
check only for assignment (ISA_LRM, "Types"): "… a runtime check that the value
being assigned is a member of the set". It does not say whether binding an argument to a
set-typed parameter is checked, when that check happens, or what a failed check does.
Proposed fix
- In the manual, state that binding an argument to a parameter of a set type checks
membership after all arguments have been evaluated, and that a failed check fails as a
failedassertdoes. - With that rule, move each leading assert in the table into the parameter's type, and
drop the 17 repeated asserts. Each change keeps the same checks in the same order, so
no result changes; the parameter domains become part of the signatures.
AI disclosure
Assisted-by: Claude
Claude assisted with source analysis, the proposed correction and drafting this report.
Reviewed with assistance from Codex.
Pinned source: definitions.xml.gz at revision 35eface1b7ee003a1cda95005ec5fd83de658a64.
Activity