#!/bin/sh

set -e

printf "%s\n" '$Id: alltests 34871 2010-02-03 15:21:02Z vinc17/ypig $'

: ${CC:="gcc -Wall -O3 -march=native -std=c99"}

cmdarg()
{
  printf "\n==> %s\n" "$*"
  cmd="./$1"
  shift
  "$cmd" "$@" > alltests-out
  perl -pi -e "s/^Precision $p\n//" alltests-out
}

cmpres()
{
  ctr=$((ctr+1))
  if [ $p -gt 2 ] && cmp -s alltests-out alltests-out-$ctr; then
    printf "Same result as in precision %d\n" $((p-1))
    rm alltests-out
  else
    cat alltests-out
    mv alltests-out alltests-out-$ctr
  fi
}

minasm()
{
  nr=$1
  shift
  cmdarg minasm-sipe$nr "$@"
  cmpres
  cmdarg minasm-mpfr$nr "$@" $p
  diff -u alltests-out alltests-out-$ctr
  printf "Same result as with SIPE\n"
  rm alltests-out
}

$CC minasm.c -o minasm-mpfr3 -DNR=3 -DMPFR -lmpfr
$CC minasm.c -o minasm-mpfr4 -DNR=4 -DMPFR -lmpfr
for p in `seq 2 12`
do
  printf "\n*** Precision $p ***\n"
  ctr=0
  $CC minasm.c -o minasm-sipe3 -DNR=3 -DSIPE=$p
  $CC minasm.c -o minasm-sipe4 -DNR=4 -DSIPE=$p
  minasm 3 1 2 6
  minasm 4 1 4 6
  minasm 4 1 6 5
  if [ $p -le 3 ]; then nr=4; else nr=3; fi
  $CC depth4.c -o depth4-mpfr -DNR=$nr -DMPFR -lmpfr
  cmdarg depth4-mpfr $p
  cmpres
done

rm -f minasm-mpfr* minasm-sipe* depth4-mpfr alltests-out-*
printf "\nOK\n"
