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