1# Copyright (c) 2021-2024 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# a0 * 0 + a1 15.function i64 mzav(i64 a0, i64 a1) <static> { 16 movi.64 v0, 0 17 lda.64 a0 18 mul2v.64 v0, v0 19 lda.64 v0 20 add2v.64 v0, a1 21 lda.64 v0 22 return.64 23} 24 25# a0 * a1 + 0 26.function i64 mazv(i64 a0, i64 a1) <static> { 27 movi.64 v0, 0 28 lda.64 a0 29 mul2v.64 v1, a1 30 lda.64 v1 31 add2v.64 v0, v0 32 lda.64 v0 33 return.64 34} 35 36# a0 - a1 * 0 37.function i64 mzsv(i64 a0, i64 a1) <static> { 38 movi.64 v0, 0 39 lda.64 a1 40 mul2v.64 v0, v0 41 lda.64 a0 42 sub2v.64 v0, v0 43 lda.64 v0 44 return.64 45} 46 47# 0 - a0 * a1 48.function i64 mszv(i64 a0, i64 a1) <static> { 49 movi.64 v0, 0 50 lda.64 a0 51 mul2v.64 v1, a1 52 lda.64 v0 53 sub2v.64 v0, v1 54 lda.64 v0 55 return.64 56} 57 58.function i32 main() <static> { 59 movi.64 v0, 21 60 movi.64 v1, 17 61 call.short mzav, v0, v1 62 sta.64 v2 63 call.short mazv, v0, v1 64 sta.64 v3 65 call.short mzsv, v0, v1 66 sta.64 v4 67 call.short mszv, v0, v1 68 add2.64 v2 69 add2.64 v3 70 add2.64 v4 71 # (a * 0 + b) + (a * b + 0) + (a - b * 0) + (0 - a * b) => a + b 72 movi.64 v0, 38 73 cmp.64 v0 74 jnez error 75 ldai 0 76 return 77error: 78 ldai 1 79 return 80}