• 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.function f64 Math.sin(f64 a0) <external>
16.function f64 Math.absF64(f64 a0) <external>
17
18.function u1 main(){
19    movi.64 v0, 1500
20    movi v1, 120
21    movi v2, 120
22    call test, v0, v1, v2, v0
23    return
24}
25
26.function u1 test(i32 a0, i32 a1, i32 a2){
27    mul a1, a2
28    muli 3
29    sta v3                #lenarr
30    newarr v4, v3, f64[]              #a
31    call.short init, v4, v4
32    movi v5, 0    #loop counter
33loop:
34    lda v5
35    jeq a0, loop_exit
36    lda a0
37    i32tof64
38    sta.64 v10
39    lda v5
40    i32tof64
41    fdiv2.64 v10
42    sta.64 v6
43    call morph, v4, v6, a1, a2
44    inci v5, 1
45    jmp loop
46loop_exit:
47    fmovi.64 v7, 0.0       #testOutput
48    movi v5, 0
49    lda a1
50    sta v11
51loop2:
52    lda v5
53    jeq v11, loop2_exit
54    mul2 v11
55    add2 v5
56    muli 3
57    addi 1
58    fldarr.64 v4
59    fadd2.64 v7
60    sta.64 v7
61    inci v5, 1
62    jmp loop2
63loop2_exit:
64    fmovi.64 v9, 1e-13               #epsilon
65    call.short Math.absF64, v7, v7
66    fcmpl.64 v9
67    jgez if
68    ldai 0
69    return
70if:
71    ldai 1
72    return
73}
74
75.function u1 morph(f64[] a0, f64 a1, i32 a2, i32 a3){
76    fmovi.64 v4, 3.141592653589793
77    fmovi.64 v0, 8.0
78    movi v21, 8
79    movi v22, 3
80    movi v23, 1
81    lda a2
82    i32tof64
83    sta.64 v2
84    lda a3
85    sta v3
86    lda.64 v4
87    fmul2.64 v0
88    fdiv2.64 v2
89    sta.64 v5                          #PI2nx
90    lda a2
91    sta v2
92    fmovi.64 v0, 2.0
93    lda.64 v4
94    fmul2.64 v0
95    fmul2.64 a1
96    sta.64 v0
97    call.short Math.sin, v0, v0
98    fmovi.64 v0, 50.0
99    fmul2.64 v0
100    fneg.64
101    sta.64 v6                          #f30
102    movi v7, 0                      #loop counter
103loop:
104    lda v7
105    jeq v3, loop_exit
106    movi v8, 0                      #loop2 counter
107loop2:
108    lda v8
109    jeq v2, loop2_exit
110    lda v7
111    mul2 v2
112    add2 v8
113    mul2 v22
114    add2 v23
115    sta v9                          #3*(i*nx+j)+1
116    lda v8
117    subi 1
118    i32tof64
119    fmul2.64 v5
120    sta.64 v0
121    call.short Math.sin, v0, v0
122    sta.64 v10                         #sin((j-1)*PI2nx)
123    lda.64 v6
124    fneg.64
125    fmul2.64 v10
126    mov.obj v0, a0
127    fstarr.64 v0, v9
128    inci v8, 1
129    jmp loop2
130loop2_exit:
131    inci v7, 1
132    jmp loop
133loop_exit:
134    ldai 0
135    return
136}
137
138.function f64[] init(f64[] a0){
139    movi v2, 0
140    fmovi.64 v4, 0.0
141    lenarr a0
142    sta v1
143loop:
144    lda v2
145    jeq v1, loop_exit
146    lda.64 v4
147    fstarr.64 a0, v2
148    inci v2, 1
149    jmp loop
150loop_exit:
151    lda.obj a0
152    return.obj
153}
154