Skip to content

builtins: overflow arithmetic perf optimization #10854

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

Closed
wants to merge 2 commits into from

Conversation

matu3ba
Copy link
Contributor

@matu3ba matu3ba commented Feb 10, 2022

builtins: overflow arithmetic perf optimization

change signature of arithmetic operations @addwithOverflow,
@subWithOverflow, @mulWithOverflow, shlWithOverflow from
@operation(comptime T: type, a: T, b: T, result: *T) bool
to
@operation(comptime T: type, a: T, b: T) anytype
with anytype being a tuple
struct { res: T, ov: bool }

This removes the pointer store and load for efficiency of codegen.
Comptime operation is accordingly kept in sync.

closes #10248

Jan Philipp Hafer added 2 commits February 10, 2022 08:19
change signature of arithmetic operations @addwithOverflow,
@subWithOverflow, @mulWithOverflow, shlWithOverflow from
  @operation(comptime T: type, a: T, b: T, result: *T) bool
to
  @operation(comptime T: type, a: T, b: T) anytype
with anytype being a tuple
  struct { res: T, ov: bool }

This removes the pointer store and load for efficiency of codegen.
Comptime operation is accordingly kept in sync.

closes ziglang#10248
@matu3ba
Copy link
Contributor Author

matu3ba commented Feb 10, 2022

I am abit stuck at figuring out how to construct a composite type in Air for https://github.com/ziglang/zig/pull/10854/files#diff-23f8450a3403f774f20a81390ea9072846dc675ee17a679f715b26b22c86b591R8132, since the result should be a struct {res: T, ov:bool} as shown here https://github.com/matu3ba/zorro/blob/44a3ac0aa37bacb54623708ea3437462c2d20492/src/crt/addo_noptr.zig#L17.
- const ptr = sema.resolveInst(extra.ptr); needs to be removed, but I need to figure out how to generate the struct in Air.
It uses additional data besides what is in Zir and Ast.
For the builtins I found no "stuff that allocates further data", so a hint where to look would be nice.
Otherwise I will debug stage1 (and Sema) for aforementioned example, which should reveal how to do it.

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.

make overflow arithmetic builtins return a tuple instead of using a pointer parameter and bool return value
1 participant