Re: [PATCH V3] LoongArch: Add unaligned access support

Xi Ruoyao
2022-10-17T14:20:26Z

On Mon, 2022-10-17 at 13:11 +0000, David Laight wrote:
> From: Huacai Chen
> > Sent: 17 October 2022 13:52
> >
> > Loongson-2 series (Loongson-2K500, Loongson-2K1000) don't support
> > unaligned access in hardware, while Loongson-3 series (Loongson-3A5000,
> > Loongson-3C5000) are configurable whether support unaligned access in
> > hardware. This patch add unaligned access emulation for those LoongArch
> > processors without hardware support.
> >
> .....
> > +       } else if (insn.reg2i12_format.opcode == fstd_op ||
> > +               insn.reg3_format.opcode == fstxd_op) {
> > +               value = read_fpr(insn.reg2i12_format.rd);
> > +               res = unaligned_write(addr, value, 8);
> > +               if (res)
> > +                       goto fault;
> > +       } else if (insn.reg2i12_format.opcode == fsts_op ||
> > +               insn.reg3_format.opcode == fstxs_op) {
> > +               value = read_fpr(insn.reg2i12_format.rd);
> > +               res = unaligned_write(addr, value, 4);
> > +               if (res)
> > +                       goto fault;
>
> Are those right?
> Shouldn't something be converting from 'double' to
> 'float' in there?
> And generating SIGFPE (?) if the exponent is out of range.

To me it looks right.

The semantic of FST.S does not include conversion. It just stores the
lower 32 bits of a floating-point register into the memory. If someone
attempts to use FST.S to convert a double into a float, it's a
programming error.

--
Xi Ruoyao <xry111@xry111.site>
School of Aerospace Science and Technology, Xidian University