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

Consider adding HalfToInt16Bits and Int16BitsToHalf to BitConverter #38288

Closed
Tracked by #63902
pgovind opened this issue Jun 23, 2020 · 8 comments · Fixed by #40882
Closed
Tracked by #63902

Consider adding HalfToInt16Bits and Int16BitsToHalf to BitConverter #38288

pgovind opened this issue Jun 23, 2020 · 8 comments · Fixed by #40882
Labels
api-approved API was approved in API review, it can be implemented area-System.Numerics
Milestone

Comments

@pgovind
Copy link

pgovind commented Jun 23, 2020

#37630 adds HalfToInt16Bits and Int16BitsToHalf as internal methods to BitConverter. We should consider exposing them as public.

Proposed API

        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        internal static unsafe short HalfToInt16Bits(Half value);

        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        internal static unsafe Half Int16BitsToHalf(short value);

cc: @tannergooding

@pgovind pgovind added the api-suggestion Early API idea and discussion, it is NOT ready for implementation label Jun 23, 2020
@Dotnet-GitSync-Bot
Copy link
Collaborator

I couldn't figure out the best area label to add to this issue. Please help me learn by adding exactly one area label.

@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added the untriaged New issue has not been triaged by the area owner label Jun 23, 2020
@tannergooding tannergooding added api-ready-for-review area-System.Numerics and removed api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.Runtime untriaged New issue has not been triaged by the area owner labels Jun 23, 2020
@ghost
Copy link

ghost commented Jun 23, 2020

Tagging subscribers to this area: @tannergooding
Notify danmosemsft if you want to be subscribed.

@tannergooding tannergooding added this to the Future milestone Jun 23, 2020
@tannergooding
Copy link
Member

This isn't critical for .NET 5 so marking as future. This just provides parity with the equivalents exposed for Single/Double.

@eiriktsarpalis
Copy link
Member

For CBOR requirements we'd probably also need to add the following methods to the BinaryPrimitives class:

public static class BinaryPrimitives
{
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static Half ReadHalfLittleEndian(ReadOnlySpan<byte> source);
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static Half ReadHalfBigEndian(ReadOnlySpan<byte> source);
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static bool TryReadHalfLittleEndian(ReadOnlySpan<byte> source, out Half);
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static bool TryReadHalfBigEndian(ReadOnlySpan<byte> source, out Half);

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static void WriteHalfLittleEndian(Span<byte> destination, Half value);
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static void WriteHalfBigEndian(Span<byte> destination, Half value);
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static bool TryWriteHalfLittleEndian(Span<byte> destination, Half value);
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static bool TryWriteHalfBigEndian(Span<byte> destination, Half value);
}

I feel that we could include these to the existing API proposal. If not I can file a separate issue.

@tannergooding
Copy link
Member

Given its a separate class, it would likely be good to have in a separate API proposal.

The CBOR implementation wouldn't be blocked on these APIs being public, correct? That is, it can be implemented as an internal API until API review can happen, correct?

@eiriktsarpalis
Copy link
Member

That is, it can be implemented as an internal API until API review can happen, correct?

That's correct

@carlossanlop carlossanlop added api-ready-for-review API is ready for review, it is NOT ready for implementation and removed api-ready-for-review labels Jul 6, 2020
@terrajobst terrajobst modified the milestones: Future, 5.0.0 Jul 23, 2020
@terrajobst terrajobst added api-approved API was approved in API review, it can be implemented and removed api-ready-for-review API is ready for review, it is NOT ready for implementation labels Jul 24, 2020
@terrajobst
Copy link
Member

terrajobst commented Jul 24, 2020

Video

Looks good

namespace System
{
    public sealed class BitConverter
    {
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static short HalfToInt16Bits(Half value);

        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static Half Int16BitsToHalf(short value);
    }
}

@tannergooding tannergooding modified the milestones: 5.0.0, Future Jul 24, 2020
@huoyaoyuan
Copy link
Member

For consistency, there are 4 more overloads for Half can be added:

public static Half ToHalf(byte[] value, int startIndex);
public static Half ToHalf(ReadOnlySpan<byte> value);
public static byte[] GetBytes(Half value);
public static bool TryWriteBytes(Span<byte> destination, Half value);

Do I need to create a new API proposal because this one is already approved?

@ghost ghost locked as resolved and limited conversation to collaborators Dec 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api-approved API was approved in API review, it can be implemented area-System.Numerics
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants