Discussion
Loading...

Post

  • About
  • Code of conduct
  • Privacy
  • Users
  • Instances
  • About Bonfire
Karsten Schmidt
@toxi@mastodon.thi.ng  ·  activity timestamp 7 days ago

After almost a week of refactoring and experimenting with several different approaches, I've updated my Zig nD SIMD vector library to be compatible with the latest Zig 0.15.1, and at the same time cleaned up some internals.

The solution I settled on is a mix of techniques proposed by others, and was needed due to the removal of the struct/namespace-merging syntax in the new Zig version, which this library heavily relies on. I don't like that the new source code is now more than 2x larger and involves a huge amount of duplication to address the many special cases of supported operations for different vector sizes and types. I might still take another pass to eliminate those (by using @compileError() for unsupported cases), but that'd be an implementation detail downstream users don't have to care about. I tried AOT code generation as well, but the special case handling made this feel less maintainable...

UPDATE: The only breaking change is the handling of vector swizzles. I had to remove the hundreds of named swizzle functions and replaced them with a single (comptime optimized) .swizzle(vec, pattern), e.g. .swizzle(vec, "xxyy")...

If you're interested, the new code is here:
https://github.com/thi-ng/zig-thing/blob/main/src/vectors.zig

The readme contains details about the many supported operations:
https://github.com/thi-ng/zig-thing/blob/main/doc/vectors.md

Installation instructions in the main repo readme:
https://github.com/thi-ng/zig-thing/tree/main

#Zig#Ziglang#ZigThing#Vectors#Refactoring

  • Copy link
  • Flag this post
  • Block
Karsten Schmidt
@toxi@mastodon.thi.ng replied  ·  activity timestamp 7 days ago

Btw. It's amazing that this swizzle function gets compiled into single WASM i8x16.shuffle ops (per 4 vector components, i.e. swizzling into an 8-dimensional vector would require 2 shuffles):

https://github.com/thi-ng/zig-thing/blob/ab8566baf6f413abc29ca9ced222189bdb1f455e/src/vectors.zig#L1287-L1301

#Ziglang#WebAssembly#WASM

  • Copy link
  • Flag this comment
  • Block
Log in

bonfire.cafe

A space for Bonfire maintainers and contributors to communicate

bonfire.cafe: About · Code of conduct · Privacy · Users · Instances
Bonfire social · 1.0.0-rc.2.21 no JS en
Automatic federation enabled
  • Explore
  • About
  • Members
  • Code of Conduct
Home
Login