modularml / mojo

The Mojo Programming Language
https://docs.modular.com/mojo/manual/
Other
23.13k stars 2.59k forks source link

[BUG]: simd integral `//` always returns zero with negative operand #1464

Closed helehex closed 5 months ago

helehex commented 10 months ago

Bug description

floor divide always return zero if any of the operands are negative

Steps to reproduce

fn main():
    let a: Scalar[DType.int64] = -4
    let b: Scalar[DType.int64] = -2

    print(a//b)  # prints 0
    print(a/b)   # prints 2
    # print(-4//b) # error, recursive call

System information

Host Information
  ================

  Target Triple: x86_64-unknown-linux
  CPU: skylake
  CPU Features: 64bit, adx, aes, avx, avx2, bmi, bmi2, clflushopt, cmov, crc32, cx16, cx8, f16c, fma, fsgsbase, fxsr, invpcid, lzcnt, mmx, movbe, pclmul, popcnt, prfchw, rdrnd, rdseed, rtm, sahf, sgx, sse, sse2, sse3, sse4.1, sse4.2, ssse3, x87, xsave, xsavec, xsaveopt, xsaves

mojo 0.6.0 (d55c0025)

modular 0.2.2 (95d42445)
JoeLoser commented 10 months ago

Thanks for filing the bug report. I confirmed the repro and it's indeed a bug. BTW, in the third example, the function (__floordiv__) actually got removed in v0.6.1 release (coming next week) due to the recursive call (someone else ran into this internally while doing something else). We'll fix that separately and revive that function.

bgreni commented 5 months ago

@JoeLoser Testing on mojo 2024.5.622 (d9dc4c21) and this appears to have been resolved

helehex commented 5 months ago

yup looks good to me

JoeLoser commented 5 months ago

Great, thanks for closing it! I haven't looked closely at this one specifically, but the community has been filling in a lot of missing methods and fixing them, so I'm sure this was one of them 🎉🎉🎉