1module Platform.AArch64.WordArithmetic
2
3import Compiler.MachineAArch64
4import Compiler.MachineAArch64Assembly
5import Platform.AArch64.RoutineEmitter
6
7-- x0 destination, x1 left, x2 right. Unsigned addition overflow is equivalent
8-- to the wrapped sum being below the left operand. Test before storing so a
9-- rejected update cannot change the destination or reuse a frame version.
10-- Return zero on success or one on overflow, matching Runtime.NativeWordArithmetic.
11def aarch64CheckedWordAddAssembly =
12 (ahrEmit
13 (constructor
14 AArch64Instruction
15 AArch64AddRegister
16 (constructor AArch64Register AArch64X3)
17 (constructor AArch64Register AArch64X1)
18 (constructor AArch64Register AArch64X2))
19 (ahrEmit
20 (constructor
21 AArch64Instruction
22 AArch64CompareRegister
23 (constructor AArch64Register AArch64X3)
24 (constructor AArch64Register AArch64X1))
25 (app
26 (lambda unrestricted tail : (family AArch64Assembly) .
27 (constructor
28 AArch64Assembly
29 AArch64AssemblyBranchIf
30 (constructor AArch64Condition AArch64CarryClear)
31 b"overflow"
32 tail))
33 (ahrEmit
34 (constructor
35 AArch64Instruction
36 AArch64StoreMemory64
37 (constructor AArch64Register AArch64X0)
38 0
39 (constructor AArch64Register AArch64X3))
40 (ahrMovImm
41 (constructor AArch64Register AArch64X0)
42 0
43 (ahrReturn
44 (ahrLabel
45 b"overflow"
46 (ahrMovImm (constructor AArch64Register AArch64X0) 1 (ahrReturn ahrEnd)))))))))
47
48def aarch64CheckedWordAddCode =
49 (aarch64RoutineBytes aarch64CheckedWordAddAssembly)The compiler supplied declaration spans and resolved links from this source snapshot. This page does not assert that this file belongs to a checked closure.