• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2021-2022 Huawei Device Co., Ltd.
2# Licensed under the Apache License, Version 2.0 (the "License");
3# you may not use this file except in compliance with the License.
4# You may obtain a copy of the License at
5#
6# http://www.apache.org/licenses/LICENSE-2.0
7#
8# Unless required by applicable law or agreed to in writing, software
9# distributed under the License is distributed on an "AS IS" BASIS,
10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11# See the License for the specific language governing permissions and
12# limitations under the License.
13
14.record Math <external>
15.record Globals{
16    i32 flag <static>
17}
18
19.function f64 Math.pow(f64 a0, f64 a1) <external>
20.function f64 Math.cos(f64 a0) <external>
21.function f64 Math.sin(f64 a0) <external>
22.function f64 Math.absF64(f64 a0) <external>
23
24.function u1 main(){
25    movi v0, 1024
26    movi v1, 163840
27    fmovi.64 v2, 104.46302508421098
28    call test, v0, v1, v2, v0
29    return
30}
31
32.function u1 test(i32 a0, i32 a1, f64 a2){
33    ldai 0
34    ststatic Globals.flag
35    fmovi.64 v3, 0.0               #total
36    mov v5, a0                 #loop counter
37loop:
38    jgt a1, loop_exit
39    call.short partial, v5, v0
40    fadd2.64 v3
41    sta.64 v3
42    lda v5
43    muli 2
44    sta v5
45    jmp loop
46loop_exit:
47    lda.64 v3
48    fsub2.64 a2
49    sta.64 v6
50    call.short Math.absF64, v6, v6
51    sta.64 v6
52    fldai.64 1e-13
53    fcmpl.64 v6
54    jlez exit_failure
55    ldstatic Globals.flag
56    jeqz exit_failure
57    ldai 0
58    return
59exit_failure:
60    ldai 1
61    return
62}
63
64.function f64 partial(i32 a0){
65    fmovi.64 v10, -0.5
66    fmovi.64 v11, 0.0                #a1
67    fmovi.64 v12, 0.0                #a2
68    fmovi.64 v13, 0.0                #a3
69    fmovi.64 v14, 0.0                #a4
70    fmovi.64 v15, 0.0                #a5
71    fmovi.64 v16, 0.0                #a6
72    fmovi.64 v17, 0.0                #a7
73    fmovi.64 v18, 0.0                #a8
74    fmovi.64 v19, 0.0                #a9
75    fmovi.64 v20, 3.0
76    fldai.64 2.0
77    fdiv2.64 v20
78    sta.64 v20                     #twothirds
79    fmovi.64 v21, -1.0              #alt
80    fmovi.64 v22, 0.0               #k2
81    fmovi.64 v23, 0.0               #k3
82    fmovi.64 v24, 0.0               #sk
83    fmovi.64 v25, 0.0               #ck
84    movi.64 v27, 0                 #flag
85    movi v28, 1                 #loop counter
86    mov v26, a0
87    ldai 1
88loop:
89    jgt v26, loop_exit
90    i32tof64
91    sta.64 v29
92    fmul2.64 v29
93    sta.64 v30                     #k2
94    fmul2.64 v29
95    sta.64 v31                     #k3
96    mov.64 v0, v29
97    call.short Math.sin, v0, v0
98    sta.64 v32                     #sk
99    call.short Math.cos, v0, v0
100    sta.64 v33                     #ck
101    lda.64 v21
102    fneg.64
103    sta.64 v21
104    mov.64 v0, v20
105    fldai.64 -1.0
106    fadd2.64 v29
107    sta.64 v1
108    call.short Math.pow, v0, v1
109    fadd2.64 v11
110    sta.64 v11
111    mov.64 v0, v29
112    call.short Math.pow, v0, v10
113    fadd2.64 v12
114    sta.64 v12
115    fldai.64 1.0
116    fadd2.64 v29
117    fmul2.64 v29
118    sta.64 v34
119    fldai.64 1.0
120    fdiv2.64 v34
121    fadd2.64 v13
122    sta.64 v13
123    lda.64 v31
124    fmul2.64 v32
125    fmul2.64 v32
126    sta.64 v34
127    fldai.64 1.0
128    fdiv2.64 v34
129    fadd2.64 v14
130    sta.64 v14
131    lda.64 v31
132    fmul2.64 v33
133    fmul2.64 v33
134    sta.64 v34
135    fldai.64 1.0
136    fdiv2.64 v34
137    fadd2.64 v15
138    sta.64 v15
139    fldai.64 1.0
140    fdiv2.64 v29
141    fadd2.64 v16
142    sta.64 v16
143    fldai.64 1.0
144    fdiv2.64 v30
145    fadd2.64 v17
146    sta.64 v17
147    lda.64 v21
148    fdiv2.64 v29
149    fadd2.64 v18
150    sta.64 v18
151    fldai.64 2.0
152    fmul2.64 v29
153    sta.64 v34
154    fldai.64 -1.0
155    fadd2.64 v34
156    sta.64 v34
157    lda.64 v21
158    fdiv2.64 v34
159    fadd2.64 v19
160    sta.64 v19
161    lda v28
162    addi 1
163    sta v28
164    jmp loop
165loop_exit:
166    lda.64 v11
167    fadd2.64 v12
168    fadd2.64 v13
169    fadd2.64 v14
170    fadd2.64 v15
171    fmovi.64 v5, 0.0
172    fcmpl.64 v5
173    jgtz if
174    ldai 2
175    ststatic Globals.flag
176endif:
177    lda.64 v16
178    fadd2.64 v17
179    fadd2.64 v18
180    fadd2.64 v19
181    return.64
182if:
183    ldai 1
184    ststatic Globals.flag
185    jmp endif
186}
187