Skip to content

minimum/maximum builtins #9448

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

Merged
merged 1 commit into from
Jul 27, 2021
Merged

minimum/maximum builtins #9448

merged 1 commit into from
Jul 27, 2021

Conversation

Snektron
Copy link
Collaborator

This pull request adds @minimum and @maximum builtin functions. The main use case for these is SIMD (See #903), though they work on scalars as well.

For floats, this uses the llvm.maxnum and llvm.minnum intrinsics. Note that x86_64 vminps and vmaxps have different semantics, and so these generate some extra instructions:

c5 f0 5d d0              vminps xmm2,xmm1,xmm0
c5 f8 c2 c0 03           vcmpunordps xmm0,xmm0,xmm0
c4 e3 69 4a c1 00        vblendvps xmm0,xmm2,xmm1,xmm0
c3  

On other architectures (riscv and arm) this shouldn't be a problem.

@Snektron
Copy link
Collaborator Author

Oh, and i also made sure to implement the float semantics in comptime: if either argument is nan, the other is returned.

@Snektron
Copy link
Collaborator Author

CI errors seem unrelated

static void float_negate(ZigValue *out_val, ZigValue *op) {
out_val->type = op->type;
if (op->type->id == ZigTypeIdComptimeFloat) {
bigfloat_negate(&out_val->data.x_bigfloat, &op->data.x_bigfloat);
} else if (op->type->id == ZigTypeIdFloat) {
switch (op->type->data.floating.bit_count) {
case 16:
out_val->data.x_f16 = f16_neg(op->data.x_f16);
Copy link
Contributor

Choose a reason for hiding this comment

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

why was this line removed?

Copy link
Collaborator Author

@Snektron Snektron Jul 25, 2021

Choose a reason for hiding this comment

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

That must have been an accident. Thanks for the find :)

@Snektron Snektron force-pushed the minimum-maximum branch 3 times, most recently from 56ea0ed to bc057c0 Compare July 26, 2021 00:50
@andrewrk andrewrk merged commit cdeea3b into ziglang:master Jul 27, 2021
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