Source/Packages

Platform.AArch64.MemoryRoutine

packages/hardware/platforms/dgx-spark/src/Platform/AArch64/MemoryRoutine.alpha

167 lines4 declarations6.2 KiBSHA-256 1b4b89cd8196

Complete file · line 1

MemoryRoutine.alpha

Definition view
1module Platform.AArch64.MemoryRoutine
2
3import Compiler.MachineAArch64
4import Compiler.MachineAArch64Assembly
5import Platform.AArch64.RoutineEmitter
6
7-- AAPCS64 realizations of Runtime.NativeMemoryRoutine's admitted views:
8-- x0 destination/left, x1 source/right, x2 extent. Copy requires disjoint or
9-- identical regions and returns zero; comparison returns one iff every byte
10-- matches. Empty views access no memory. No x19-x29 or stack state is changed.
11-- This is a bounded integrity comparison, not a constant-time secret compare.
12def aarch64MemoryCopyAssembly =
13  (ahrCmpImm
14    (constructor AArch64Register AArch64X2)
15    0
16    (app
17      (lambda unrestricted tail : (family AArch64Assembly) .
18        (constructor
19          AArch64Assembly
20          AArch64AssemblyBranchIf
21          (constructor AArch64Condition AArch64Equal)
22          b"done"
23          tail))
24      (ahrLabel
25        b"copy"
26        (ahrEmit
27          (constructor
28            AArch64Instruction
29            AArch64LoadMemory8ZeroExtend
30            (constructor AArch64Register AArch64X3)
31            (constructor AArch64Register AArch64X1)
32            0)
33          (ahrEmit
34            (constructor
35              AArch64Instruction
36              AArch64StoreMemory8
37              (constructor AArch64Register AArch64X0)
38              0
39              (constructor AArch64Register AArch64X3))
40            (ahrEmit
41              (constructor
42                AArch64Instruction
43                AArch64AddImmediate
44                (constructor AArch64Register AArch64X0)
45                (constructor AArch64Register AArch64X0)
46                1)
47              (ahrEmit
48                (constructor
49                  AArch64Instruction
50                  AArch64AddImmediate
51                  (constructor AArch64Register AArch64X1)
52                  (constructor AArch64Register AArch64X1)
53                  1)
54                (ahrEmit
55                  (constructor
56                    AArch64Instruction
57                    AArch64SubtractImmediate
58                    (constructor AArch64Register AArch64X2)
59                    (constructor AArch64Register AArch64X2)
60                    1)
61                  (ahrCmpImm
62                    (constructor AArch64Register AArch64X2)
63                    0
64                    (app
65                      (lambda unrestricted tail : (family AArch64Assembly) .
66                        (constructor
67                          AArch64Assembly
68                          AArch64AssemblyBranchIf
69                          (constructor AArch64Condition AArch64NotEqual)
70                          b"copy"
71                          tail))
72                      (ahrLabel
73                        b"done"
74                        (ahrMovImm (constructor AArch64Register AArch64X0) 0 (ahrReturn ahrEnd)))))))))))))
75
76def aarch64MemoryCopyCode =
77  (aarch64RoutineBytes aarch64MemoryCopyAssembly)
78
79def aarch64MemoryEqualAssembly =
80  (ahrCmpImm
81    (constructor AArch64Register AArch64X2)
82    0
83    (app
84      (lambda unrestricted tail : (family AArch64Assembly) .
85        (constructor
86          AArch64Assembly
87          AArch64AssemblyBranchIf
88          (constructor AArch64Condition AArch64Equal)
89          b"equal"
90          tail))
91      (ahrLabel
92        b"compare"
93        (ahrEmit
94          (constructor
95            AArch64Instruction
96            AArch64LoadMemory8ZeroExtend
97            (constructor AArch64Register AArch64X3)
98            (constructor AArch64Register AArch64X0)
99            0)
100          (ahrEmit
101            (constructor
102              AArch64Instruction
103              AArch64LoadMemory8ZeroExtend
104              (constructor AArch64Register AArch64X4)
105              (constructor AArch64Register AArch64X1)
106              0)
107            (ahrEmit
108              (constructor
109                AArch64Instruction
110                AArch64CompareRegister
111                (constructor AArch64Register AArch64X3)
112                (constructor AArch64Register AArch64X4))
113              (app
114                (lambda unrestricted tail : (family AArch64Assembly) .
115                  (constructor
116                    AArch64Assembly
117                    AArch64AssemblyBranchIf
118                    (constructor AArch64Condition AArch64NotEqual)
119                    b"different"
120                    tail))
121                (ahrEmit
122                  (constructor
123                    AArch64Instruction
124                    AArch64AddImmediate
125                    (constructor AArch64Register AArch64X0)
126                    (constructor AArch64Register AArch64X0)
127                    1)
128                  (ahrEmit
129                    (constructor
130                      AArch64Instruction
131                      AArch64AddImmediate
132                      (constructor AArch64Register AArch64X1)
133                      (constructor AArch64Register AArch64X1)
134                      1)
135                    (ahrEmit
136                      (constructor
137                        AArch64Instruction
138                        AArch64SubtractImmediate
139                        (constructor AArch64Register AArch64X2)
140                        (constructor AArch64Register AArch64X2)
141                        1)
142                      (ahrCmpImm
143                        (constructor AArch64Register AArch64X2)
144                        0
145                        (app
146                          (lambda unrestricted tail : (family AArch64Assembly) .
147                            (constructor
148                              AArch64Assembly
149                              AArch64AssemblyBranchIf
150                              (constructor AArch64Condition AArch64NotEqual)
151                              b"compare"
152                              tail))
153                          (ahrLabel
154                            b"equal"
155                            (ahrMovImm
156                              (constructor AArch64Register AArch64X0)
157                              1
158                              (ahrReturn
159                                (ahrLabel
160                                  b"different"
161                                  (ahrMovImm
162                                    (constructor AArch64Register AArch64X0)
163                                    0
164                                    (ahrReturn ahrEnd))))))))))))))))))
165
166def aarch64MemoryEqualCode =
167  (aarch64RoutineBytes aarch64MemoryEqualAssembly)

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.