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 support of CreateScalarUnsafe() for arm64 intrinsic in JIT #34579

Merged
merged 6 commits into from
Apr 27, 2020

Conversation

kunalspathak
Copy link
Member

@kunalspathak kunalspathak commented Apr 6, 2020

Add support for Vector64.CreateUnsafe() and Vector128.CreateUnsafe() inside JIT that maps to one of fmov, ins or movi/movni instruction.

  1. For float/double, if operand is immediate and can be encoded in fmov, use it. Else, use fmov on register.
  2. For byte/sbyte/short/ushort/int/uint/long/ulong, if operand is immediate and can be encoded in movi/movi, use it. Otherwise, load the value in register and use ins to save in 0th lane.

Thanks @echesakovMSFT for the suggestion in #34485 (comment)

static void Vector64Test(Single value1, Single value2)
{
	var data0 = Vector64.CreateScalarUnsafe((float)5.9f);
	Console.WriteLine(data0);
	var data1 = Vector64.CreateScalarUnsafe((float)2.0f);
	Console.WriteLine(data1);
	var data2 = Vector64.CreateScalarUnsafe(4353);
	Console.WriteLine(data2);	
	var data3 = Vector64.CreateScalarUnsafe(32);
	Console.WriteLine(data3);
}

Output:

<5.9, 0>
<2, 0>
<4353, 0>
<32, 32>
<1.0696732, 0>
<43, 0>
Assembly output
G_M707_IG02:
       D28AE400          movz    x0, #0x5720
       F2A70740          movk    x0, #0x383a LSL #16
       F2CFFFA0          movk    x0, #0x7ffd LSL #32
       97FF15C2          bl      CORINFO_HELP_NEWSFAST
       1C0005B0          ldr     s16, [@RWD00]
       FD000410          str     d16, [x0,#8]
       97FFADE3          bl      System.Console:WriteLine(System.Object)
       D28AE400          movz    x0, #0x5720
       F2A70740          movk    x0, #0x383a LSL #16
       F2CFFFA0          movk    x0, #0x7ffd LSL #32
       97FF15BB          bl      CORINFO_HELP_NEWSFAST
       1E201010          fmov    s16, #2.0000
       FD000410          str     d16, [x0,#8]
       97FFADDC          bl      System.Console:WriteLine(System.Object)
       D28BA800          movz    x0, #0x5d40
       F2A70740          movk    x0, #0x383a LSL #16
       F2CFFFA0          movk    x0, #0x7ffd LSL #32
       97FF15B4          bl      CORINFO_HELP_NEWSFAST
       52822021          mov     w1, #0x1101
       4E041C30          ins     v16.s[0], w1
       FD000410          str     d16, [x0,#8]
       97FFADD4          bl      System.Console:WriteLine(System.Object)
       D28BA800          movz    x0, #0x5d40
       F2A70740          movk    x0, #0x383a LSL #16
       F2CFFFA0          movk    x0, #0x7ffd LSL #32
       97FF15AC          bl      CORINFO_HELP_NEWSFAST
       0F010410          movi    v16.2s, #0x20
       FD000410          str     d16, [x0,#8]
       97FFADCD          bl      System.Console:WriteLine(System.Object)
       D28AE400          movz    x0, #0x5720
       F2A70740          movk    x0, #0x383a LSL #16
       F2CFFFA0          movk    x0, #0x7ffd LSL #32
       97FF15A5          bl      CORINFO_HELP_NEWSFAST
       BD401FA0          ldr     s0, [fp,#28]  // [V00 arg0]
       BD401BA1          ldr     s1, [fp,#24]  // [V01 arg1]
       1E212810          fadd    s16, s0, s1
       FD000410          str     d16, [x0,#8]
       97FFADC4          bl      System.Console:WriteLine(System.Object)
       D28BA800          movz    x0, #0x5d40
       F2A70740          movk    x0, #0x383a LSL #16
       F2CFFFA0          movk    x0, #0x7ffd LSL #32
       97FF159C          bl      CORINFO_HELP_NEWSFAST
       0B140261          add     w1, w19, w20
       4E041C30          ins     v16.s[0], w1
       FD000410          str     d16, [x0,#8]
       97FFADBC          bl      System.Console:WriteLine(System.Object)

RWD00  dd       40BCCCCDh
static void Vector128Test(double value1, double value2, long value3, long value4)
{
	var data0 = Vector128.CreateScalarUnsafe((float)5.9f);
	Console.WriteLine(data0);
	var data1 = Vector128.CreateScalarUnsafe((float)2.0f);
	Console.WriteLine(data1);
	var data2 = Vector128.CreateScalarUnsafe((long)4353);
	Console.WriteLine(data2);	
	var data3 = Vector128.CreateScalarUnsafe(32);
	Console.WriteLine(data3);
	var data4 = Vector128.CreateScalarUnsafe(value1 + value2);
	Console.WriteLine(data4);
	var data5 = Vector128.CreateScalarUnsafe(value3 + value4);
	Console.WriteLine(data5);
}

Output:

<5.9, 0, 0, 0>
<2, 0, 0, 0>
<4353, 0>
<32, 32, 32, 32>
<0.30312630808659924, 0>
<12884901882, 0>
Assembly output
G_M3610_IG02:
       D28C2E00          movz    x0, #0x6170
       F2A70720          movk    x0, #0x3839 LSL #16
       F2CFFFA0          movk    x0, #0x7ffd LSL #32
       97FF13D2          bl      CORINFO_HELP_NEWSFAST
       1C0005B0          ldr     s16, [@RWD00]
       3C808010          str     q16, [x0,#8]
       97FFAC09          bl      System.Console:WriteLine(System.Object)
       D28C2E00          movz    x0, #0x6170
       F2A70720          movk    x0, #0x3839 LSL #16
       F2CFFFA0          movk    x0, #0x7ffd LSL #32
       97FF13CB          bl      CORINFO_HELP_NEWSFAST
       1E201010          fmov    s16, #2.0000
       3C808010          str     q16, [x0,#8]
       97FFAC02          bl      System.Console:WriteLine(System.Object)
       D28CFD00          movz    x0, #0x67e8
       F2A70720          movk    x0, #0x3839 LSL #16
       F2CFFFA0          movk    x0, #0x7ffd LSL #32
       97FF13C4          bl      CORINFO_HELP_NEWSFAST
       D2822021          mov     x1, #0x1101
       4E081C30          ins     v16.d[0], x1
       3C808010          str     q16, [x0,#8]
       97FFABFA          bl      System.Console:WriteLine(System.Object)
       D28DCC00          movz    x0, #0x6e60
       F2A70720          movk    x0, #0x3839 LSL #16
       F2CFFFA0          movk    x0, #0x7ffd LSL #32
       97FF13BC          bl      CORINFO_HELP_NEWSFAST
       4F010410          movi    v16.4s, #0x20
       3C808010          str     q16, [x0,#8]
       97FFABF3          bl      System.Console:WriteLine(System.Object)
       D28E9B00          movz    x0, #0x74d8
       F2A70720          movk    x0, #0x3839 LSL #16
       F2CFFFA0          movk    x0, #0x7ffd LSL #32
       97FF13B5          bl      CORINFO_HELP_NEWSFAST
       FD400FA0          ldr     d0, [fp,#24]  // [V00 arg0]
       FD400BA1          ldr     d1, [fp,#16]  // [V01 arg1]
       1E612810          fadd    d16, d0, d1
       3C808010          str     q16, [x0,#8]
       97FFABEA          bl      System.Console:WriteLine(System.Object)
       D28CFD00          movz    x0, #0x67e8
       F2A70720          movk    x0, #0x3839 LSL #16
       F2CFFFA0          movk    x0, #0x7ffd LSL #32
       97FF13AC          bl      CORINFO_HELP_NEWSFAST
       8B140261          add     x1, x19, x20
       4E081C30          ins     v16.d[0], x1
       3C808010          str     q16, [x0,#8]
       97FFABE2          bl      System.Console:WriteLine(System.Object)

RWD00  dd       40BCCCCDh

Fixes: #34485
Contributes to #33308

@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Apr 6, 2020
@kunalspathak kunalspathak force-pushed the create-scalar-unsafe branch from 825f28f to ef15294 Compare April 25, 2020 05:32
@kunalspathak kunalspathak marked this pull request as ready for review April 25, 2020 06:16
@kunalspathak
Copy link
Member Author

kunalspathak commented Apr 25, 2020

/cc: @dotnet/jit-contrib , @tannergooding , @TamarChristinaArm

@kunalspathak kunalspathak force-pushed the create-scalar-unsafe branch from 5e41e37 to b55e6d4 Compare April 27, 2020 16:41
src/coreclr/src/jit/hwintrinsiccodegenarm64.cpp Outdated Show resolved Hide resolved
src/coreclr/src/jit/hwintrinsiccodegenarm64.cpp Outdated Show resolved Hide resolved
src/coreclr/src/jit/hwintrinsiclistarm64.h Outdated Show resolved Hide resolved
src/coreclr/src/jit/lowerarmarch.cpp Show resolved Hide resolved
Copy link
Contributor

@echesakov echesakov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (minus nit)

@kunalspathak
Copy link
Member Author

Failure related to #35502

@kunalspathak kunalspathak merged commit d68342c into dotnet:master Apr 27, 2020
@kunalspathak kunalspathak deleted the create-scalar-unsafe branch April 27, 2020 23:14
@ghost ghost locked as resolved and limited conversation to collaborators Dec 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add fmov arm64 intrinsic in JIT to implement Vector*.CreateScalarUnsafe API
3 participants