News for hackers. Stuff that matters.
Re:Why SciPy builds for Python 3.12 on Windows are a minor m... by Sohcahtoa82 on Wednesday November 08, 2023 @06:16PM (#38198643)
> Because there are no pointers in Fortran, only arrays, and because arguments to functions aren't allowed to alias [...], aggressive optimization and vectorization is easier.

Can you explain this like I'm 12?

What's an example of an aggressive optimization you can make based on arguments not being aliased and there being no pointers?

Re:Why SciPy builds for Python 3.12 on Windows are a minor m... by superlopuh on Wednesday November 08, 2023 @06:40PM (#38198868)
Re:Why SciPy builds for Python 3.12 on Windows are a minor m... by Falell on Wednesday November 08, 2023 @06:28PM (#38198760)
Not a direct compiler optimization, but consider memcpy() vs memmove() as an example. If you know two regions of memory do not overlap you can call memcpy() for a direct optimized copy, but if they overlap you must call memmove() and introduce an intermediate copy.
Re:Why SciPy builds for Python 3.12 on Windows are a minor m... by Sohcahtoa82 on Wednesday November 08, 2023 @07:20PM (#38199228)
It makes sense, but when would you ever memcpy with overlap? I would think any situation that lets that happen is from a bug, like you have an incorrect buffer length or an incorrect destination address.
Re:Why SciPy builds for Python 3.12 on Windows are a minor m... by murderfs on Wednesday November 08, 2023 @07:47PM (#38199413)
Inserting an element in an array is something along the lines of memmove(arr + idx + 1, arr + idx, (length - idx) * sizeof(*arr)); arr[idx] = foo;
Re:Why SciPy builds for Python 3.12 on Windows are a minor m... by johncolanduoni on Thursday November 09, 2023 @07:13AM (#38204013)
memmove does not (in any implementation I’ve ever heard of) introduce an intermediate copy, it just performs the copy loop in the reverse direction to handle the overlap (and can’t always vectorize in the same way memcpy can).
Re:Why SciPy builds for Python 3.12 on Windows are a minor m... by hurryer on Wednesday November 08, 2023 @06:49PM (#38198936)

  int *x;
  int *y;
  // ...
  *x = 5;
Because of aliasing, x and y might point to the same memory location, so the compiler must assume that when you modified x to 5, y also potentially got modifed, so at next access it will read y again from memory and discard any cached value in a register it might have.

The compiler will try proving that no such aliasing is present, by tracking your pointer usage, but it's not always possible, in those cases it will assume the worse and re-read values from memory.

Re:Why SciPy builds for Python 3.12 on Windows are a minor m... by Sohcahtoa82 on Wednesday November 08, 2023 @07:18PM (#38199208)
Ah that makes sense. Thank you!
Re:Why SciPy builds for Python 3.12 on Windows are a minor m... by wycy on Wednesday November 08, 2023 @09:38PM (#38200393)
I finally understand—-thanks for this example.