• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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# a & ~b
15.function i32 and_not_i32(i32 a0, i32 a1) {
16    lda a1
17    not
18    and2 a0
19    return
20}
21
22# a & ~b
23.function i64 and_not_i64(i64 a0, i64 a1) {
24    lda.64 a1
25    not.64
26    and2.64 a0
27    return.64
28}
29
30# a | ~b
31.function i32 or_not_i32(i32 a0, i32 a1) {
32    lda a1
33    not
34    or2 a0
35    return
36}
37
38# a | ~b
39.function i64 or_not_i64(i64 a0, i64 a1) {
40    lda.64 a1
41    not.64
42    or2.64 a0
43    return.64
44}
45
46# a ^ ~b
47.function i32 xor_not_i32(i32 a0, i32 a1) {
48    lda a1
49    not
50    xor2 a0
51    return
52}
53
54# a ^ ~b
55.function i64 xor_not_i64(i64 a0, i64 a1) {
56    lda.64 a1
57    not.64
58    xor2.64 a0
59    return.64
60}
61
62.record IO <external>
63.function void IO.printI64(i64 a0) <external>
64
65.function i32 main() {
66    movi v0, 0x0000ffff
67    movi v1, 0x0
68    call.short or_not_i32, v0, v1
69    movi v0, 0xffffffff
70    jne v0, exit_error_0
71    movi.64 v0, 0x0000ffff0000ffff
72    movi.64 v1, 0x00ffffffff000000
73    call.short or_not_i64, v0, v1
74    movi.64 v0, 0xff00ffff00ffffff
75    cmp.64 v0
76    jnez exit_error_1
77    movi v0, 0x0f0f0f0f
78    movi v1, 0
79    call.short and_not_i32, v0, v1
80    movi v0, 0x0f0f0f0f
81    jne v0, exit_error_2
82    movi.64 v0, 0x00ff00ff00ff00ff
83    movi.64 v1, 0xff0ffff0ff0ffff0
84    call.short and_not_i64, v0, v1
85    movi.64 v0, 0x00f0000f00f0000f
86    cmp.64 v0
87    jnez exit_error_3
88    movi v0, 0x01234567
89    movi v1, 0x76543210
90    call.short xor_not_i32, v0, v1
91    movi v0, 0x88888888
92    jne v0, exit_error_4
93    movi.64 v0, 0x0123456789abcdef
94    movi.64 v1, 0xfedcba9876543210
95    call.short xor_not_i64, v0, v1
96    movi.64 v0, 0
97    cmp.64 v0
98    jnez exit_error_5
99    ldai 0
100    return
101exit_error_0:
102    ldai 1
103    return
104exit_error_1:
105    ldai 2
106    return
107exit_error_2:
108    ldai 3
109    return
110exit_error_3:
111    ldai 4
112    return
113exit_error_4:
114    ldai 5
115    return
116exit_error_5:
117    ldai 6
118    return
119}
120