CPYFPRN, CPYFMRN, CPYFERN
Memory copy forward-only, reads non-temporal
These instructions perform a memory copy. The prologue, main, and epilogue
instructions are expected to be run in succession and to appear consecutively
in memory: CPYFPRN, then CPYFMRN, and then CPYFERN.
CPYFPRN performs some preconditioning of the arguments suitable for using the CPYFMRN instruction,
and performs an IMPLEMENTATION DEFINED amount of the memory copy.
CPYFMRN performs an IMPLEMENTATION DEFINED amount of the memory copy.
CPYFERN performs the last part of the memory copy.
The inclusion of IMPLEMENTATION DEFINED amounts of memory copy
allows some optimization of the size that can be performed.
The memory copy performed by these instructions is in the forward direction only,
so the instructions are suitable for a memory copy only where there is no overlap
between the source and destination locations, or where the source address
is greater than the destination address.
The architecture supports two algorithms for the memory copy: option A and option B.
Which algorithm is used is IMPLEMENTATION DEFINED.
Portable software should not assume that the choice of algorithm is constant.
After execution of CPYFPRN, option A (which results in encoding PSTATE.C = 0):
If Xn<63> == 1, the copy size is saturated to 0x7FFFFFFFFFFFFFFF.
Xs holds the original Xs + saturated Xn.
Xd holds the original Xd + saturated Xn.
Xn holds -1* saturated Xn + an IMPLEMENTATION DEFINED
number of bytes copied.
PSTATE.{N,Z,V} are set to {0,0,0}.
After execution of CPYFPRN, option B (which results in encoding PSTATE.C = 1):
If Xn<63> == 1, the copy size is saturated to 0x7FFFFFFFFFFFFFFF.
Xs holds the original Xs + an IMPLEMENTATION DEFINED
number of bytes copied.
Xd holds the original Xd + an IMPLEMENTATION DEFINED
number of bytes copied.
Xn holds the saturated Xn - an IMPLEMENTATION DEFINED
number of bytes copied.
PSTATE.{N,Z,V} are set to {0,0,0}.
For CPYFMRN, option A (encoded by PSTATE.C = 0), the format of the arguments is:
Xn is treated as a signed 64-bit number and holds -1* the number of bytes
remaining to be copied in the memory copy in total.
Xs holds the lowest address that the copy is copied from -Xn.
Xd holds the lowest address that the copy is made to -Xn.
At the end of the instruction, the value of Xn is written back with -1* the
number of bytes remaining to be copied in the memory copy in total.
For CPYFMRN, option B (encoded by PSTATE.C = 1), the format of the arguments is:
Xn holds the number of bytes remaining to be copied in the memory copy in total.
Xs holds the lowest address that the copy is copied from.
Xd holds the lowest address that the copy is copied to.
At the end of the instruction:
the value of Xn is written back with the number of bytes remaining to be copied
in the memory copy in total.
the value of Xs is written back with the lowest address that has not been copied from.
the value of Xd is written back with the lowest address that has not been copied to.
For CPYFERN, option A (encoded by PSTATE.C = 0), the format of the arguments is:
Xn is treated as a signed 64-bit number and holds -1* the number of bytes
remaining to be copied in the memory copy in total.
Xs holds the lowest address that the copy is copied from -Xn.
Xd holds the lowest address that the copy is made to -Xn.
At the end of the instruction, the value of Xn is written back with 0.
For CPYFERN, option B (encoded by PSTATE.C = 1), the format of the arguments is:
Xn holds the number of bytes remaining to be copied in the memory copy in total.
Xs holds the lowest address that the copy is copied from.
Xd holds the lowest address that the copy is copied to.
At the end of the instruction:
the value of Xn is written back with 0.
the value of Xs is written back with the lowest address that has not been copied from.
the value of Xd is written back with the lowest address that has not been copied to.
For information about the CONSTRAINED UNPREDICTABLE behavior of this instruction, see Architectural Constraints on UNPREDICTABLE behaviors, and particularly Memory Copy and Memory Set CPY*.
0
1
1
0
0
1
0
1
0
0
0
0
1
0
0
CPYFPRN [<Xd>]!, [<Xs>]!, <Xn>!
0
1
CPYFMRN [<Xd>]!, [<Xs>]!, <Xn>!
1
0
CPYFERN [<Xd>]!, [<Xs>]!, <Xn>!
if !IsFeatureImplemented(FEAT_MOPS) || sz != '00' then UNDEFINED;
CPYParams memcpy;
memcpy.d = UInt(Rd);
memcpy.s = UInt(Rs);
memcpy.n = UInt(Rn);
constant bits(4) options = op2;
constant boolean rnontemporal = options<3> == '1';
constant boolean wnontemporal = options<2> == '1';
case op1 of
when '00' memcpy.stage = MOPSStage_Prologue;
when '01' memcpy.stage = MOPSStage_Main;
when '10' memcpy.stage = MOPSStage_Epilogue;
otherwise SEE "Memory Copy and Memory Set";
<Xd>
For the prologue variant: is the 64-bit name of the general-purpose register that holds the destination address and is updated by the instruction, encoded in the "Rd" field.
<Xd>
For the epilogue and main variant: is the 64-bit name of the general-purpose register that holds an encoding of the destination address, encoded in the "Rd" field.
<Xs>
For the prologue variant: is the 64-bit name of the general-purpose register that holds the source address and is updated by the instruction, encoded in the "Rs" field.
<Xs>
For the epilogue and main variant: is the 64-bit name of the general-purpose register that holds an encoding of the source address, encoded in the "Rs" field.
<Xn>
For the prologue variant: is the 64-bit name of the general-purpose register that holds the number of bytes to be transferred and is updated by the instruction to encode the remaining size and destination, encoded in the "Rn" field.
<Xn>
For the main variant: is the 64-bit name of the general-purpose register that holds an encoding of the number of bytes to be transferred, encoded in the "Rn" field.
<Xn>
For the epilogue variant: is the 64-bit name of the general-purpose register that holds an encoding of the number of bytes to be transferred and is set to zero at the end of the instruction, encoded in the "Rn" field.
CheckMOPSEnabled();
CheckCPYConstrainedUnpredictable(memcpy.n, memcpy.d, memcpy.s);
memcpy.nzcv = PSTATE.<N,Z,C,V>;
memcpy.toaddress = X[memcpy.d, 64];
memcpy.fromaddress = X[memcpy.s, 64];
memcpy.cpysize = SInt(X[memcpy.n, 64]);
memcpy.implements_option_a = CPYFOptionA();
constant boolean rprivileged = (if options<1> == '1' then AArch64.IsUnprivAccessPriv()
else PSTATE.EL != EL0);
constant boolean wprivileged = (if options<0> == '1' then AArch64.IsUnprivAccessPriv()
else PSTATE.EL != EL0);
constant AccessDescriptor raccdesc = CreateAccDescMOPS(MemOp_LOAD, rprivileged, rnontemporal);
constant AccessDescriptor waccdesc = CreateAccDescMOPS(MemOp_STORE, wprivileged, wnontemporal);
if memcpy.stage == MOPSStage_Prologue then
if memcpy.cpysize<63> == '1' then memcpy.cpysize = ArchMaxMOPSBlockSize;
if memcpy.implements_option_a then
memcpy.nzcv = '0000';
// Copy in the forward direction offsets the arguments.
memcpy.toaddress = memcpy.toaddress + memcpy.cpysize;
memcpy.fromaddress = memcpy.fromaddress + memcpy.cpysize;
memcpy.cpysize = 0 - memcpy.cpysize;
else
memcpy.nzcv = '0010';
memcpy.stagecpysize = MemCpyStageSize(memcpy);
if memcpy.stage != MOPSStage_Prologue then
CheckMemCpyParams(memcpy, options);
integer copied;
boolean iswrite;
AddressDescriptor memaddrdesc;
PhysMemRetStatus memstatus;
memcpy.forward = TRUE;
boolean fault = FALSE;
MOPSBlockSize B;
if memcpy.implements_option_a then
while memcpy.stagecpysize != 0 && !fault do
// IMP DEF selection of the block size that is worked on. While many
// implementations might make this constant, that is not assumed.
B = CPYSizeChoice(memcpy);
assert B <= -1 * memcpy.stagecpysize;
(copied, iswrite, memaddrdesc, memstatus) = MemCpyBytes(memcpy.toaddress + memcpy.cpysize,
memcpy.fromaddress + memcpy.cpysize,
memcpy.forward, B,
raccdesc, waccdesc);
if copied != B then
fault = TRUE;
else
memcpy.cpysize = memcpy.cpysize + B;
memcpy.stagecpysize = memcpy.stagecpysize + B;
else
while memcpy.stagecpysize > 0 && !fault do
// IMP DEF selection of the block size that is worked on. While many
// implementations might make this constant, that is not assumed.
B = CPYSizeChoice(memcpy);
assert B <= memcpy.stagecpysize;
(copied, iswrite, memaddrdesc, memstatus) = MemCpyBytes(memcpy.toaddress,
memcpy.fromaddress,
memcpy.forward, B,
raccdesc, waccdesc);
if copied != B then
fault = TRUE;
else
memcpy.fromaddress = memcpy.fromaddress + B;
memcpy.toaddress = memcpy.toaddress + B;
memcpy.cpysize = memcpy.cpysize - B;
memcpy.stagecpysize = memcpy.stagecpysize - B;
UpdateCpyRegisters(memcpy, fault, copied);
if fault then
if IsFault(memaddrdesc) then
AArch64.Abort(memaddrdesc.vaddress, memaddrdesc.fault);
if IsFault(memstatus) then
constant AccessDescriptor accdesc = if iswrite then waccdesc else raccdesc;
HandleExternalAbort(memstatus, iswrite, memaddrdesc, B, accdesc);
if memcpy.stage == MOPSStage_Prologue then
PSTATE.<N,Z,C,V> = memcpy.nzcv;