Skip to content

Instantly share code, notes, and snippets.

@Validark
Created June 11, 2024 12:29
Show Gist options
  • Save Validark/05420622fdf08bfb68083dff46d41725 to your computer and use it in GitHub Desktop.
Save Validark/05420622fdf08bfb68083dff46d41725 to your computer and use it in GitHub Desktop.
`cls` on Arm
export fn cls(e: u64) @TypeOf(e) {
const e2: @TypeOf(e) = @bitCast(@as(std.meta.Int(.signed, @bitSizeOf(@TypeOf(e))), @bitCast(e)) >> (@bitSizeOf(@TypeOf(e)) - 1));
return @clz(((e ^ e2) << 1) | 1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment