Last active
July 13, 2025 16:05
-
-
Save vaguinerg/2a8057a184509590e31416773eca0675 to your computer and use it in GitHub Desktop.
Nim-lang GCC Auto vectorization (SIMD)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import random, raylib | |
| randomize() | |
| type | |
| Unit = object | |
| pos: Vector2 | |
| hp: int | |
| let size = rand(5..22) | |
| var units = newSeq[Unit](size) | |
| proc moveUnits(seq: var openArray[Unit], offset: Vector2) = | |
| for i in 0..<seq.len: | |
| seq[i].pos.x += offset.x | |
| seq[i].pos.y += offset.y | |
| let randomOffset = Vector2(x: rand(-3.0..3.0), y: rand(-3.0..3.0)) | |
| moveUnits(units, randomOffset) | |
| echo "Final positions:" | |
| for u in units: | |
| echo u.pos | |
| #@mOptmizable.nim.c:107:8: optimized: loop vectorized using 32 byte vectors |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import random, sequtils | |
| randomize() | |
| let size = rand(5..15) | |
| var numbers = newSeq[int](size) | |
| proc increment(seq: var openArray[int]) = | |
| for i in 0..<seq.len: | |
| seq[i] = seq[i] + 1 | |
| increment(numbers) | |
| echo "Final: ", numbers | |
| #@mOptmizable.nim.c:81:8: optimized: loop vectorized using 32 byte vectors | |
| #nim c -r -d:danger --verbosity:3 --passC:"-fopt-info-vec-optimized -march=native" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import random | |
| randomize() | |
| let size = rand(5..18) | |
| var numbers = newSeq[int](size) | |
| proc increment(seq: var openArray[int]) = | |
| for x in mitems(seq): | |
| x += 2 | |
| increment(numbers) | |
| echo "Final: ", numbers | |
| #@mOptmizable.nim.c:78:8: optimized: loop vectorized using 32 byte vectors | |
| #nim c -r -d:danger --verbosity:3 --passC:"-fopt-info-vec-optimized -march=native" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import random, raylib | |
| randomize() | |
| type | |
| Unit = ref object | |
| pos: Vector2 | |
| hp: int | |
| let size = rand(5..22) | |
| var units = newSeq[Unit](size) | |
| for i in 0..<size: | |
| units[i] = Unit(pos: Vector2(x: 0.0, y: 0.0), hp: 100) | |
| proc moveUnits(seq: var openArray[Unit], offset: Vector2) = | |
| for i in 0..<seq.len: | |
| seq[i].pos.x += offset.x | |
| seq[i].pos.y += offset.y | |
| let randomOffset = Vector2(x: rand(-3.0..3.0), y: rand(-3.0..3.0)) | |
| moveUnits(units, randomOffset) | |
| echo "Final positions:" | |
| for u in units: | |
| echo u.pos | |
| #@mOpt.nim.c:178:34: missed: not vectorized: no vectype for stmt: _5 = *_4; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import random | |
| randomize() | |
| let size = rand(5..19) | |
| var numbers = newSeq[int](size) | |
| for x in mitems(numbers.toOpenArray(0, numbers.high)): | |
| x = x + 1 | |
| echo "Final: ", numbers | |
| #@mOptmizable.nim.c:149:8: missed: not vectorized: number of iterations cannot be computed. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import random, sequtils | |
| randomize() | |
| let size = rand(5..15) | |
| var numbers = newSeq[int](size) | |
| for i in 0..<numbers.len: | |
| numbers[i] = numbers[i] + 1 | |
| echo "Final: ", numbers | |
| #nim c -r -d:danger --verbosity:3 --passC:"-fopt-info-vec-optimized -march=native" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment