This is an archive of the discontinued LLVM Phabricator instance.

[LoongArch] Add intrinsics for MOVFCSR2GR and MOVGR2FCSR instructions
ClosedPublic

Authored by XiaodongLoong on Dec 27 2022, 1:03 AM.

Details

Summary

Instruction formats:
movgr2fcsr fcsr, rj
movfcsr2gr rd, fcsr
MOVGR2FCSR modifies the value of the software writable field
corresponding to the FCSR (floating-point control and status
register) fcsr according to the value of the lower 32 bits of
the GR (general purpose register) rj.
MOVFCSR2GR sign extends the 32-bit value of the FCSR fcsr
and writes it into the GR rd.

Add "i32 @llvm.loongarch.movfcsr2gr(i32)" intrinsic for MOVFCSR2GR
instruction. The argument is FCSR register number. The return value
is the value in the FCSR.
Add "void @llvm.loongarch.movgr2fcsr(i32, i32)" intrinsic for MOVGR2FCSR
instruction. The first argument is the FCSR number, the second argument
is the value in GR.

Diff Detail

Event Timeline

XiaodongLoong created this revision.Dec 27 2022, 1:03 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 27 2022, 1:03 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
XiaodongLoong requested review of this revision.Dec 27 2022, 1:03 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptDec 27 2022, 1:03 AM
xen0n added a comment.Dec 27 2022, 4:26 AM

MOVGR2FCSR modifies the value of the software writable field
corresponding to the FCSR (floating-point control and status
register) fcsr according to the value of the lower 32 bits of
the GR (general purpose register) rj.

The description of movgr2fcsr is incorrect, it implies GPR[rj]is read, but in fact it's only the ui5 immediate in rj slot, i.e. FCSR[rj]. I didn't look very closely but the test case changes seem good.

(It's probably more appropriate to name the instructions fcsrrd and fcsrwr (as done in loongarch-opcodes) but it may be hard to officially revise the ISA manual according to some of Loongson insiders. Maybe we can use the corrected names in the internals and expose the official name for now? This is just a suggestion for your teammates to consider though.)

llvm/lib/Target/LoongArch/LoongArchInstrInfo.td
53

Be consistent with the surrounding code and spell out the instruction mnemonic fully? Like SDT_LoongArchMovfcsr2gr?

XiaodongLoong marked an inline comment as done.

rebase code and change code for @xen0n's comments.

@xen0n Thanks for your suggestion.

llvm/lib/Target/LoongArch/LoongArchInstrInfo.td
53

Thanks, I changed that.

SixWeining accepted this revision.Jan 3 2023, 1:39 AM
This revision is now accepted and ready to land.Jan 3 2023, 1:39 AM
xen0n accepted this revision.Jan 3 2023, 2:37 AM

MOVGR2FCSR modifies the value of the software writable field
corresponding to the FCSR (floating-point control and status
register) fcsr according to the value of the lower 32 bits of
the GR (general purpose register) rj.

The description of movgr2fcsr is incorrect, it implies GPR[rj]is read, but in fact it's only the ui5 immediate in rj slot, i.e. FCSR[rj]. I didn't look very closely but the test case changes seem good.

On a closer look it turns out the description is correct after all, the description is very much non-intuitive (uses just fcsr without any position marker) so I've mistaken the GPR operand for the FCSR slot. This is very unfortunate but luckily users of the intrinsics won't have to think about it.

This revision was landed with ongoing or failed builds.Jan 3 2023, 10:12 PM
This revision was automatically updated to reflect the committed changes.