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# Issue 1606 15.function i32 find_even_on_even(i32[] a0, i32 a1) { 16 movi v0, 2 17 lda a1 18 mod2 v0 19 jeqz _zero # if a1 is even jump to _zero 20_one: 21 inci a1, 1 # make a1 even 22_zero: 23 lda a1 24 ldarr a0 # load even index a1 25 sta v1 26 27 inci a1, 1 # increment a1 (now it's odd) 28 29 lda a1 30 ldarr a0 # load next element 31 32 jeq v1, _exit # exit if elements equal 33 jmp _one # make a1 even 34_exit: 35 inci a1, -1 36 lda a1 37 return 38} 39 40.function i32 main() { 41 movi v0, 10 42 newarr v0, v0, i32[] 43 44 movi v1, 0 45 ldai 0 46 starr v0, v1 # v0[0] = 0 47 48 inci v1, 1 49 ldai 0 50 starr v0, v1 # v0[1] = 0 51 52 inci v1, 1 53 ldai 1 54 starr v0, v1 # v0[2] = 1 55 56 inci v1, 1 57 ldai 2 58 starr v0, v1 # v0[3] = 2 59 60 inci v1, 1 61 ldai 3 62 starr v0, v1 # v0[4] = 3 63 64 inci v1, 1 65 ldai 3 66 starr v0, v1 # v0[5] = 3 67 68 movi v1, 1 69 call.short find_even_on_even, v0, v1 70 movi v1, 4 71 jne v1, exit_1 72 ldai 0 73 return 74 exit_1: 75 ldai 1 76 return 77} 78