1270029Sjilles# $FreeBSD: releng/11.0/bin/sh/tests/expansion/arith14.0 270029 2014-08-15 22:36:41Z jilles $
2270029Sjilles# Check that <</>> use the low bits of the shift count.
3270029Sjilles
4270029Sjillesif [ $((1<<16<<16)) = 0 ]; then
5270029Sjilles	width=32
6270029Sjilleselif [ $((1<<32<<32)) = 0 ]; then
7270029Sjilles	width=64
8270029Sjilleselif [ $((1<<64<<64)) = 0 ]; then
9270029Sjilles	width=128
10270029Sjilleselif [ $((1<<64>>64)) = 1 ]; then
11270029Sjilles	# Integers are wider than 128 bits; assume arbitrary precision.
12270029Sjilles	# Nothing to test here.
13270029Sjilles	exit 0
14270029Sjilleselse
15270029Sjilles	echo "Cannot determine integer width"
16270029Sjilles	exit 2
17270029Sjillesfi
18270029Sjilles
19270029Sjillestwowidth=$((width * 2))
20270029Sjillesj=43 k=$((1 << (width - 2))) r=0
21270029Sjilles
22270029Sjillesi=0
23270029Sjilleswhile [ $i -lt $twowidth ]; do
24270029Sjilles	if [ "$((j << i))" != "$((j << (i + width)))" ]; then
25270029Sjilles		echo "Problem with $j << $i"
26270029Sjilles		r=2
27270029Sjilles	fi
28270029Sjilles	i=$((i + 1))
29270029Sjillesdone
30270029Sjilles
31270029Sjillesi=0
32270029Sjilleswhile [ $i -lt $twowidth ]; do
33270029Sjilles	if [ "$((k >> i))" != "$((k >> (i + width)))" ]; then
34270029Sjilles		echo "Problem with $k >> $i"
35270029Sjilles		r=2
36270029Sjilles	fi
37270029Sjilles	i=$((i + 1))
38270029Sjillesdone
39270029Sjilles
40270029Sjillesexit $r
41