Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bit operations #4

Open
dzmitry-lahoda opened this issue Apr 27, 2019 · 1 comment
Open

Add bit operations #4

dzmitry-lahoda opened this issue Apr 27, 2019 · 1 comment

Comments

@dzmitry-lahoda
Copy link

dzmitry-lahoda commented Apr 27, 2019

.NET Core 3.0 got BitOperations

https://github.com/dotnet/corefx/blob/release/3.0/src/Common/src/CoreLib/System/Numerics/BitOperations.cs

Please add these into this lib for 128 bit number.

I can add these ops if you will five me right for repo.

I work on https://github.com/dzmitry-lahoda/NetStack/blob/master/Assets/Scripts/src/NetStack.Serialization/Coder.cs and need 91 bit number in one case (128 seems will be ok).

@dzmitry-lahoda
Copy link
Author

Here are some

        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        private static u128 WriteBit(u128 value, int bitOffset, bool on)
        {
            u128 onn = on ? u128.One << bitOffset : 0;
            return (value & ~(u128.One << bitOffset)) | onn;
        }

                [MethodImpl(MethodImplOptions.AggressiveInlining)]
        private static bool ExtractBit(u128 value, int bitOffset)
            => (value & (u128.One << bitOffset)) != 0;

I guess these are not optimal. I could add https://github.com/dotnet/BenchmarkDotNet then XUnit. And optimzia perf of this if you will give me rights onto the repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant