Turn `compareByteArrays#` out-of-line primop into inline primop
ClosedPublic

Authored by hvr on Oct 14 2017, 1:31 PM.

Diff Detail

Repository
rGHC Glasgow Haskell Compiler
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
hvr created this revision.Oct 14 2017, 1:31 PM
hvr planned changes to this revision.Oct 16 2017, 4:53 AM

there's a minor bug in the codegen not properly sign-extending the result from 32bit -> 64bit

hvr updated this revision to Diff 14347.Oct 16 2017, 5:53 AM
  • Perform proper sign-extension of memcmp result to machine-words.
bgamari accepted this revision.Oct 16 2017, 11:32 AM

This looks fine to me.

This revision is now accepted and ready to land.Oct 16 2017, 11:32 AM

However, something isn't quite right here,

=====> compareByteArrays(g1) 1 of 12 [0, 1, 0]
cd "./codeGen/should_run/compareByteArrays.run" &&  "/mnt/work/ghc/ghc-testing/inplace/test   spaces/ghc-stage2" -o compareByteArrays compareByteArrays.hs -dcore-lint -dcmm-lint -no-user-package-db -rtsopts -fno-warn-missed-specialisations -fshow-warning-groups -fdiagnostics-color=never -fno-diagnostics-show-caret -dno-debug-output  
Compile failed (exit code 1) errors were:
[1 of 1] Compiling Main             ( compareByteArrays.hs, compareByteArrays.o )
Cmm lint error:
  in basic block c4U0
    in MachOp application: 
      %MO_SS_Conv_W32_W64(_c4TQ::I64)
    op is expecting:  [W32]
    arguments provide:  [I64]
Program was:
  {offset
    c4TD: // global
        _s4E3::P64 = R1;
        if ((old + 0) - <highSp> < SpLim) (likely: False) goto c4U4; else goto c4U5;
    c4U4: // global
        R1 = _s4E3::P64;
        call (stg_gc_enter_1)(R1) args: 8, res: 0, upd: 8;
    c4U5: // global
        I64[(old + 24)] = stg_upd_frame_info;
        P64[(old + 16)] = _s4E3::P64;
        _s4DJ::P64 = P64[_s4E3::P64 + 16];
        _s4DK::P64 = P64[_s4E3::P64 + 24];
        _s4DL::P64 = P64[_s4E3::P64 + 32];
        I64[(young<c4TA> + 8)] = c4TA;
        R1 = _s4DJ::P64;
        if (R1 & 7 != 0) goto c4TA; else goto c4TB;
    c4TB: // global
        call (I64[R1])(R1) returns to c4TA, args: 8, res: 8, upd: 24;
    c4TA: // global
        _s4DW::P64 = R1;
        _s4DX::P64 = P64[_s4DW::P64 + 7];
        I64[(young<c4TG> + 8)] = c4TG;
        R1 = _s4DK::P64;
        if (R1 & 7 != 0) goto c4TG; else goto c4TH;
    c4TH: // global
        call (I64[R1])(R1) returns to c4TG, args: 8, res: 8, upd: 24;
    c4TG: // global
        _s4DY::P64 = R1;
        _s4DZ::P64 = P64[_s4DY::P64 + 7];
        I64[(young<c4TL> + 8)] = c4TL;
        R1 = _s4DL::P64;
        if (R1 & 7 != 0) goto c4TL; else goto c4TM;
    c4TM: // global
        call (I64[R1])(R1) returns to c4TL, args: 8, res: 8, upd: 24;
    c4TL: // global
        _s4E0::P64 = R1;
        Hp = Hp + 16;
        if (Hp > HpLim) (likely: False) goto c4U1; else goto c4U0;
    c4U1: // global
        HpAlloc = 16;
        R1 = _s4E0::P64;
        call stg_gc_unpt_r1(R1) returns to c4TL, args: 8, res: 8, upd: 24;
    c4U0: // global
        _s4E1::I64 = I64[_s4E0::P64 + 7];
        _c4TR::P64 = _s4DX::P64 + 16;
        _c4TS::P64 = _s4DZ::P64 + 16;
        _c4TT::P64 = _c4TR::P64;
        _c4TU::P64 = _c4TS::P64;
        _c4TV::I64 = _s4E1::I64;
        (_c4TQ::I64) = call MO_Memcmp 1(_c4TT::P64, _c4TU::P64, _c4TV::I64);
        _c4TQ::I64 = %MO_SS_Conv_W32_W64(_c4TQ::I64);
        _s4E2::I64 = _c4TQ::I64;
        I64[Hp - 8] = I#_con_info;
        I64[Hp] = _s4E2::I64;
        _c4TY::P64 = Hp - 7;
        R1 = _c4TY::P64;
        call (P64[(old + 24)])(R1) args: 24, res: 0, upd: 24;
  }

<no location info>: error: 
Compilation had errors
hvr planned changes to this revision.Oct 19 2017, 4:51 PM

Oh well, so the cmm linter doesn't like my hack... gonna have to workaround differently :-/

alexbiehl updated this revision to Diff 14475.Oct 26 2017, 1:16 AM
  • Implement inline compareByteArrays
  • Use temporary register for extension
This revision is now accepted and ready to land.Oct 26 2017, 1:16 AM
This revision was automatically updated to reflect the committed changes.