Skip to content

Commit 04974c5

Browse files
sisshiki1969claude
andcommitted
arm64: add fsqrt / fneg / fabs (FP data-processing, 1 source)
The macro only had the two-operand FP arithmetic (fadd/fsub/fmul/fdiv); add the single-source double-precision ops fabs (0x1e60c000), fneg (0x1e614000) and fsqrt (0x1e61c000). Same 2-register (Rd, Rn) shape as the D-D fmov, encoded via emit_rr. Needed to inline Math.sqrt on AArch64. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 0d1129d commit 04974c5

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

monoasm_macro/src/arm64.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,8 @@ pub(crate) enum Inst {
335335

336336
Fmov(Reg, Reg),
337337
FArith(String, Reg, Reg, Reg),
338+
/// Floating-point data-processing (1 source): `fabs`/`fneg`/`fsqrt`.
339+
FUnary(String, Reg, Reg),
338340
Fcmp(Reg, Option<Reg>),
339341
Scvtf(Reg, Reg),
340342
Fcvtzs(Reg, Reg),
@@ -552,6 +554,11 @@ impl Parse for Inst {
552554
comma!();
553555
Inst::FArith(m, rd, rn, parse_reg(input)?)
554556
}
557+
"fabs" | "fneg" | "fsqrt" => {
558+
let rd = parse_reg(input)?;
559+
comma!();
560+
Inst::FUnary(m, rd, parse_reg(input)?)
561+
}
555562
"fcmp" => {
556563
let rn = parse_reg(input)?;
557564
comma!();
@@ -1138,6 +1145,18 @@ pub(crate) fn compile(inst: Inst) -> TokenStream {
11381145
};
11391146
quote!(jit.fp_3op(#base, #a, #b, #c);)
11401147
}
1148+
Inst::FUnary(name, rd, rn) => {
1149+
// FP data-processing (1 source), double precision (type=01).
1150+
let a = rd.freg();
1151+
let b = rn.freg();
1152+
let base = match name.as_str() {
1153+
"fabs" => 0x1e60_c000u32,
1154+
"fneg" => 0x1e61_4000u32,
1155+
"fsqrt" => 0x1e61_c000u32,
1156+
_ => unreachable!(),
1157+
};
1158+
quote!(jit.emit_rr(#base, (#a).enc(), (#b).enc());)
1159+
}
11411160
Inst::Fcmp(rn, rm) => {
11421161
let a = rn.freg();
11431162
match rm {

0 commit comments

Comments
 (0)