• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2021 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.function u1 main(){
15    movi v0, 45000
16    movi v1, 256
17    movi v2, 46080000
18    call test, v0, v1, v2, v0
19    return
20}
21
22.function i32 test(i32 a0, i32 a1, i32 a2){
23    movi v3, 0   #sum
24    movi v4, 0   #loop counter
25    ldai 0
26loop:
27    movi v5, 0   #loop2_counter
28    jeq a0, loop_exit
29    lda v5
30loop2:
31    jeq a1, loop2_exit
32    call.short bitsinbyte, v5, v0
33    add2 v3
34    sta v3
35    inci v5, 1
36    lda v5
37    jmp loop2
38loop2_exit:
39    inci v4, 1
40    lda v4
41    jmp loop
42loop_exit:
43    lda v3
44    jne a2, assert_err
45    ldai 0
46    return
47assert_err:
48    ldai 1
49    return
50}
51
52.function i32 bitsinbyte(i32 a0){
53    movi v1, 1       #m
54    movi v2, 0       #c
55loop:
56    ldai 0x100
57    jle v1, loop_exit
58    and a0, v1
59    jnez if_b
60endif:
61    lda v1
62    shli 1
63    sta v1
64    jmp loop
65loop_exit:
66    lda v2
67    return
68if_b:
69    inci v2, 1
70    jmp endif
71}
72