Created
June 11, 2024 12:29
-
-
Save Validark/05420622fdf08bfb68083dff46d41725 to your computer and use it in GitHub Desktop.
`cls` on Arm
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
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