Skip to content

[herd] Petty optimisation of the Cat interpreter#1855

Merged
maranget merged 3 commits into
masterfrom
petty-opt-interpreter
Jul 7, 2026
Merged

[herd] Petty optimisation of the Cat interpreter#1855
maranget merged 3 commits into
masterfrom
petty-opt-interpreter

Conversation

@maranget

@maranget maranget commented Jun 11, 2026

Copy link
Copy Markdown
Member

Some optimisations that may help and never harm.

@maranget maranget force-pushed the petty-opt-interpreter branch 2 times, most recently from 0287e14 to ad9bfb2 Compare June 11, 2026 15:11
@maranget maranget changed the title [herd[ Petty optimisation nterpreter [herd[ Petty optimisation of the Cat interpreter Jun 11, 2026
@HadrienRenaud HadrienRenaud changed the title [herd[ Petty optimisation of the Cat interpreter [herd] Petty optimisation of the Cat interpreter Jun 11, 2026

@HadrienRenaud HadrienRenaud left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM, thanks Luc

Comment thread lib/innerRel.ml
Comment on lines +259 to +264
M.fold
(fun n _ r ->
if Elts.mem n nodes then
let _,r = dfs n r in r
else r)
m

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
M.fold
(fun n _ r ->
if Elts.mem n nodes then
let _,r = dfs n r in r
else r)
m
Elts.fold (fun n r -> dfs n r |> snd) m

But is it really different from scan_nodes_rel?

@maranget maranget Jun 12, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I guess you mean:

Elts.fold (fun n r -> dfs n r |> snd) nodes

This is slightly different from scan_nodes_rel as regards the type of nodes (set vs. list).

I choosed to iterate over the map and not over the set because I worried about the cost of dfs n r in the case where there is no binding for n in the map m. However if nodes is small it would be better to iterate over the set. I have no good solution here.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Oh I see what you mean, I had forgotten the case where nodes ⊄ domain(m).
I think probably your solution is better than mine.

In an ideal world it'd be nice to iterate over both at the same time, for example what baby does to compute the domain of a map.

Comment thread lib/innerRel.ml
@maranget maranget force-pushed the petty-opt-interpreter branch 3 times, most recently from 36b6275 to 2451721 Compare June 12, 2026 15:27
Comment thread lib/interpreter.ml Outdated
Comment thread lib/interpreter.ml
Comment thread lib/interpreter.ml
@maranget maranget force-pushed the petty-opt-interpreter branch 4 times, most recently from 7b1db3e to 3da02cd Compare June 22, 2026 08:39
@maranget maranget force-pushed the petty-opt-interpreter branch from 3da02cd to be7f652 Compare July 7, 2026 09:57
@maranget

maranget commented Jul 7, 2026

Copy link
Copy Markdown
Member Author

Hi @HadrienRenaud, I'd like to merge soon. May I have your opinion on this last version?

@HadrienRenaud HadrienRenaud left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Just some documentation comments. Please merge at your convenience.

Comment thread lib/innerRel.ml Outdated
Comment thread lib/innerRel.ml Outdated
Comment thread lib/innerRel.ml Outdated
maranget added 3 commits July 7, 2026 14:09
  + [restrict_codomain_to_set] Optimised evaluation of `r;[s]`
  + [restrict_domain_transitive_closure] Optimised evaluation of `[s];r+`

Gains are probably minor, but implementation is easy.

+
 + Compute `(...|r+|....)+` as `(...|r|...)+`
 + Optimise  `r;[s]`.
 + Optimise `[s];r+`.
@maranget maranget force-pushed the petty-opt-interpreter branch from be7f652 to 1e23070 Compare July 7, 2026 12:09
@maranget maranget merged commit 55f10df into master Jul 7, 2026
5 checks passed
@maranget maranget deleted the petty-opt-interpreter branch July 7, 2026 12:17
@maranget

maranget commented Jul 7, 2026

Copy link
Copy Markdown
Member Author

Merged, thanks @HadrienRenaud.

@akiyks

akiyks commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Hi @maranget ,

Another report of LKMM issue. After this merge, I get this fatal error in running herd7 on many LKMM litmus tests:

File "./linux-kernel.bell", line 85, characters 12-39: primitive different-values: argument mismatch

Said line in linux-kernel.bell looks like this:

flag ~empty different-values(srcu-rscs) as srcu-bad-value-match

I see a lot of activity in herd these days and this might be a transitory issue, but can you please have a look?

FYI, reverting 1e23070 on current master can paper over the error, but ends up in behavior changes of most litmus tests.

@maranget

Copy link
Copy Markdown
Member Author

Thanks for this @akiyks. This is indeed a "petty" bug. I publish a fix soon.

maranget added a commit that referenced this pull request Jul 10, 2026
Since PR #1855, the polymorphic value empty  circulates more.
Some primitives were performing set and relation normalisation
by themselves, overlooking the cases of empty and universe.
We fix this by using the already present and complete
normalisation functions `as_set` and `as_rel`
slightly generalised to handle different error reporting.
maranget added a commit that referenced this pull request Jul 10, 2026
Since PR #1855, the polymorphic value empty  circulates more.
Some primitives were performing set and relation normalisation
by themselves, overlooking the cases of empty and universe.
We fix this by using the already present and complete
normalisation functions `as_set` and `as_rel`
slightly generalised to handle different error reporting.
@maranget

Copy link
Copy Markdown
Member Author

Fix is PR #1912.

maranget added a commit that referenced this pull request Jul 10, 2026
Since PR #1855, the polymorphic value empty  circulates more.
Some primitives were performing set and relation normalisation
by themselves, overlooking the cases of empty and universe.
We fix this by using the already present and complete
normalisation functions `as_set` and `as_rel`
slightly generalised to handle different error reporting.

Reported-by: Akira Yokosawa <akiyks@gmail.com>
maranget added a commit that referenced this pull request Jul 10, 2026
Since PR #1855, the polymorphic value empty  circulates more.
Some primitives were performing set and relation normalisation
by themselves, overlooking the cases of empty and universe.
We fix this by using the already present and complete
normalisation functions `as_set` and `as_rel`
slightly generalised to handle different error reporting.

Reported-by: Akira Yokosawa <akiyks@gmail.com>
maranget added a commit that referenced this pull request Jul 10, 2026
Since PR #1855, the polymorphic value empty  circulates more.
Some primitives were performing set and relation normalisation
by themselves, overlooking the cases of empty and universe.
We fix this by using the already present and complete
normalisation functions `as_set` and `as_rel`
slightly generalised to handle different error reporting.

Reported-by: Akira Yokosawa <akiyks@gmail.com>
maranget added a commit that referenced this pull request Jul 10, 2026
Since PR #1855, the polymorphic value empty  circulates more.
Some primitives were performing set and relation normalisation
by themselves, overlooking the cases of empty and universe.
We fix this by using the already present and complete
normalisation functions `as_set` and `as_rel`
slightly generalised to handle different error reporting.

Reported-by: Akira Yokosawa <akiyks@gmail.com>
maranget added a commit that referenced this pull request Jul 13, 2026
[herd,cat] Fix some problems with the C architecture

This PR fixes two problems:

1. Since PR #1855, the polymorphic value `V.Empty`  circulates more. Some primitives were performing set and relation  normalisation by themselves, overlooking the cases of empty and universe. We fix this by using the already present and complete normalisation functions `as_set` and `as_rel` slightly generalised to handle different error reporting.
2. PR #1889 changed how the relation  `rmw` is computed  by defining it in stdlb.cat. The Cat definition of the relation `rmw` assumes that atomic effects are gathered in the set `X`, which was not the case of the C semantics. As a result the `rmw` relation was empty when the read-modify-write instructions are implemented by two (atomic) effects.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants