# Copyright (c) 2021-2022 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # a2 - a0 * a1 .function i32 msub_i32(i32 a0, i32 a1, i32 a2) { mul a0, a1 sta v1 sub a2, v1 return } # - (a0 * a1) + a2 .function i32 msub_i32_var0(i32 a0, i32 a1, i32 a2) { mul a0, a1 neg add2 a2 return } # (-a0) * a1 + a2 .function i32 msub_i32_var1(i32 a0, i32 a1, i32 a2) { lda a0 neg mul2 a1 add2 a2 return } # a2 - a0 * a1 .function i64 msub_i64(i64 a0, i64 a1, i64 a2) { lda.64 a1 mul2.64 a0 sta.64 v0 lda.64 a2 sub2.64 v0 return.64 } # - (a0 * a1) + a2 .function i64 msub_i64_var0(i64 a0, i64 a1, i64 a2) { lda.64 a1 mul2.64 a0 neg.64 sta.64 v0 lda.64 a2 add2.64 v0 return.64 } # (-a0) * a1 + a2 .function i64 msub_i64_var1(i64 a0, i64 a1, i64 a2) { lda.64 a0 neg.64 mul2.64 a1 add2.64 a2 return.64 } .function i32 main() { movi v0, 10 movi v1, 1000 movi v2, -56 call msub_i32, v0, v1, v2 sta v0 ldai -10056 jne v0, exit_error_0 movi v0, 10 movi v1, 1000 movi v2, -56 call msub_i32_var0, v0, v1, v2 sta v0 ldai -10056 jne v0, exit_error_1 movi v0, 10 movi v1, 1000 movi v2, -56 call msub_i32_var1, v0, v1, v2 sta v0 ldai -10056 jne v0, exit_error_2 movi.64 v0, -1 movi.64 v1, 123 movi.64 v2, 19 call msub_i64, v0, v1, v2 sta.64 v0 ldai.64 142 cmp.64 v0 jnez exit_error_3 movi.64 v0, -1 movi.64 v1, 123 movi.64 v2, 19 call msub_i64_var0, v0, v1, v2 sta.64 v0 ldai.64 142 cmp.64 v0 jnez exit_error_4 movi.64 v0, -1 movi.64 v1, 123 movi.64 v2, 19 call msub_i64_var1, v0, v1, v2 sta.64 v0 ldai.64 142 cmp.64 v0 jnez exit_error_5 ldai 0 return exit_error_0: ldai 1 return exit_error_1: ldai 2 return exit_error_2: ldai 3 return exit_error_3: ldai 4 exit_error_4: ldai 5 exit_error_5: ldai 6 return }