• 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# a2 - a0 * a1
15.function i32 msubv_i32(i32 a0, i32 a1, i32 a2) {
16    mulv a0, a1
17    subv a2, a0
18    lda a2
19    return
20}
21
22# - (a0 * a1) + a2
23.function i32 msubv_i32_var0(i32 a0, i32 a1, i32 a2) {
24    mulv a0, a1
25    lda a0
26    neg
27    add2v v0, a2
28    lda v0
29    return
30}
31
32# (-a0) * a1 + a2
33.function i32 msubv_i32_var1(i32 a0, i32 a1, i32 a2) {
34    lda a0
35    neg
36    mul2v v0, a1
37    addv v0, a2
38    lda v0
39    return
40}
41
42# a2 - a0 * a1
43.function i64 msubv_i64(i64 a0, i64 a1, i64 a2) {
44    lda.64 a1
45    mul2v.64 v0, a0
46    lda.64 a2
47    sub2v.64 v0, v0
48    lda.64 v0
49    return.64
50}
51
52# - (a0 * a1) + a2
53.function i64 msubv_i64_var0(i64 a0, i64 a1, i64 a2) {
54    lda.64 a1
55    mul2v.64 v0, a0
56    lda.64 v0
57    neg.64
58    add2v.64 v0, a2
59    lda.64 v0
60    return.64
61}
62
63# (-a0) * a1 + a2
64.function i64 msubv_i64_var1(i64 a0, i64 a1, i64 a2) {
65    lda.64 a0
66    neg.64
67    mul2v.64 v0, a1
68    lda.64 a2
69    add2v.64 v0, v0
70    lda.64 v0
71    return.64
72}
73
74.function i32 main() {
75    movi v0, 10
76    movi v1, 1000
77    movi v2, -56
78    call msubv_i32, v0, v1, v2
79    sta v0
80    ldai -10056
81    jne v0, exit_error_0
82    movi v0, 10
83    movi v1, 1000
84    movi v2, -56
85    call msubv_i32_var0, v0, v1, v2
86    sta v0
87    ldai -10056
88    jne v0, exit_error_1
89    movi v0, 10
90    movi v1, 1000
91    movi v2, -56
92    call msubv_i32_var1, v0, v1, v2
93    sta v0
94    ldai -10056
95    jne v0, exit_error_2
96    movi.64 v0, -1
97    movi.64 v1, 123
98    movi.64 v2, 19
99    call msubv_i64, v0, v1, v2
100    sta.64 v0
101    ldai.64 142
102    cmp.64 v0
103    jnez exit_error_3
104    movi.64 v0, -1
105    movi.64 v1, 123
106    movi.64 v2, 19
107    call msubv_i64_var0, v0, v1, v2
108    sta.64 v0
109    ldai.64 142
110    cmp.64 v0
111    jnez exit_error_4
112    movi.64 v0, -1
113    movi.64 v1, 123
114    movi.64 v2, 19
115    call msubv_i64_var1, v0, v1, v2
116    sta.64 v0
117    ldai.64 142
118    cmp.64 v0
119    jnez exit_error_5
120    ldai 0
121    return
122exit_error_0:
123    ldai 1
124    return
125exit_error_1:
126    ldai 2
127    return
128exit_error_2:
129    ldai 3
130    return
131exit_error_3:
132    ldai 4
133exit_error_4:
134    ldai 5
135exit_error_5:
136    ldai 6
137    return
138}
139