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

[X64] [xtqqczze] Reduce IL size for BitConverter.GetBytes #176

Open
MihuBot opened this issue Sep 7, 2023 · 2 comments
Open

[X64] [xtqqczze] Reduce IL size for BitConverter.GetBytes #176

MihuBot opened this issue Sep 7, 2023 · 2 comments

Comments

@MihuBot
Copy link
Owner

MihuBot commented Sep 7, 2023

Build completed in 1 hour 13 minutes.
dotnet/runtime#91639

CoreLib diffs

Found 2 files with textual diffs.

Summary of Code Size diffs:
(Lower is better)

Total bytes of base: 6605444
Total bytes of diff: 6605438
Total bytes of delta: -6 (-0.00 % of base)
Total relative delta: -0.13
    diff is an improvement.
    relative diff is an improvement.


Top file improvements (bytes):
          -6 : System.Private.CoreLib.dasm (-0.00 % of base)

1 total files with Code Size differences (1 improved, 0 regressed), 0 unchanged.

Top method improvements (bytes):
          -4 (-8.70 % of base) : System.Private.CoreLib.dasm - System.BitConverter:GetBytes(float):ubyte[] (FullOpts)
          -2 (-4.55 % of base) : System.Private.CoreLib.dasm - System.BitConverter:GetBytes(double):ubyte[] (FullOpts)

Top method improvements (percentages):
          -4 (-8.70 % of base) : System.Private.CoreLib.dasm - System.BitConverter:GetBytes(float):ubyte[] (FullOpts)
          -2 (-4.55 % of base) : System.Private.CoreLib.dasm - System.BitConverter:GetBytes(double):ubyte[] (FullOpts)

2 total methods with Code Size differences (2 improved, 0 regressed), 52947 unchanged.

--------------------------------------------------------------------------------

Frameworks diffs

Diffs
Found 260 files with textual diffs.

Summary of Code Size diffs:
(Lower is better)

Total bytes of base: 37857694
Total bytes of diff: 37857647
Total bytes of delta: -47 (-0.00 % of base)
Total relative delta: -0.57
    diff is an improvement.
    relative diff is an improvement.


Top file regressions (bytes):
          41 : System.Data.Common.dasm (0.00 % of base)

Top file improvements (bytes):
         -82 : Microsoft.VisualBasic.Core.dasm (-0.01 % of base)
          -6 : System.Private.CoreLib.dasm (-0.00 % of base)

3 total files with Code Size differences (2 improved, 1 regressed), 253 unchanged.

Top method regressions (bytes):
          41 (2.92 % of base) : System.Data.Common.dasm - System.Data.Common.ObjectStorage:Set(int,System.Object):this (FullOpts)

Top method improvements (bytes):
         -74 (-41.57 % of base) : Microsoft.VisualBasic.Core.dasm - Microsoft.VisualBasic.VBMath:Randomize(double) (FullOpts)
          -4 (-3.39 % of base) : Microsoft.VisualBasic.Core.dasm - Microsoft.VisualBasic.VBMath:Randomize() (FullOpts)
          -4 (-2.17 % of base) : Microsoft.VisualBasic.Core.dasm - Microsoft.VisualBasic.VBMath:Rnd(float):float (FullOpts)
          -4 (-8.70 % of base) : System.Private.CoreLib.dasm - System.BitConverter:GetBytes(float):ubyte[] (FullOpts)
          -2 (-4.55 % of base) : System.Private.CoreLib.dasm - System.BitConverter:GetBytes(double):ubyte[] (FullOpts)

Top method regressions (percentages):
          41 (2.92 % of base) : System.Data.Common.dasm - System.Data.Common.ObjectStorage:Set(int,System.Object):this (FullOpts)

Top method improvements (percentages):
         -74 (-41.57 % of base) : Microsoft.VisualBasic.Core.dasm - Microsoft.VisualBasic.VBMath:Randomize(double) (FullOpts)
          -4 (-8.70 % of base) : System.Private.CoreLib.dasm - System.BitConverter:GetBytes(float):ubyte[] (FullOpts)
          -2 (-4.55 % of base) : System.Private.CoreLib.dasm - System.BitConverter:GetBytes(double):ubyte[] (FullOpts)
          -4 (-3.39 % of base) : Microsoft.VisualBasic.Core.dasm - Microsoft.VisualBasic.VBMath:Randomize() (FullOpts)
          -4 (-2.17 % of base) : Microsoft.VisualBasic.Core.dasm - Microsoft.VisualBasic.VBMath:Rnd(float):float (FullOpts)

6 total methods with Code Size differences (5 improved, 1 regressed), 232296 unchanged.

--------------------------------------------------------------------------------

Artifacts:

@MihuBot
Copy link
Owner Author

MihuBot commented Sep 7, 2023

Top method improvements

-4 (-8.70 % of base) - System.BitConverter:GetBytes(float):ubyte[]
 ; Assembly listing for method System.BitConverter:GetBytes(float):ubyte[] (FullOpts)
 ; Emitting BLENDED_CODE for X64 with AVX - Unix
 ; FullOpts code
 ; optimized code
 ; rsp based frame
 ; partially interruptible
 ; No PGO data
+; 0 inlinees with PGO data; 1 single block inlinees; 0 inlinees without PGO data
 ; Final local variable assignments
 ;
 ;  V00 arg0         [V00,T01] (  3,  3   )   float  ->  [rsp+0x04]  single-def
-;  V01 loc0         [V01,T00] (  3,  3   )     ref  ->  rax         class-hnd exact single-def <ubyte[]>
-;# V02 OutArgs      [V02    ] (  1,  1   )  struct ( 0) [rsp+0x00]  do-not-enreg[XS] addr-exposed "OutgoingArgSpace"
+;# V01 OutArgs      [V01    ] (  1,  1   )  struct ( 0) [rsp+0x00]  do-not-enreg[XS] addr-exposed "OutgoingArgSpace"
+;* V02 tmp1         [V02    ] (  0,  0   )     ref  ->  zero-ref    class-hnd exact "Inline return value spill temp" <ubyte[]>
+;  V03 tmp2         [V03,T00] (  3,  3   )     ref  ->  rax         class-hnd exact single-def "Inline stloc first use temp" <ubyte[]>
+;* V04 tmp3         [V04    ] (  0,  0   )     int  ->  zero-ref    "Inlining Arg"
 ;
 ; Lcl frame size = 8
 
 G_M32905_IG01:
        push     rax
        vzeroupper 
        vmovss   dword ptr [rsp+0x04], xmm0
 						;; size=10 bbWeight=1 PerfScore 3.00
 G_M32905_IG02:
        mov      rdi, 0xD1FFAB1E      ; ubyte[]
        mov      esi, 4
        call     CORINFO_HELP_NEWARR_1_VC
-       vmovss   xmm0, dword ptr [rsp+0x04]
-       vmovss   dword ptr [rax+0x10], xmm0
-						;; size=31 bbWeight=1 PerfScore 6.50
+       mov      ecx, dword ptr [rsp+0x04]
+       mov      dword ptr [rax+0x10], ecx
+						;; size=27 bbWeight=1 PerfScore 3.50
 G_M32905_IG03:
        add      rsp, 8
        ret      
 						;; size=5 bbWeight=1 PerfScore 1.25
 
-; Total bytes of code 46, prolog size 4, PerfScore 15.35, instruction count 10, allocated bytes for code 46 (MethodHash=41997f76) for method System.BitConverter:GetBytes(float):ubyte[] (FullOpts)
+; Total bytes of code 42, prolog size 4, PerfScore 11.95, instruction count 10, allocated bytes for code 42 (MethodHash=41997f76) for method System.BitConverter:GetBytes(float):ubyte[] (FullOpts)
-2 (-4.55 % of base) - System.BitConverter:GetBytes(double):ubyte[]
 ; Assembly listing for method System.BitConverter:GetBytes(double):ubyte[] (FullOpts)
 ; Emitting BLENDED_CODE for X64 with AVX - Unix
 ; FullOpts code
 ; optimized code
 ; rsp based frame
 ; partially interruptible
 ; No PGO data
+; 0 inlinees with PGO data; 1 single block inlinees; 0 inlinees without PGO data
 ; Final local variable assignments
 ;
 ;  V00 arg0         [V00,T01] (  3,  3   )  double  ->  [rsp+0x00]  single-def
-;  V01 loc0         [V01,T00] (  3,  3   )     ref  ->  rax         class-hnd exact single-def <ubyte[]>
-;# V02 OutArgs      [V02    ] (  1,  1   )  struct ( 0) [rsp+0x00]  do-not-enreg[XS] addr-exposed "OutgoingArgSpace"
+;# V01 OutArgs      [V01    ] (  1,  1   )  struct ( 0) [rsp+0x00]  do-not-enreg[XS] addr-exposed "OutgoingArgSpace"
+;* V02 tmp1         [V02    ] (  0,  0   )     ref  ->  zero-ref    class-hnd exact "Inline return value spill temp" <ubyte[]>
+;  V03 tmp2         [V03,T00] (  3,  3   )     ref  ->  rax         class-hnd exact single-def "Inline stloc first use temp" <ubyte[]>
+;* V04 tmp3         [V04    ] (  0,  0   )    long  ->  zero-ref    "Inlining Arg"
 ;
 ; Lcl frame size = 8
 
 G_M20108_IG01:
        push     rax
        vzeroupper 
        vmovsd   qword ptr [rsp], xmm0
 						;; size=9 bbWeight=1 PerfScore 3.00
 G_M20108_IG02:
        mov      rdi, 0xD1FFAB1E      ; ubyte[]
        mov      esi, 8
        call     CORINFO_HELP_NEWARR_1_VC
-       vmovsd   xmm0, qword ptr [rsp]
-       vmovsd   qword ptr [rax+0x10], xmm0
-						;; size=30 bbWeight=1 PerfScore 6.50
+       mov      rcx, qword ptr [rsp]
+       mov      qword ptr [rax+0x10], rcx
+						;; size=28 bbWeight=1 PerfScore 3.50
 G_M20108_IG03:
        add      rsp, 8
        ret      
 						;; size=5 bbWeight=1 PerfScore 1.25
 
-; Total bytes of code 44, prolog size 4, PerfScore 15.15, instruction count 10, allocated bytes for code 44 (MethodHash=02c0b173) for method System.BitConverter:GetBytes(double):ubyte[] (FullOpts)
+; Total bytes of code 42, prolog size 4, PerfScore 11.95, instruction count 10, allocated bytes for code 42 (MethodHash=02c0b173) for method System.BitConverter:GetBytes(double):ubyte[] (FullOpts)

@MihuBot
Copy link
Owner Author

MihuBot commented Sep 7, 2023

@MihaZupan

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