xref: /freebsd/bin/sh/tests/expansion/arith14.0 (revision 06c3fb2749bda94cb5201f81ffdb8fa6c3161b2e)
1# Check that <</>> use the low bits of the shift count.
2
3if [ $((1<<16<<16)) = 0 ]; then
4	width=32
5elif [ $((1<<32<<32)) = 0 ]; then
6	width=64
7elif [ $((1<<64<<64)) = 0 ]; then
8	width=128
9elif [ $((1<<64>>64)) = 1 ]; then
10	# Integers are wider than 128 bits; assume arbitrary precision.
11	# Nothing to test here.
12	exit 0
13else
14	echo "Cannot determine integer width"
15	exit 2
16fi
17
18twowidth=$((width * 2))
19j=43 k=$((1 << (width - 2))) r=0
20
21i=0
22while [ $i -lt $twowidth ]; do
23	if [ "$((j << i))" != "$((j << (i + width)))" ]; then
24		echo "Problem with $j << $i"
25		r=2
26	fi
27	i=$((i + 1))
28done
29
30i=0
31while [ $i -lt $twowidth ]; do
32	if [ "$((k >> i))" != "$((k >> (i + width)))" ]; then
33		echo "Problem with $k >> $i"
34		r=2
35	fi
36	i=$((i + 1))
37done
38
39exit $r
40