Bug 227202

Summary: Add ARM64 BIC, ORN, BFXIL to AIR opcode and select them in AIR
Product: WebKit Reporter: Yijia Huang <yijia_huang>
Component: JavaScriptCoreAssignee: Yijia Huang <yijia_huang>
Status: RESOLVED FIXED    
Severity: Normal CC: ews-watchlist, fpizlo, keith_miller, mark.lam, msaboff, saam, tzagallo, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch
ews-feeder: commit-queue-
Patch
none
Patch
none
Patch
none
Patch
none
Patch none

Yijia Huang
Reported 2021-06-20 21:52:48 PDT
...
Attachments
Patch (15.14 KB, patch)
2021-06-24 23:05 PDT, Yijia Huang
no flags
Patch (16.84 KB, patch)
2021-06-25 09:13 PDT, Yijia Huang
no flags
Patch (14.21 KB, patch)
2021-06-25 12:48 PDT, Yijia Huang
no flags
Patch (14.21 KB, patch)
2021-06-25 16:23 PDT, Yijia Huang
no flags
Patch (34.93 KB, patch)
2021-06-26 14:49 PDT, Yijia Huang
no flags
Patch (42.09 KB, patch)
2021-06-26 22:03 PDT, Yijia Huang
ews-feeder: commit-queue-
Patch (42.07 KB, patch)
2021-06-26 22:14 PDT, Yijia Huang
no flags
Patch (44.51 KB, patch)
2021-06-27 14:16 PDT, Yijia Huang
no flags
Patch (64.53 KB, patch)
2021-06-28 01:23 PDT, Yijia Huang
no flags
Patch (64.53 KB, patch)
2021-06-28 01:39 PDT, Yijia Huang
no flags
Patch (63.33 KB, patch)
2021-06-28 19:06 PDT, Yijia Huang
no flags
Yijia Huang
Comment 1 2021-06-24 23:05:31 PDT
Yijia Huang
Comment 2 2021-06-25 09:13:49 PDT
Saam Barati
Comment 3 2021-06-25 10:06:04 PDT
Comment on attachment 432278 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=432278&action=review > Source/JavaScriptCore/ChangeLog:59 > + Before Adding BFI: > + // Old optimized AIR > + Move $1, %x2, @3 > + Lshift %x2, %x1, %x1, @5 > + Not %x1, %x1, @6 > + And %x0, %x1, %x0, @7 > + Ret %x0, @8 > + > + After Adding BFI: > + // New optimized AIR > + ClearBit %x1, %x0, %x2, @7 > + Ret %x0, @8 Nice > Source/JavaScriptCore/assembler/MacroAssemblerARM64.h:503 > + void clearBit64(RegisterID bitToClear, RegisterID dest, RegisterID scratchForMask = InvalidGPRReg) > + { > + if (scratchForMask == InvalidGPRReg) > + scratchForMask = scratchRegister(); > + > + move(TrustedImm32(1), scratchForMask); > + lshift64(bitToClear, scratchForMask); > + clearBits64WithMask(scratchForMask, dest); This is an interesting question for Phil. I wonder if it's worth sucking up the lshift as part of this instruction, instead of emitting it directly in Air IR, and just adding a "clearBits32/64WithMask" in Air > Source/JavaScriptCore/assembler/testmasm.cpp:920 > + constexpr unsigned bitsInWord = sizeof(uint32_t) * 8; nit: 8 => CHAR_BIT > Source/JavaScriptCore/b3/air/AirOpcode.opcodes:384 > +arm64: ClearBit32 U:G:32, UZD:G:32, U:G:32 the last register here should be "scratch", so, "S:G:32" > Source/JavaScriptCore/b3/air/AirOpcode.opcodes:387 > +arm64: ClearBit64 U:G:32, UD:G:64, U:G:64 ditto
Yijia Huang
Comment 4 2021-06-25 12:48:55 PDT
Yijia Huang
Comment 5 2021-06-25 16:23:26 PDT
Yijia Huang
Comment 6 2021-06-26 14:49:27 PDT
Yijia Huang
Comment 7 2021-06-26 22:03:23 PDT
Yijia Huang
Comment 8 2021-06-26 22:14:33 PDT
Yijia Huang
Comment 9 2021-06-27 14:16:31 PDT
Yijia Huang
Comment 10 2021-06-28 01:23:11 PDT
Yijia Huang
Comment 11 2021-06-28 01:39:01 PDT
Filip Pizlo
Comment 12 2021-06-28 17:36:12 PDT
Comment on attachment 432371 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=432371&action=review Didn't you previously make (n >> a) & b the canonical form for extracting a bitfield? It's probably worth saying the following though I'm sure you've started to figure it out: Canonical forms are like pseudoinstructions. Just as phases may look for instructions, they may look for patterns of instructions, or instructions with something special about them (like that some operand is a constant). Also, anytime we can express some logic in B3 IR using existing instructions, then rather than adding a new instruction, we pick a canonical form of existing ones. Like BitNot - there is no BitNot opcode. When designing canonical forms, we often have many alternative possible ways of expressing this "pseudoinstruction". So which one do we pick? There are two things that happen to instructions or instruction patterns: 1. There's a bunch of code to create them. 2. There's a bunch of code to pattern-match them. If someone wants to write a phase that as part of a transformation needs to introduce a bitfield extract, then they will want to emit it using canonical form. If someone wants to pattern-match the bitfield extract, then they will pattern-match the canonical form. Therefore: we should always pick the canonical form that requires the least amount of code for case (1) and (2), with a preference for less code in (2). Hence why I think that (n >> a) & b is the natural choice. Your instruction selection code illustraces this. To check if (n & a) >> b is a bitfield extract, you have to count trailing zeroes, then shift down, then check if it's a mask. But with (n >> a) & b, you just have to check that a is a mask. > Source/JavaScriptCore/ChangeLog:36 > + Turn this: -value - 1 > + Into this: value ^ -1 This is great. I can't believe we didn't have this rule already. Indeed, the canonical form of the BitNot(@x) operation in B3 IR is BitXor(@x, -1). So, your patch just reinforces this existing rule. > Source/JavaScriptCore/b3/B3LowerToAir.cpp:2851 > + // BFXIL Pattern: d = ((n & mask1) >> lsb) | (d & mask2) I would have made this be (n >> lsb) & mask1 > Source/JavaScriptCore/b3/B3LowerToAir.cpp:3022 > + // UBFX Pattern: d = (n & mask) >> lsb Ditto.
Radar WebKit Bug Importer
Comment 13 2021-06-28 17:36:25 PDT
Yijia Huang
Comment 14 2021-06-28 19:06:48 PDT
Filip Pizlo
Comment 15 2021-06-28 20:21:31 PDT
Comment on attachment 432447 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=432447&action=review Nice work. > Source/JavaScriptCore/b3/B3LowerToAir.cpp:2916 > + auto isValidMask2 = [&] () -> bool { I like your style of lambda usage. It makes the code easy to read since you are naming this block of computation.
EWS
Comment 16 2021-06-28 21:05:21 PDT
Committed r279362 (239228@main): <https://commits.webkit.org/239228@main> All reviewed patches have been landed. Closing bug and clearing flags on attachment 432447 [details].
Note You need to log in before you can comment on or make changes to this bug.