Home | History | Annotate | Line # | Download | only in or1k
      1      1.1  christos /* Tests the divide instructions.
      2      1.1  christos 
      3  1.1.1.2  christos    Copyright (C) 2017-2024 Free Software Foundation, Inc.
      4      1.1  christos 
      5      1.1  christos    This program is free software; you can redistribute it and/or modify
      6      1.1  christos    it under the terms of the GNU General Public License as published by
      7      1.1  christos    the Free Software Foundation; either version 3 of the License, or
      8      1.1  christos    (at your option) any later version.
      9      1.1  christos 
     10      1.1  christos    This program is distributed in the hope that it will be useful,
     11      1.1  christos    but WITHOUT ANY WARRANTY; without even the implied warranty of
     12      1.1  christos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13      1.1  christos    GNU General Public License for more details.
     14      1.1  christos 
     15      1.1  christos    You should have received a copy of the GNU General Public License
     16      1.1  christos    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
     17      1.1  christos 
     18      1.1  christos # mach: or1k
     19      1.1  christos # output: report(0x0000000c);\n
     20      1.1  christos # output: report(0x00000003);\n
     21      1.1  christos # output: report(0x00000004);\n
     22      1.1  christos # output: report(0x00000000);\n
     23      1.1  christos # output: report(0x00000000);\n
     24      1.1  christos # output: report(0x00000000);\n
     25      1.1  christos # output: \n
     26      1.1  christos # output: report(0x0000000b);\n
     27      1.1  christos # output: report(0x00000003);\n
     28      1.1  christos # output: report(0x00000003);\n
     29      1.1  christos # output: report(0x00000000);\n
     30      1.1  christos # output: report(0x00000000);\n
     31      1.1  christos # output: report(0x00000000);\n
     32      1.1  christos # output: \n
     33      1.1  christos # output: report(0xfffffff4);\n
     34      1.1  christos # output: report(0xfffffffd);\n
     35      1.1  christos # output: report(0x00000004);\n
     36      1.1  christos # output: report(0x00000000);\n
     37      1.1  christos # output: report(0x00000000);\n
     38      1.1  christos # output: report(0x00000000);\n
     39      1.1  christos # output: \n
     40      1.1  christos # output: report(0xfffffff5);\n
     41      1.1  christos # output: report(0xfffffffd);\n
     42      1.1  christos # output: report(0x00000003);\n
     43      1.1  christos # output: report(0x00000000);\n
     44      1.1  christos # output: report(0x00000000);\n
     45      1.1  christos # output: report(0x00000000);\n
     46      1.1  christos # output: \n
     47      1.1  christos # output: report(0xfffffff4);\n
     48      1.1  christos # output: report(0x00000003);\n
     49      1.1  christos # output: report(0xfffffffc);\n
     50      1.1  christos # output: report(0x00000000);\n
     51      1.1  christos # output: report(0x00000000);\n
     52      1.1  christos # output: report(0x00000000);\n
     53      1.1  christos # output: \n
     54      1.1  christos # output: report(0xfffffff5);\n
     55      1.1  christos # output: report(0x00000003);\n
     56      1.1  christos # output: report(0xfffffffd);\n
     57      1.1  christos # output: report(0x00000000);\n
     58      1.1  christos # output: report(0x00000000);\n
     59      1.1  christos # output: report(0x00000000);\n
     60      1.1  christos # output: \n
     61      1.1  christos # output: report(0x0000000c);\n
     62      1.1  christos # output: report(0xfffffffd);\n
     63      1.1  christos # output: report(0xfffffffc);\n
     64      1.1  christos # output: report(0x00000000);\n
     65      1.1  christos # output: report(0x00000000);\n
     66      1.1  christos # output: report(0x00000000);\n
     67      1.1  christos # output: \n
     68      1.1  christos # output: report(0x0000000b);\n
     69      1.1  christos # output: report(0xfffffffd);\n
     70      1.1  christos # output: report(0xfffffffd);\n
     71      1.1  christos # output: report(0x00000000);\n
     72      1.1  christos # output: report(0x00000000);\n
     73      1.1  christos # output: report(0x00000000);\n
     74      1.1  christos # output: \n
     75      1.1  christos # output: report(0x0000000c);\n
     76      1.1  christos # output: report(0x00000000);\n
     77      1.1  christos # output: report(0xfffffffd);\n
     78      1.1  christos # output: report(0x00000000);\n
     79      1.1  christos # output: report(0x00000001);\n
     80      1.1  christos # output: report(0x00000000);\n
     81      1.1  christos # output: \n
     82      1.1  christos # output: report(0xfffffff4);\n
     83      1.1  christos # output: report(0x00000000);\n
     84      1.1  christos # output: report(0xfffffffd);\n
     85      1.1  christos # output: report(0x00000000);\n
     86      1.1  christos # output: report(0x00000001);\n
     87      1.1  christos # output: report(0x00000000);\n
     88      1.1  christos # output: \n
     89      1.1  christos # output: report(0x0000000c);\n
     90      1.1  christos # output: report(0x00000000);\n
     91      1.1  christos # output: report(0xfffffffd);\n
     92      1.1  christos # output: report(0x00000000);\n
     93      1.1  christos # output: report(0x00000001);\n
     94      1.1  christos # output: report(0x00000001);\n
     95      1.1  christos # output: \n
     96      1.1  christos # output: report(0xfffffff4);\n
     97      1.1  christos # output: report(0x00000000);\n
     98      1.1  christos # output: report(0xfffffffd);\n
     99      1.1  christos # output: report(0x00000000);\n
    100      1.1  christos # output: report(0x00000001);\n
    101      1.1  christos # output: report(0x00000001);\n
    102      1.1  christos # output: \n
    103      1.1  christos # output: report(0x0000000c);\n
    104      1.1  christos # output: report(0x00000003);\n
    105      1.1  christos # output: report(0x00000004);\n
    106      1.1  christos # output: report(0x00000000);\n
    107      1.1  christos # output: report(0x00000000);\n
    108      1.1  christos # output: report(0x00000000);\n
    109      1.1  christos # output: \n
    110      1.1  christos # output: report(0x0000000b);\n
    111      1.1  christos # output: report(0x00000003);\n
    112      1.1  christos # output: report(0x00000003);\n
    113      1.1  christos # output: report(0x00000000);\n
    114      1.1  christos # output: report(0x00000000);\n
    115      1.1  christos # output: report(0x00000000);\n
    116      1.1  christos # output: \n
    117      1.1  christos # output: report(0xfffffff4);\n
    118      1.1  christos # output: report(0xfffffffd);\n
    119      1.1  christos # output: report(0x00000000);\n
    120      1.1  christos # output: report(0x00000000);\n
    121      1.1  christos # output: report(0x00000000);\n
    122      1.1  christos # output: report(0x00000000);\n
    123      1.1  christos # output: \n
    124      1.1  christos # output: report(0xfffffff5);\n
    125      1.1  christos # output: report(0xfffffffd);\n
    126      1.1  christos # output: report(0x00000000);\n
    127      1.1  christos # output: report(0x00000000);\n
    128      1.1  christos # output: report(0x00000000);\n
    129      1.1  christos # output: report(0x00000000);\n
    130      1.1  christos # output: \n
    131      1.1  christos # output: report(0xfffffff4);\n
    132      1.1  christos # output: report(0x00000003);\n
    133      1.1  christos # output: report(0x55555551);\n
    134      1.1  christos # output: report(0x00000000);\n
    135      1.1  christos # output: report(0x00000000);\n
    136      1.1  christos # output: report(0x00000000);\n
    137      1.1  christos # output: \n
    138      1.1  christos # output: report(0xfffffff5);\n
    139      1.1  christos # output: report(0x00000003);\n
    140      1.1  christos # output: report(0x55555551);\n
    141      1.1  christos # output: report(0x00000000);\n
    142      1.1  christos # output: report(0x00000000);\n
    143      1.1  christos # output: report(0x00000000);\n
    144      1.1  christos # output: \n
    145      1.1  christos # output: report(0x0000000c);\n
    146      1.1  christos # output: report(0xfffffffd);\n
    147      1.1  christos # output: report(0x00000000);\n
    148      1.1  christos # output: report(0x00000000);\n
    149      1.1  christos # output: report(0x00000000);\n
    150      1.1  christos # output: report(0x00000000);\n
    151      1.1  christos # output: \n
    152      1.1  christos # output: report(0x0000000b);\n
    153      1.1  christos # output: report(0xfffffffd);\n
    154      1.1  christos # output: report(0x00000000);\n
    155      1.1  christos # output: report(0x00000000);\n
    156      1.1  christos # output: report(0x00000000);\n
    157      1.1  christos # output: report(0x00000000);\n
    158      1.1  christos # output: \n
    159      1.1  christos # output: report(0x0000000c);\n
    160      1.1  christos # output: report(0x00000000);\n
    161      1.1  christos # output: report(0x00000000);\n
    162      1.1  christos # output: report(0x00000001);\n
    163      1.1  christos # output: report(0x00000000);\n
    164      1.1  christos # output: report(0x00000000);\n
    165      1.1  christos # output: \n
    166      1.1  christos # output: report(0xfffffff4);\n
    167      1.1  christos # output: report(0x00000000);\n
    168      1.1  christos # output: report(0x00000000);\n
    169      1.1  christos # output: report(0x00000001);\n
    170      1.1  christos # output: report(0x00000000);\n
    171      1.1  christos # output: report(0x00000000);\n
    172      1.1  christos # output: \n
    173      1.1  christos # output: report(0x0000000c);\n
    174      1.1  christos # output: report(0x00000000);\n
    175      1.1  christos # output: report(0x00000000);\n
    176      1.1  christos # output: report(0x00000001);\n
    177      1.1  christos # output: report(0x00000000);\n
    178      1.1  christos # output: report(0x00000001);\n
    179      1.1  christos # output: \n
    180      1.1  christos # output: report(0xfffffff4);\n
    181      1.1  christos # output: report(0x00000000);\n
    182      1.1  christos # output: report(0x00000000);\n
    183      1.1  christos # output: report(0x00000001);\n
    184      1.1  christos # output: report(0x00000000);\n
    185      1.1  christos # output: report(0x00000001);\n
    186      1.1  christos # output: \n
    187      1.1  christos # output: exit(0)\n
    188      1.1  christos 
    189      1.1  christos #include "or1k-asm-test-helpers.h"
    190      1.1  christos 
    191      1.1  christos 	STANDARD_TEST_ENVIRONMENT
    192      1.1  christos 
    193      1.1  christos 	.section .exception_vectors
    194      1.1  christos 
    195      1.1  christos 	/* Range exception.  */
    196      1.1  christos 	.org	0xb00
    197      1.1  christos 
    198      1.1  christos 	l.addi r1, r1, -EXCEPTION_STACK_SKIP_SIZE
    199      1.1  christos 	PUSH r2
    200      1.1  christos 	PUSH r3
    201      1.1  christos 	/* Save the address of the instruction that caused the problem.  */
    202      1.1  christos 	MOVE_FROM_SPR r2, SPR_EPCR_BASE
    203      1.1  christos 	LOAD_IMMEDIATE r3, 0x15000000 /* Opcode for l.nop  */
    204      1.1  christos 	l.sw	0(r2), r3
    205      1.1  christos 	POP r3
    206      1.1  christos 	POP r2
    207      1.1  christos 	l.addi r1, r1, EXCEPTION_STACK_SKIP_SIZE
    208      1.1  christos 	l.rfe
    209      1.1  christos 
    210      1.1  christos 	.section .text
    211      1.1  christos start_tests:
    212      1.1  christos 	PUSH LINK_REGISTER_R9
    213      1.1  christos 
    214      1.1  christos 	/* Test l.div  */
    215      1.1  christos 
    216      1.1  christos 	/* Divide two positive numbers and check rounding.  Should set no
    217      1.1  christos 	   flags.  */
    218      1.1  christos 	TEST_INST_I32_I32 l.div, 0x0000000c, 0x00000003 /* 12 / 3 = 4  */
    219      1.1  christos 	TEST_INST_I32_I32 l.div, 0x0000000b, 0x00000003 /* 11 / 3 = 3  */
    220      1.1  christos 
    221      1.1  christos 	/* Divide two negative numbers and check rounding.  Should set no
    222      1.1  christos 	   flags.  */
    223      1.1  christos 	TEST_INST_I32_I32 l.div, 0xfffffff4, 0xfffffffd
    224      1.1  christos 	TEST_INST_I32_I32 l.div, 0xfffffff5, 0xfffffffd
    225      1.1  christos 
    226      1.1  christos 	/* Divide a negative number by a positive number and check
    227      1.1  christos 	   rounding.  Should set no flags.  */
    228      1.1  christos 	TEST_INST_I32_I32 l.div, 0xfffffff4, 0x00000003
    229      1.1  christos 	TEST_INST_I32_I32 l.div, 0xfffffff5, 0x00000003
    230      1.1  christos 
    231      1.1  christos 	/* Divide a positive number by a negative number and check
    232      1.1  christos 	   rounding.  Should set no flags.  */
    233      1.1  christos 	TEST_INST_I32_I32 l.div, 0x0000000c, 0xfffffffd
    234      1.1  christos 	TEST_INST_I32_I32 l.div, 0x0000000b, 0xfffffffd
    235      1.1  christos 
    236      1.1  christos 	/* Divide by zero.  This will set the overflow flag.  */
    237      1.1  christos 	TEST_INST_I32_I32 l.div, 0x0000000c, 0x00000000
    238      1.1  christos 	TEST_INST_I32_I32 l.div, 0xfffffff4, 0x00000000
    239      1.1  christos 
    240      1.1  christos 	/* Check that range exceptions are triggered.  */
    241      1.1  christos 
    242      1.1  christos 	SET_SPR_SR_FLAGS SPR_SR_OVE, r2, r3
    243      1.1  christos 
    244      1.1  christos 	/* Divide by zero.  This will set the overflow flag and trigger an
    245      1.1  christos 	   exception.  */
    246      1.1  christos 	TEST_INST_I32_I32 l.div, 0x0000000c, 0x00000000
    247      1.1  christos 	TEST_INST_I32_I32 l.div, 0xfffffff4, 0x00000000
    248      1.1  christos 
    249      1.1  christos 	CLEAR_SPR_SR_FLAGS SPR_SR_OVE, r2, r3
    250      1.1  christos 
    251      1.1  christos 	/* Test l.divu  */
    252      1.1  christos 
    253      1.1  christos 	/* Divide two positive numbers and check rounding.  Should set no
    254      1.1  christos 	   flags.  */
    255      1.1  christos 	TEST_INST_I32_I32 l.divu, 0x0000000c, 0x00000003
    256      1.1  christos 	TEST_INST_I32_I32 l.divu, 0x0000000b, 0x00000003
    257      1.1  christos 
    258      1.1  christos 	/* Divide two numbers that would be negative under 2's complement
    259      1.1  christos 	   and check rounding.  Should set no flags.  */
    260      1.1  christos 	TEST_INST_I32_I32 l.divu, 0xfffffff4, 0xfffffffd
    261      1.1  christos 	TEST_INST_I32_I32 l.divu, 0xfffffff5, 0xfffffffd
    262      1.1  christos 
    263      1.1  christos 	/* Divide a number that would be negative under 2's complement by a
    264      1.1  christos 	   number that would be positive under 2's complement and check
    265      1.1  christos 	   rounding.  This should set no flags.  */
    266      1.1  christos 	TEST_INST_I32_I32 l.divu, 0xfffffff4, 0x00000003
    267      1.1  christos 	TEST_INST_I32_I32 l.divu, 0xfffffff5, 0x00000003
    268      1.1  christos 
    269      1.1  christos 	/* Divide a number that would be positive under 2's complement by a
    270      1.1  christos 	   number that would be negative under 2's complement and check
    271      1.1  christos 	   rounding.  This should set no flags.  */
    272      1.1  christos 	TEST_INST_I32_I32 l.divu, 0x0000000c, 0xfffffffd
    273      1.1  christos 	TEST_INST_I32_I32 l.divu, 0x0000000b, 0xfffffffd
    274      1.1  christos 
    275      1.1  christos 	/* Divide by zero.  This will set the carry flag.  */
    276      1.1  christos 	TEST_INST_I32_I32 l.divu, 0x0000000c, 0x00000000
    277      1.1  christos 	TEST_INST_I32_I32 l.divu, 0xfffffff4, 0x00000000
    278      1.1  christos 
    279      1.1  christos 	/* Check that range exceptions are triggered.  */
    280      1.1  christos 
    281      1.1  christos 	SET_SPR_SR_FLAGS SPR_SR_OVE, r2, r3
    282      1.1  christos 
    283      1.1  christos 	/* Divide by zero.  This will set the carry flag and trigger an
    284      1.1  christos 	   exception.  */
    285      1.1  christos 	TEST_INST_I32_I32 l.divu, 0x0000000c, 0x00000000
    286      1.1  christos 	TEST_INST_I32_I32 l.divu, 0xfffffff4, 0x00000000
    287      1.1  christos 
    288      1.1  christos 	CLEAR_SPR_SR_FLAGS SPR_SR_OVE, r2, r3
    289      1.1  christos 
    290      1.1  christos 	POP LINK_REGISTER_R9
    291      1.1  christos 	RETURN_TO_LINK_REGISTER_R9
    292