1b1994897Sopenharmony_ci# Copyright (c) 2021-2022 Huawei Device Co., Ltd.
2b1994897Sopenharmony_ci# Licensed under the Apache License, Version 2.0 (the "License");
3b1994897Sopenharmony_ci# you may not use this file except in compliance with the License.
4b1994897Sopenharmony_ci# You may obtain a copy of the License at
5b1994897Sopenharmony_ci#
6b1994897Sopenharmony_ci# http://www.apache.org/licenses/LICENSE-2.0
7b1994897Sopenharmony_ci#
8b1994897Sopenharmony_ci# Unless required by applicable law or agreed to in writing, software
9b1994897Sopenharmony_ci# distributed under the License is distributed on an "AS IS" BASIS,
10b1994897Sopenharmony_ci# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11b1994897Sopenharmony_ci# See the License for the specific language governing permissions and
12b1994897Sopenharmony_ci# limitations under the License.
13b1994897Sopenharmony_ci
14b1994897Sopenharmony_ci.function u1 main(){
15b1994897Sopenharmony_ci    movi v0, 20000
16b1994897Sopenharmony_ci    movi v1, 2560
17b1994897Sopenharmony_ci    movi v2, 204800000
18b1994897Sopenharmony_ci    call test, v0, v1, v2, v0
19b1994897Sopenharmony_ci    return
20b1994897Sopenharmony_ci}
21b1994897Sopenharmony_ci
22b1994897Sopenharmony_ci.function i32 test(i32 a0, i32 a1, i32 a2){
23b1994897Sopenharmony_ci    movi v3, 0              #sum
24b1994897Sopenharmony_ci    movi v4, 0              #loop counter
25b1994897Sopenharmony_ci    ldai 0
26b1994897Sopenharmony_ciloop:
27b1994897Sopenharmony_ci    movi v5, 0              #loop2 counter
28b1994897Sopenharmony_ci    jeq a0, loop_exit
29b1994897Sopenharmony_ci    lda v5
30b1994897Sopenharmony_ciloop2:
31b1994897Sopenharmony_ci    jeq a1, loop2_exit
32b1994897Sopenharmony_ci    call.short fast3bitlookup, v5, v5
33b1994897Sopenharmony_ci    add2 v3
34b1994897Sopenharmony_ci    sta v3
35b1994897Sopenharmony_ci    inci v5, 1
36b1994897Sopenharmony_ci    lda v5
37b1994897Sopenharmony_ci    jmp loop2
38b1994897Sopenharmony_ciloop2_exit:
39b1994897Sopenharmony_ci    inci v4, 1
40b1994897Sopenharmony_ci    lda v4
41b1994897Sopenharmony_ci    jmp loop
42b1994897Sopenharmony_ciloop_exit:
43b1994897Sopenharmony_ci    lda v3
44b1994897Sopenharmony_ci    jne a2, assert_err
45b1994897Sopenharmony_ci    ldai 0
46b1994897Sopenharmony_ci    return
47b1994897Sopenharmony_ciassert_err:
48b1994897Sopenharmony_ci    ldai 1
49b1994897Sopenharmony_ci    return
50b1994897Sopenharmony_ci}
51b1994897Sopenharmony_ci
52b1994897Sopenharmony_ci.function i32 fast3bitlookup(i32 a0){
53b1994897Sopenharmony_ci    movi v1, 0              #c
54b1994897Sopenharmony_ci    movi v2, 0xE994         #bi3b
55b1994897Sopenharmony_ci    lda a0
56b1994897Sopenharmony_ci    shli 1
57b1994897Sopenharmony_ci    andi 14
58b1994897Sopenharmony_ci    sta v3
59b1994897Sopenharmony_ci    shr v2, v3
60b1994897Sopenharmony_ci    andi 3
61b1994897Sopenharmony_ci    sta v1
62b1994897Sopenharmony_ci    lda a0
63b1994897Sopenharmony_ci    shri 2
64b1994897Sopenharmony_ci    andi 14
65b1994897Sopenharmony_ci    sta v3
66b1994897Sopenharmony_ci    shr v2, v3
67b1994897Sopenharmony_ci    andi 3
68b1994897Sopenharmony_ci    add2 v1
69b1994897Sopenharmony_ci    sta v1
70b1994897Sopenharmony_ci    lda a0
71b1994897Sopenharmony_ci    shri 5
72b1994897Sopenharmony_ci    andi 6
73b1994897Sopenharmony_ci    sta v3
74b1994897Sopenharmony_ci    shr v2, v3
75b1994897Sopenharmony_ci    andi 3
76b1994897Sopenharmony_ci    add2 v1
77b1994897Sopenharmony_ci    sta v1
78b1994897Sopenharmony_ci    lda v1
79b1994897Sopenharmony_ci    return
80b1994897Sopenharmony_ci}
81