--- tme/ic/m68k/m68k-insns-auto.sh 2018/04/24 16:37:52 1.1.1.1 +++ tme/ic/m68k/m68k-insns-auto.sh 2018/04/24 16:39:03 1.1.1.2 @@ -1,6 +1,6 @@ #! /bin/sh -# $Id: m68k-insns-auto.sh,v 1.1.1.1 2018/04/24 16:37:52 root Exp $ +# $Id: m68k-insns-auto.sh,v 1.1.1.2 2018/04/24 16:39:03 root Exp $ # ic/m68k/m68k-insns-auto.sh - automatically generates C code # for many m68k emulation instructions: @@ -48,7 +48,7 @@ done PROG=`basename $0` cat < SHIFTMAX_INT${size}_T" @@ -498,16 +499,17 @@ for size in 8 16 32; do echo " flags |= (flags * TME_M68K_FLAG_X);" echo " res <<= 1;" if test ${name} = asl; then + echo " sign_bits_mask = (tme_uint${size}_t) -1;" echo " if (count != ${size} - 1) {" echo " if (count < ${size}) {" - echo " sign_bits >>= ((${size} - 1) - count);" + echo " sign_bits_mask <<= ((${size} - 1) - count);" echo " }" echo " else {" - echo " sign_bits |= (sign_bits << 1);" - echo " sign_bits &= -2;" + echo " sign_bits ^= !(sign_bits + 1);" echo " }" echo " }" - echo " if ((sign_bits + 1) & sign_bits) {" + echo " sign_bits &= sign_bits_mask;" + echo " if (sign_bits != 0 && sign_bits != sign_bits_mask) {" echo " flags |= TME_M68K_FLAG_V;" echo " }" fi @@ -657,8 +659,6 @@ for size in 8 16 32; do echo " tme_uint32_t addend;" echo "" - echo " TME_M68K_INSN_CANFAULT;" - echo "" echo " /* figure out what direction to move in, and where to start from: */" echo " ea_mode = TME_FIELD_EXTRACTU(TME_M68K_INSN_OPCODE, 3, 3);" echo " direction = 1;" @@ -677,6 +677,9 @@ for size in 8 16 32; do echo "" echo " /* do the transfer: */" echo " mask = TME_M68K_INSN_SPECOP;" + echo " if (mask != 0) {" + echo " TME_M68K_INSN_CANFAULT;" + echo " }" echo " for (bit = 1; bit != 0; bit <<= 1) {" echo " if (mask & bit) {" if test $name = rm; then @@ -1702,9 +1705,9 @@ for _sign in u s; do echo "TME_M68K_INSN(tme_m68k_mul${_sign}${_size})" echo "{" if test $large = 64; then - echo "#ifndef HAVE_UINT${large}_T" + echo "#ifndef TME_HAVE_INT${large}_T" echo " abort();" - echo "#else /* HAVE_UINT${large}_T */" + echo "#else /* TME_HAVE_INT${large}_T */" echo " unsigned int flag_v;" echo " int ireg_dh;" fi @@ -1744,8 +1747,11 @@ for _sign in u s; do echo " if (((tme_int${large}_t) res) < 0) flags |= TME_M68K_FLAG_N;" echo " if (res == 0) flags |= TME_M68K_FLAG_Z;" if test $large = 64; then - echo -n " if (res > 0xffffffff" - if test $_sign = s; then echo -n " || res < -2147483648"; fi + if test $_sign = s; then + echo -n " if (res > 0x7fffffffL || res < ((0L - 0x7fffffffL) - 1L)" + else + echo -n " if (res > 0xffffffffUL" + fi echo ") flags |= flag_v;" fi echo " ic->tme_m68k_ireg_ccr = flags;" @@ -1753,7 +1759,7 @@ for _sign in u s; do echo "" echo " TME_M68K_INSN_OK;" if test $large = 64; then - echo "#endif /* HAVE_UINT${large}_T */" + echo "#endif /* TME_HAVE_INT${large}_T */" fi echo "}" @@ -1762,9 +1768,9 @@ for _sign in u s; do echo "TME_M68K_INSN(tme_m68k_div${_sign}${_size})" echo "{" if test $large = 64; then - echo "#ifndef HAVE_UINT${large}_T" + echo "#ifndef TME_HAVE_INT${large}_T" echo " abort();" - echo "#else /* HAVE_UINT${large}_T */" + echo "#else /* TME_HAVE_INT${large}_T */" echo " int ireg_dr;" fi echo " int ireg_dq;" @@ -1808,13 +1814,13 @@ for _sign in u s; do echo "" echo " /* set the flags and return the quotient and remainder: */" echo " flags = ic->tme_m68k_ireg_ccr & TME_M68K_FLAG_X;" - echo -n " if (quotient > 0xffff" - if test $small = 16; then - if test $_sign = s; then echo -n " || quotient < -32768"; fi - else - echo -n "ffff" - if test $_sign = s; then echo -n " || quotient < -2147483648"; fi - fi + echo -n " if (" + case "${small}${_sign}" in + 16s) echo -n "quotient > 0x7fff || quotient < -32768" ;; + 16u) echo -n "quotient > 0xffff" ;; + 32s) echo -n "quotient > 0x7fffffffL || quotient < ((0L - 0x7fffffffL) - 1L)" ;; + 32u) echo -n "quotient > 0xffffffffUL" ;; + esac echo ") {" echo " flags |= TME_M68K_FLAG_V;" echo " }" @@ -1835,7 +1841,7 @@ for _sign in u s; do echo "" echo " TME_M68K_INSN_OK;" if test $large = 64; then - echo "#endif /* HAVE_UINT${large}_T */" + echo "#endif /* TME_HAVE_INT${large}_T */" fi echo "}"