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