# 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. definitions: [] tests: - file-name: "mod" isa: title: Three address integer division or modulo description: Perform integer division or modulo on two registers and store result into accumulator commands: - file-name: "op_v1_4_v2_4_zero" isa: instructions: - sig: mod v1:in:i32, v2:in:i32 acc: out:i32 format: [op_v1_4_v2_4] code-template: | # movi v0, 0 movi v1, %s mod v0, v1 movi v0, 0 jne v0, set_failure ldai 0 jmp fall_through set_failure: ldai 1 fall_through: description: Check mod with zero and various values. cases: - values: ["1"] - values: ["-1"] - values: ["0x7FFFFFFF"] - values: ["0x80000000"] - values: ["-0x7FFFFFFF"] - values: ["-0x80000000"] - values: ["0xFFFFFFFF"] - values: ["-0xFFFFFFFF"] - file-name: "op_vs_8_pone" isa: instructions: - sig: mod v1:in:i32, v2:in:i32 acc: out:i32 format: [op_v1_4_v2_4] code-template: | # movi v0, 1 movi v1, %s mod v0, v1 movi v0, %s jne v0, set_failure ldai 0 jmp fall_through set_failure: ldai 1 fall_through: description: Check mod with +1 and various values. cases: - values: ["1", "0x0"] - values: ["-1", "0x0"] - values: ["0x7FFFFFFF", "0x1"] - values: ["-0x7FFFFFFF", "0x1"] - values: ["0x80000000", "0x1"] - values: ["-0x80000000", "0x1"] - values: ["0xFFFFFFFF", "0x0"] - values: ["-0xFFFFFFFF", "0x0"] - file-name: "op_vs_8_none" isa: instructions: - sig: mod v1:in:i32, v2:in:i32 acc: out:i32 format: [op_v1_4_v2_4] code-template: | # movi v0, -1 movi v1, %s mod v0, v1 movi v0, %s jne v0, set_failure ldai 0 jmp fall_through set_failure: ldai 1 fall_through: description: Check mod with -1 and various values. cases: - values: ["1", "0x0"] - values: ["-1", "0x0"] - values: ["0x7FFFFFFF", "0xFFFFFFFF"] - values: ["-0x7FFFFFFF", "0xFFFFFFFF"] - values: ["0x80000000", "0xFFFFFFFF"] - values: ["-0x80000000", "0xFFFFFFFF"] - values: ["0xFFFFFFFF", "0x0"] - values: ["-0xFFFFFFFF", "0x0"] - file-name: "op_vs_8_pmax" isa: instructions: - sig: mod v1:in:i32, v2:in:i32 acc: out:i32 format: [op_v1_4_v2_4] code-template: | # movi v0, 0x7FFFFFFF movi v1, %s mod v0, v1 movi v0, %s jne v0, set_failure ldai 0 jmp fall_through set_failure: ldai 1 fall_through: description: Check mod with +max and various values. cases: - values: ["1", "0x0"] - values: ["-1", "0x0"] - values: ["0x7FFFFFFF", "0x0"] - values: ["-0x7FFFFFFF", "0x0"] - values: ["0x80000000", "0x7FFFFFFF"] - values: ["-0x80000000", "0x7FFFFFFF"] - values: ["0xFFFFFFFF", "0x0"] - values: ["-0xFFFFFFFF", "0x0"] - file-name: "op_vs_8_nmax" isa: instructions: - sig: mod v1:in:i32, v2:in:i32 acc: out:i32 format: [op_v1_4_v2_4] code-template: | # movi v0, -0x80000000 movi v1, %s mod v0, v1 movi v0, %s jne v0, set_failure ldai 0 jmp fall_through set_failure: ldai 1 fall_through: description: Check mod with -max and various values. cases: - values: ["1", "0x0"] - values: ["-1", "0x0"] - values: ["0x7FFFFFFF", "0xFFFFFFFF"] - values: ["-0x7FFFFFFF", "0xFFFFFFFF"] - values: ["0x80000000", "0x0"] - values: ["-0x80000000", "0x0"] - values: ["0xFFFFFFFF", "0x0"] - values: ["-0xFFFFFFFF", "0x0"] - file-name: "vals" isa: instructions: - sig: mod v1:in:i32, v2:in:i32 acc: out:i32 format: [op_v1_4_v2_4] code-template: | # movi v0, %s movi v1, %s mod v0, v1 movi v0, %s jne v0, set_failure ldai 0 jmp fall_through set_failure: ldai 1 fall_through: description: Check mod with various values. tags: ['tsan'] cases: - values: ["0x87A8E1D9", "0x6D8935CF", "0xF53217A8"] - values: ["0x6AFB709C", "0xD7328FDF", "0x1960905A"] - values: ["0x91AD1CA9", "0x330B9F8D", "0xF7C45BC3"] - values: ["0xC5EA3D60", "0x40FCDDC1", "0xC5EA3D60"] - values: ["0x63F6803C", "0x616041E0", "0x2963E5C"] - values: ["0x1E0384B", "0x7C662C8", "0x1E0384B"] - values: ["0x3CFC06FC", "0x54EF2076", "0x3CFC06FC"] - values: ["0x47CB3788", "0x35782ACF", "0x12530CB9"] - values: ["0x2680767A", "0x4E618FD7", "0x2680767A"] - values: ["0x817E8C9D", "0xB92B1E1B", "0xC8536E82"] - values: ["0x80000000", "-1", "0"] - values: ["-2147483648", "-1", "0"] - file-name: "op_v1_4_v2_4_exception" isa: instructions: - sig: mod v1:in:i32, v2:in:i32 acc: out:i32 format: [op_v1_4_v2_4] exceptions: - x_arith tags: ['irtoc_ignore'] header-template: [ArithmeticException, main] code-template: | # movi v0, %s movi v1, 0 begin: mod v0, v1 end: ldai 1 # Should not reach this line return catch_AE: ldai 0 # Expected panda.ArithmeticException return catch_all: ldai 1 # Unexpected exception, test failed return .catch panda.ArithmeticException, begin, end, catch_AE .catchall begin, end, catch_all check-type: none description: Check `mod` throws ArithmeticException when divides by zero. cases: - values: ["0"] - values: ["1"] - values: ["0x7FFFFFFF"] - values: ["0x80000000"] - values: ["0xFFFFFFFF"] - values: ["-1"] - values: ["-0x7FFFFFFF"] - values: ["-0x80000000"] - values: ["-0xFFFFFFFF"] - file-name: "regs" isa: instructions: - sig: mod v1:in:i32, v2:in:i32 acc: out:i32 format: [op_v1_4_v2_4] runner-options: ['compile-only'] code-template: | # mod %s, %s check-type: none description: Check mod with various register numbers. cases: - values: ["v15", "v15"] - values: ["v0", "v15"] - values: ["v15", "v0"] - values: ["v15", "v16"] runner-options: ['compile-failure'] - values: ["v16", "v15"] runner-options: ['compile-failure'] - values: ["v16", "v16"] runner-options: ['compile-failure'] - file-name: type isa: verification: - v1_type - v2_type tags: ['verifier'] runner-options: ['verifier-failure', 'verifier-config'] header-template: [] code-template: | # .record A {} .record B {} .record panda.String .record panda.Object .function i32 main() { %s *s mod v0, v1 check-type: exit-positive description: Check 'mod' with incorrect register types. template-cases: - values: - movi v0, 0 exclude: [val] - values: - movi.64 v0, 0 - values: - fmovi v0, 0 - values: - fmovi.64 v0, 0 - values: - | # lda.type B sta.obj v0 - values: - | # lda.type B[] sta.obj v0 - values: - | # lda.type panda.String sta.obj v0 - values: - | # lda.type panda.Object sta.obj v0 - values: - | # movi v0, 10 newarr v0, v0, i32[] - values: - mov.null v0 cases: - values: - movi v1, 0 id: val - values: - movi.64 v1, 0 - values: - fmovi v1, 0 - values: - fmovi.64 v1, 0 - values: - | # lda.type A sta.obj v1 - values: - | # lda.type A[] sta.obj v1 - values: - | # lda.type panda.String sta.obj v1 - values: - | # lda.type panda.Object sta.obj v1 - values: - | # movi v1, 10 newarr v1, v1, i32[] - values: - mov.null v1 - file-name: uninitialized_regs isa: instructions: - sig: mod v1:in:i32, v2:in:i32 acc: out:i32 format: [op_v1_4_v2_4] description: Check 'mod' with uninitialized registers. tags: ['verifier'] runner-options: ['verifier-failure', 'verifier-config'] code-template: | # %s *s mod %s, *s check-type: exit-positive template-cases: - values: - '' - v0 - values: - movi v0, 0 - v0 exclude: [init] - values: - '' - v7 - values: - '' - v15 - values: - 'movi v15, 0' - v15 exclude: [init] cases: - values: - '' - v1 - values: - movi v1, 0 - v1 id: init - values: - '' - v8 - values: - '' - v14