# 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. # Issue 1606 .function i32 find_even_on_even(i32[] a0, i32 a1) { movi v0, 2 lda a1 mod2 v0 jeqz _zero # if a1 is even jump to _zero _one: inci a1, 1 # make a1 even _zero: lda a1 ldarr a0 # load even index a1 sta v1 inci a1, 1 # increment a1 (now it's odd) lda a1 ldarr a0 # load next element jeq v1, _exit # exit if elements equal jmp _one # make a1 even _exit: inci a1, -1 lda a1 return } .function i32 main() { movi v0, 10 newarr v0, v0, i32[] movi v1, 0 ldai 0 starr v0, v1 # v0[0] = 0 inci v1, 1 ldai 0 starr v0, v1 # v0[1] = 0 inci v1, 1 ldai 1 starr v0, v1 # v0[2] = 1 inci v1, 1 ldai 2 starr v0, v1 # v0[3] = 2 inci v1, 1 ldai 3 starr v0, v1 # v0[4] = 3 inci v1, 1 ldai 3 starr v0, v1 # v0[5] = 3 movi v1, 1 call.short find_even_on_even, v0, v1 movi v1, 4 jne v1, exit_1 ldai 0 return exit_1: ldai 1 return }