Skip to content

stage1: Implement @reduce builtin for vector types - #6558

Merged
andrewrk merged 1 commit into
ziglang:masterfrom
LemonBoy:simd-reduce
Oct 5, 2020
Merged

andrewrk merged 1 commit into
ziglang:masterfrom
LemonBoy:simd-reduce

Conversation

@LemonBoy

@LemonBoy LemonBoy commented Oct 4, 2020

Copy link
Copy Markdown
Contributor

The builtin folds a Vector(N,T) into a scalar T using a specified operator.

Closes #2698

The builtin folds a Vector(N,T) into a scalar T using a specified
operator.

Closes ziglang#2698
@alexnask alexnask added the stage1 The process of building from source via WebAssembly and the C backend. label Oct 4, 2020
@andrewrk

andrewrk commented Oct 5, 2020

Copy link
Copy Markdown
Member

My goodness, we just cannot catch a break with that windows CI

@andrewrk andrewrk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice progress! 1 nitpick and then this is good to land.

BTW why not work towards this in stage2? This is still useful progress because the changes to builtin.zig, behavior tests, and zig_llvm.{h,cpp} will persist, but I have a feeling you would enjoy the work more on stage2, and once we get far enough on that, the current plan is to delete the stage1 codebase (#6378).

Also I'm happy to do the nitpick myself in the merge process if you want, just say the word.

Comment thread lib/std/builtin.zig
Comment on lines +104 to +108
And,
Or,
Xor,
Min,
Max,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lower case tag names for new enums please. I normally don't want to care about style stuff but I also don't want to have to make unnecessary breaking changes later.

@LemonBoy

LemonBoy commented Oct 5, 2020

Copy link
Copy Markdown
Contributor Author

BTW why not work towards this in stage2?

Because I was playing with SIMD rather than with the compiler :^)
When the LLVM backend for stage2 is kickstarted I'll definitely move to the Zig side of the moon.

Also I'm happy to do the nitpick myself in the merge process if you want, just say the word.

Yeah go ahead, didn't know about the lowercase rule for enum members.

@andrewrk

andrewrk commented Oct 5, 2020

Copy link
Copy Markdown
Member

Oh, hmm. Gonna change my mind on this one. Capitalized enum tag names in this case works around the conflicts with the language keywords. 🤷

@andrewrk
andrewrk merged commit 22b5e47 into ziglang:master Oct 5, 2020
@andrewrk

andrewrk commented Oct 5, 2020

Copy link
Copy Markdown
Member

When the LLVM backend for stage2 is kickstarted I'll definitely move to the Zig side of the moon.

Alright well that's certainly motivating for me or someone else to get started on #6541 :-)

@data-man

Copy link
Copy Markdown
Contributor

@LemonBoy

llvm/IR/IRBuilder.h also has CreateAddReduce and CreateMulReduce
Can you implement .Add and .Mul, please?

@LemonBoy

Copy link
Copy Markdown
Contributor Author

Can you implement .Add and .Mul, please?

Sure, I didn't implement those because I wasn't sure about the names to use (nor I had any need for those ops).
Since the add/sub/mul provided by LLVM are wrapping I'd go for Wrapping{Add,Mul}.

@data-man

data-man commented Nov 1, 2020

Copy link
Copy Markdown
Contributor

@LemonBoy

Sure

Before 0.7.0 release? :)

But I thought about integer/float overflow for .Add and .Mul. :(
E.g. if a vector is float32 type, can @reduce return float64?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stage1 The process of building from source via WebAssembly and the C backend.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@reduce builtin

4 participants