|
| 1 | +# See LICENSE for license details. |
| 2 | + |
| 3 | +#***************************************************************************** |
| 4 | +# psshl_hs.S |
| 5 | +#----------------------------------------------------------------------------- |
| 6 | +# |
| 7 | +# Test psshl.hs instruction (packed saturating shift left halfword). |
| 8 | +# Bidirectional saturating shift on each 16-bit element: |
| 9 | +# positive shamt = left shift with saturation, negative shamt = right shift (logical). |
| 10 | +# |
| 11 | + |
| 12 | +#include "riscv_test.h" |
| 13 | +#include "test_macros.h" |
| 14 | + |
| 15 | +RVTEST_RV32U |
| 16 | +RVTEST_CODE_BEGIN |
| 17 | + |
| 18 | + #------------------------------------------------------------- |
| 19 | + # Arithmetic tests |
| 20 | + #------------------------------------------------------------- |
| 21 | + |
| 22 | + # psshl.hs rd, rs1, rs2 |
| 23 | + # For each 16-bit element: |
| 24 | + # If rs2[7:0] >= 0: left shift with saturation to 16-bit max |
| 25 | + # If rs2[7:0] < 0: right shift logical |
| 26 | + |
| 27 | + # Test case 1: Left shift without saturation |
| 28 | + # rs1 = 0x00050005, rs2 = 0x00000002 (shift left by 2) |
| 29 | + # Expected: 0x00140014 (5 << 2 = 20 in each halfword) |
| 30 | + TEST_RR_OP( 2, psshl.hs, 0x00140014, 0x00050005, 0x00000002 ); |
| 31 | + |
| 32 | + # Test case 2: Left shift with saturation |
| 33 | + # rs1 = 0x40004000, rs2 = 0x00000002 (shift left by 2) |
| 34 | + # Expected: 0xFFFFFFFF (saturated to 0xFFFF in each halfword) |
| 35 | + TEST_RR_OP( 3, psshl.hs, 0xFFFFFFFF, 0x40004000, 0x00000002 ); |
| 36 | + |
| 37 | + # Test case 3: Left shift by 0 |
| 38 | + # rs1 = 0x12345678, rs2 = 0x00000000 |
| 39 | + # Expected: 0x12345678 (no change) |
| 40 | + TEST_RR_OP( 4, psshl.hs, 0x12345678, 0x12345678, 0x00000000 ); |
| 41 | + |
| 42 | + # Test case 4: Left shift by large amount (>= 16) |
| 43 | + # rs1 = 0x00010001, rs2 = 0x00000010 (shift left by 16) |
| 44 | + # Expected: 0x00000000 (result is 0 in each halfword) |
| 45 | + TEST_RR_OP( 5, psshl.hs, 0x00000000, 0x00010001, 0x00000010 ); |
| 46 | + |
| 47 | + # Test case 5: Right shift (negative shamt) |
| 48 | + # rs1 = 0x80008000, rs2 = 0xFFFFFFFC (shift right by 4) |
| 49 | + # Expected: 0x08000800 (logical right shift in each halfword) |
| 50 | + TEST_RR_OP( 6, psshl.hs, 0x08000800, 0x80008000, 0xFFFFFFFC ); |
| 51 | + |
| 52 | + # Test case 6: Right shift by large negative amount (<= -16) |
| 53 | + # rs1 = 0xFFFFFFFF, rs2 = 0xFFFFFFF0 (shift right by 16) |
| 54 | + # Expected: 0x00000000 |
| 55 | + TEST_RR_OP( 7, psshl.hs, 0x00000000, 0xFFFFFFFF, 0xFFFFFFF0 ); |
| 56 | + |
| 57 | + # Test case 7: Right shift by -1 |
| 58 | + # rs1 = 0x12345678, rs2 = 0xFFFFFFFF (shift right by 1) |
| 59 | + # Expected: 0x091A2B3C |
| 60 | + TEST_RR_OP( 8, psshl.hs, 0x091A2B3C, 0x12345678, 0xFFFFFFFF ); |
| 61 | + |
| 62 | + # Test case 8: 0x7FFF << 1 = 0xFFFE in zero-extended 32-bit, no unsigned 16-bit saturation |
| 63 | + # rs1 = 0x7FFF7FFF, rs2 = 0x00000001 (shift left by 1) -> 0xFFFEFFFE |
| 64 | + TEST_RR_OP( 9, psshl.hs, 0xFFFEFFFE, 0x7FFF7FFF, 0x00000001 ); |
| 65 | + |
| 66 | + # Test case 9: Zero shifted |
| 67 | + # rs1 = 0x00000000, rs2 = 0x00000005 |
| 68 | + # Expected: 0x00000000 |
| 69 | + TEST_RR_OP( 10, psshl.hs, 0x00000000, 0x00000000, 0x00000005 ); |
| 70 | + |
| 71 | + # Test case 10: Mixed values |
| 72 | + # rs1 = 0x0001FFFF, rs2 = 0x00000001 (shift left by 1) |
| 73 | + # Expected: 0x0002FFFF (0x0001 << 1 = 0x0002, 0xFFFF saturates to 0xFFFF) |
| 74 | + TEST_RR_OP( 11, psshl.hs, 0x0002FFFF, 0x0001FFFF, 0x00000001 ); |
| 75 | + |
| 76 | + TEST_PASSFAIL |
| 77 | + |
| 78 | +RVTEST_CODE_END |
| 79 | + |
| 80 | + .data |
| 81 | +RVTEST_DATA_BEGIN |
| 82 | + |
| 83 | + TEST_DATA |
| 84 | + |
| 85 | +RVTEST_DATA_END |
| 86 | + |
| 87 | + |
0 commit comments