TriCore RRR1, RRR2 instructions and bugfixes

-----BEGIN PGP SIGNATURE-----
 Version: GnuPG v2
 
 iQIcBAABCgAGBQJU9QpiAAoJEArSxjlracoUHg0P/297yR07ZkBM6BJRz93VhUj7
 ym/XDRnKMlccjRXcWJpEHZzdb0eq4gWfmmGdUjh7dZ7JINFsKTU0ZGYEnK0D9ZLh
 oYmpKG+5b7gvdjKO2OrQ8SZbJY2UfWnB3B1v1L9En13dJ6VKKjhYgjE6+0hs1JzN
 aJIVOqvDkKYxBPtp1qC4bJDzV0wY1r08mZQORVTziZMRkyLdd6HxQxpE93EB6CAm
 MTpXDZqcee+Ht8b3ZQc9R5v8csg2mO4O+JxvYBVOcg8b6PZNXCESEjuPaar0Jfo7
 S3cubh/tam1KG77+R9t/ktd1yLzLAniTSkEaAgq3LEVvB72YaUiOqc/hcNqZBWo+
 OtVgW9dG9ul5Sk68RfsNRql3PsvUQl9Do/UiB/cqOQoDZzDBtbadrl2CznJRpdFP
 QMmQwWpdSbRsCMI5TLtJ6EoVJl9HcV9FpS1ojZGcRuYi0AZIBE1t+kAibylV1Ff7
 oaOZLBxHlSgU58aUgcBD9T3sV1FBcKG6EaYeEzYF8oTaBtGr4w7z+XM9d1NqxROd
 ztrsOwa5OgLnTeChhiAx2gZ9o75Q3aq1F1of6FC2litqDweR9rLWr1qcky+kGhwF
 VCX7tc0QRG4rz8tOH6+aPBGZ9CTfvkOyokuLUrwHQSpI1xqP/hMUa6QdaHwOchgE
 Nch1TIkVVcJL+ij6NGTy
 =AwBl
 -----END PGP SIGNATURE-----

Merge remote-tracking branch 'remotes/bkoppelmann/tags/pull-tricore-20150303' into staging

TriCore RRR1, RRR2 instructions and bugfixes

# gpg: Signature made Tue Mar  3 01:12:02 2015 GMT using RSA key ID 6B69CA14
# gpg: Good signature from "Bastian Koppelmann <kbastian@mail.uni-paderborn.de>"

* remotes/bkoppelmann/tags/pull-tricore-20150303:
  target-tricore: Add instructions of RRR1 opcode format, which have 0xc3 as first opcode
  target-tricore: Add instructions of RRR1 opcode format, which have 0x43 as first opcode
  target-tricore: Add instructions of RRR1 opcode format, which have 0x83 as first opcode
  target-tricore: Add instructions of RRR2 opcode format
  target-tricore: fix msub32_suov return wrong results
  target-tricore: Fix RLC_ADDI, RLC_ADDIH using wrong microcode helper

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
Peter Maydell 2015-03-08 00:16:27 +00:00
commit cff6abd6f2
4 changed files with 1699 additions and 27 deletions

View File

@ -17,9 +17,12 @@
/* Arithmetic */ /* Arithmetic */
DEF_HELPER_3(add_ssov, i32, env, i32, i32) DEF_HELPER_3(add_ssov, i32, env, i32, i32)
DEF_HELPER_3(add64_ssov, i64, env, i64, i64)
DEF_HELPER_3(add_suov, i32, env, i32, i32) DEF_HELPER_3(add_suov, i32, env, i32, i32)
DEF_HELPER_3(add_h_ssov, i32, env, i32, i32) DEF_HELPER_3(add_h_ssov, i32, env, i32, i32)
DEF_HELPER_3(add_h_suov, i32, env, i32, i32) DEF_HELPER_3(add_h_suov, i32, env, i32, i32)
DEF_HELPER_4(addr_h_ssov, i32, env, i64, i32, i32)
DEF_HELPER_4(addsur_h_ssov, i32, env, i64, i32, i32)
DEF_HELPER_3(sub_ssov, i32, env, i32, i32) DEF_HELPER_3(sub_ssov, i32, env, i32, i32)
DEF_HELPER_3(sub_suov, i32, env, i32, i32) DEF_HELPER_3(sub_suov, i32, env, i32, i32)
DEF_HELPER_3(sub_h_ssov, i32, env, i32, i32) DEF_HELPER_3(sub_h_ssov, i32, env, i32, i32)
@ -31,6 +34,9 @@ DEF_HELPER_3(absdif_ssov, i32, env, i32, i32)
DEF_HELPER_4(madd32_ssov, i32, env, i32, i32, i32) DEF_HELPER_4(madd32_ssov, i32, env, i32, i32, i32)
DEF_HELPER_4(madd32_suov, i32, env, i32, i32, i32) DEF_HELPER_4(madd32_suov, i32, env, i32, i32, i32)
DEF_HELPER_4(madd64_ssov, i64, env, i32, i64, i32) DEF_HELPER_4(madd64_ssov, i64, env, i32, i64, i32)
DEF_HELPER_5(madd64_q_ssov, i64, env, i64, i32, i32, i32)
DEF_HELPER_3(madd32_q_add_ssov, i32, env, i64, i64)
DEF_HELPER_5(maddr_q_ssov, i32, env, i32, i32, i32, i32)
DEF_HELPER_4(madd64_suov, i64, env, i32, i64, i32) DEF_HELPER_4(madd64_suov, i64, env, i32, i64, i32)
DEF_HELPER_4(msub32_ssov, i32, env, i32, i32, i32) DEF_HELPER_4(msub32_ssov, i32, env, i32, i32, i32)
DEF_HELPER_4(msub32_suov, i32, env, i32, i32, i32) DEF_HELPER_4(msub32_suov, i32, env, i32, i32, i32)
@ -44,6 +50,9 @@ DEF_HELPER_2(abs_b, i32, env, i32)
DEF_HELPER_2(abs_h, i32, env, i32) DEF_HELPER_2(abs_h, i32, env, i32)
DEF_HELPER_3(absdif_b, i32, env, i32, i32) DEF_HELPER_3(absdif_b, i32, env, i32, i32)
DEF_HELPER_3(absdif_h, i32, env, i32, i32) DEF_HELPER_3(absdif_h, i32, env, i32, i32)
DEF_HELPER_4(addr_h, i32, env, i64, i32, i32)
DEF_HELPER_4(addsur_h, i32, env, i64, i32, i32)
DEF_HELPER_5(maddr_q, i32, env, i32, i32, i32, i32)
DEF_HELPER_3(add_b, i32, env, i32, i32) DEF_HELPER_3(add_b, i32, env, i32, i32)
DEF_HELPER_3(add_h, i32, env, i32, i32) DEF_HELPER_3(add_h, i32, env, i32, i32)
DEF_HELPER_3(sub_b, i32, env, i32, i32) DEF_HELPER_3(sub_b, i32, env, i32, i32)

View File

@ -184,6 +184,31 @@ target_ulong helper_add_ssov(CPUTriCoreState *env, target_ulong r1,
return ssov32(env, result); return ssov32(env, result);
} }
uint64_t helper_add64_ssov(CPUTriCoreState *env, uint64_t r1, uint64_t r2)
{
uint64_t result;
int64_t ovf;
result = r1 + r2;
ovf = (result ^ r1) & ~(r1 ^ r2);
env->PSW_USB_AV = (result ^ result * 2u) >> 32;
env->PSW_USB_SAV |= env->PSW_USB_AV;
if (ovf < 0) {
env->PSW_USB_V = (1 << 31);
env->PSW_USB_SV = (1 << 31);
/* ext_ret > MAX_INT */
if ((int64_t)r1 >= 0) {
result = INT64_MAX;
/* ext_ret < MIN_INT */
} else {
result = INT64_MIN;
}
} else {
env->PSW_USB_V = 0;
}
return result;
}
target_ulong helper_add_h_ssov(CPUTriCoreState *env, target_ulong r1, target_ulong helper_add_h_ssov(CPUTriCoreState *env, target_ulong r1,
target_ulong r2) target_ulong r2)
{ {
@ -194,6 +219,99 @@ target_ulong helper_add_h_ssov(CPUTriCoreState *env, target_ulong r1,
return ssov16(env, ret_hw0, ret_hw1); return ssov16(env, ret_hw0, ret_hw1);
} }
uint32_t helper_addr_h_ssov(CPUTriCoreState *env, uint64_t r1, uint32_t r2_l,
uint32_t r2_h)
{
int64_t mul_res0 = sextract64(r1, 0, 32);
int64_t mul_res1 = sextract64(r1, 32, 32);
int64_t r2_low = sextract64(r2_l, 0, 32);
int64_t r2_high = sextract64(r2_h, 0, 32);
int64_t result0, result1;
uint32_t ovf0, ovf1;
uint32_t avf0, avf1;
ovf0 = ovf1 = 0;
result0 = r2_low + mul_res0 + 0x8000;
result1 = r2_high + mul_res1 + 0x8000;
avf0 = result0 * 2u;
avf0 = result0 ^ avf0;
avf1 = result1 * 2u;
avf1 = result1 ^ avf1;
if (result0 > INT32_MAX) {
ovf0 = (1 << 31);
result0 = INT32_MAX;
} else if (result0 < INT32_MIN) {
ovf0 = (1 << 31);
result0 = INT32_MIN;
}
if (result1 > INT32_MAX) {
ovf1 = (1 << 31);
result1 = INT32_MAX;
} else if (result1 < INT32_MIN) {
ovf1 = (1 << 31);
result1 = INT32_MIN;
}
env->PSW_USB_V = ovf0 | ovf1;
env->PSW_USB_SV |= env->PSW_USB_V;
env->PSW_USB_AV = avf0 | avf1;
env->PSW_USB_SAV |= env->PSW_USB_AV;
return (result1 & 0xffff0000ULL) | ((result0 >> 16) & 0xffffULL);
}
uint32_t helper_addsur_h_ssov(CPUTriCoreState *env, uint64_t r1, uint32_t r2_l,
uint32_t r2_h)
{
int64_t mul_res0 = sextract64(r1, 0, 32);
int64_t mul_res1 = sextract64(r1, 32, 32);
int64_t r2_low = sextract64(r2_l, 0, 32);
int64_t r2_high = sextract64(r2_h, 0, 32);
int64_t result0, result1;
uint32_t ovf0, ovf1;
uint32_t avf0, avf1;
ovf0 = ovf1 = 0;
result0 = r2_low - mul_res0 + 0x8000;
result1 = r2_high + mul_res1 + 0x8000;
avf0 = result0 * 2u;
avf0 = result0 ^ avf0;
avf1 = result1 * 2u;
avf1 = result1 ^ avf1;
if (result0 > INT32_MAX) {
ovf0 = (1 << 31);
result0 = INT32_MAX;
} else if (result0 < INT32_MIN) {
ovf0 = (1 << 31);
result0 = INT32_MIN;
}
if (result1 > INT32_MAX) {
ovf1 = (1 << 31);
result1 = INT32_MAX;
} else if (result1 < INT32_MIN) {
ovf1 = (1 << 31);
result1 = INT32_MIN;
}
env->PSW_USB_V = ovf0 | ovf1;
env->PSW_USB_SV |= env->PSW_USB_V;
env->PSW_USB_AV = avf0 | avf1;
env->PSW_USB_SAV |= env->PSW_USB_AV;
return (result1 & 0xffff0000ULL) | ((result0 >> 16) & 0xffffULL);
}
target_ulong helper_add_suov(CPUTriCoreState *env, target_ulong r1, target_ulong helper_add_suov(CPUTriCoreState *env, target_ulong r1,
target_ulong r2) target_ulong r2)
{ {
@ -403,6 +521,131 @@ uint64_t helper_madd64_ssov(CPUTriCoreState *env, target_ulong r1,
return ret; return ret;
} }
uint32_t
helper_madd32_q_add_ssov(CPUTriCoreState *env, uint64_t r1, uint64_t r2)
{
int64_t result;
result = (r1 + r2);
env->PSW_USB_AV = (result ^ result * 2u);
env->PSW_USB_SAV |= env->PSW_USB_AV;
/* we do the saturation by hand, since we produce an overflow on the host
if the mul before was (0x80000000 * 0x80000000) << 1). If this is the
case, we flip the saturated value. */
if (r2 == 0x8000000000000000LL) {
if (result > 0x7fffffffLL) {
env->PSW_USB_V = (1 << 31);
env->PSW_USB_SV = (1 << 31);
result = INT32_MIN;
} else if (result < -0x80000000LL) {
env->PSW_USB_V = (1 << 31);
env->PSW_USB_SV = (1 << 31);
result = INT32_MAX;
} else {
env->PSW_USB_V = 0;
}
} else {
if (result > 0x7fffffffLL) {
env->PSW_USB_V = (1 << 31);
env->PSW_USB_SV = (1 << 31);
result = INT32_MAX;
} else if (result < -0x80000000LL) {
env->PSW_USB_V = (1 << 31);
env->PSW_USB_SV = (1 << 31);
result = INT32_MIN;
} else {
env->PSW_USB_V = 0;
}
}
return (uint32_t)result;
}
uint64_t helper_madd64_q_ssov(CPUTriCoreState *env, uint64_t r1, uint32_t r2,
uint32_t r3, uint32_t n)
{
int64_t t1 = (int64_t)r1;
int64_t t2 = sextract64(r2, 0, 32);
int64_t t3 = sextract64(r3, 0, 32);
int64_t result, mul;
int64_t ovf;
mul = (t2 * t3) << n;
result = mul + t1;
env->PSW_USB_AV = (result ^ result * 2u) >> 32;
env->PSW_USB_SAV |= env->PSW_USB_AV;
ovf = (result ^ mul) & ~(mul ^ t1);
/* we do the saturation by hand, since we produce an overflow on the host
if the mul was (0x80000000 * 0x80000000) << 1). If this is the
case, we flip the saturated value. */
if ((r2 == 0x80000000) && (r3 == 0x80000000) && (n == 1)) {
if (ovf >= 0) {
env->PSW_USB_V = (1 << 31);
env->PSW_USB_SV = (1 << 31);
/* ext_ret > MAX_INT */
if (mul < 0) {
result = INT64_MAX;
/* ext_ret < MIN_INT */
} else {
result = INT64_MIN;
}
} else {
env->PSW_USB_V = 0;
}
} else {
if (ovf < 0) {
env->PSW_USB_V = (1 << 31);
env->PSW_USB_SV = (1 << 31);
/* ext_ret > MAX_INT */
if (mul >= 0) {
result = INT64_MAX;
/* ext_ret < MIN_INT */
} else {
result = INT64_MIN;
}
} else {
env->PSW_USB_V = 0;
}
}
return (uint64_t)result;
}
uint32_t helper_maddr_q_ssov(CPUTriCoreState *env, uint32_t r1, uint32_t r2,
uint32_t r3, uint32_t n)
{
int64_t t1 = sextract64(r1, 0, 32);
int64_t t2 = sextract64(r2, 0, 32);
int64_t t3 = sextract64(r3, 0, 32);
int64_t mul, ret;
if ((t2 == -0x8000ll) && (t3 == -0x8000ll) && (n == 1)) {
mul = 0x7fffffff;
} else {
mul = (t2 * t3) << n;
}
ret = t1 + mul + 0x8000;
env->PSW_USB_AV = ret ^ ret * 2u;
env->PSW_USB_SAV |= env->PSW_USB_AV;
if (ret > 0x7fffffffll) {
env->PSW_USB_V = (1 << 31);
env->PSW_USB_SV |= env->PSW_USB_V;
ret = INT32_MAX;
} else if (ret < -0x80000000ll) {
env->PSW_USB_V = (1 << 31);
env->PSW_USB_SV |= env->PSW_USB_V;
ret = INT32_MIN;
} else {
env->PSW_USB_V = 0;
}
return ret & 0xffff0000ll;
}
uint64_t helper_madd64_suov(CPUTriCoreState *env, target_ulong r1, uint64_t helper_madd64_suov(CPUTriCoreState *env, target_ulong r1,
uint64_t r2, target_ulong r3) uint64_t r2, target_ulong r3)
{ {
@ -443,13 +686,28 @@ target_ulong helper_msub32_ssov(CPUTriCoreState *env, target_ulong r1,
target_ulong helper_msub32_suov(CPUTriCoreState *env, target_ulong r1, target_ulong helper_msub32_suov(CPUTriCoreState *env, target_ulong r1,
target_ulong r2, target_ulong r3) target_ulong r2, target_ulong r3)
{ {
int64_t t1 = extract64(r1, 0, 32); uint64_t t1 = extract64(r1, 0, 32);
int64_t t2 = extract64(r2, 0, 32); uint64_t t2 = extract64(r2, 0, 32);
int64_t t3 = extract64(r3, 0, 32); uint64_t t3 = extract64(r3, 0, 32);
int64_t result; uint64_t result;
uint64_t mul;
result = t2 - (t1 * t3); mul = (t1 * t3);
return suov32_neg(env, result); result = t2 - mul;
env->PSW_USB_AV = result ^ result * 2u;
env->PSW_USB_SAV |= env->PSW_USB_AV;
/* we calculate ovf by hand here, because the multiplication can overflow on
the host, which would give false results if we compare to less than
zero */
if (mul > t2) {
env->PSW_USB_V = (1 << 31);
env->PSW_USB_SV = (1 << 31);
result = 0;
} else {
env->PSW_USB_V = 0;
}
return result;
} }
uint64_t helper_msub64_ssov(CPUTriCoreState *env, target_ulong r1, uint64_t helper_msub64_ssov(CPUTriCoreState *env, target_ulong r1,
@ -604,6 +862,110 @@ uint32_t helper_absdif_h(CPUTriCoreState *env, target_ulong r1, target_ulong r2)
return ret; return ret;
} }
uint32_t helper_addr_h(CPUTriCoreState *env, uint64_t r1, uint32_t r2_l,
uint32_t r2_h)
{
int64_t mul_res0 = sextract64(r1, 0, 32);
int64_t mul_res1 = sextract64(r1, 32, 32);
int64_t r2_low = sextract64(r2_l, 0, 32);
int64_t r2_high = sextract64(r2_h, 0, 32);
int64_t result0, result1;
uint32_t ovf0, ovf1;
uint32_t avf0, avf1;
ovf0 = ovf1 = 0;
result0 = r2_low + mul_res0 + 0x8000;
result1 = r2_high + mul_res1 + 0x8000;
if ((result0 > INT32_MAX) || (result0 < INT32_MIN)) {
ovf0 = (1 << 31);
}
if ((result1 > INT32_MAX) || (result1 < INT32_MIN)) {
ovf1 = (1 << 31);
}
env->PSW_USB_V = ovf0 | ovf1;
env->PSW_USB_SV |= env->PSW_USB_V;
avf0 = result0 * 2u;
avf0 = result0 ^ avf0;
avf1 = result1 * 2u;
avf1 = result1 ^ avf1;
env->PSW_USB_AV = avf0 | avf1;
env->PSW_USB_SAV |= env->PSW_USB_AV;
return (result1 & 0xffff0000ULL) | ((result0 >> 16) & 0xffffULL);
}
uint32_t helper_addsur_h(CPUTriCoreState *env, uint64_t r1, uint32_t r2_l,
uint32_t r2_h)
{
int64_t mul_res0 = sextract64(r1, 0, 32);
int64_t mul_res1 = sextract64(r1, 32, 32);
int64_t r2_low = sextract64(r2_l, 0, 32);
int64_t r2_high = sextract64(r2_h, 0, 32);
int64_t result0, result1;
uint32_t ovf0, ovf1;
uint32_t avf0, avf1;
ovf0 = ovf1 = 0;
result0 = r2_low - mul_res0 + 0x8000;
result1 = r2_high + mul_res1 + 0x8000;
if ((result0 > INT32_MAX) || (result0 < INT32_MIN)) {
ovf0 = (1 << 31);
}
if ((result1 > INT32_MAX) || (result1 < INT32_MIN)) {
ovf1 = (1 << 31);
}
env->PSW_USB_V = ovf0 | ovf1;
env->PSW_USB_SV |= env->PSW_USB_V;
avf0 = result0 * 2u;
avf0 = result0 ^ avf0;
avf1 = result1 * 2u;
avf1 = result1 ^ avf1;
env->PSW_USB_AV = avf0 | avf1;
env->PSW_USB_SAV |= env->PSW_USB_AV;
return (result1 & 0xffff0000ULL) | ((result0 >> 16) & 0xffffULL);
}
uint32_t helper_maddr_q(CPUTriCoreState *env, uint32_t r1, uint32_t r2,
uint32_t r3, uint32_t n)
{
int64_t t1 = sextract64(r1, 0, 32);
int64_t t2 = sextract64(r2, 0, 32);
int64_t t3 = sextract64(r3, 0, 32);
int64_t mul, ret;
if ((t2 == -0x8000ll) && (t3 == -0x8000ll) && (n == 1)) {
mul = 0x7fffffff;
} else {
mul = (t2 * t3) << n;
}
ret = t1 + mul + 0x8000;
if ((ret > 0x7fffffffll) || (ret < -0x80000000ll)) {
env->PSW_USB_V = (1 << 31);
env->PSW_USB_SV |= env->PSW_USB_V;
} else {
env->PSW_USB_V = 0;
}
env->PSW_USB_AV = ret ^ ret * 2u;
env->PSW_USB_SAV |= env->PSW_USB_AV;
return ret & 0xffff0000ll;
}
uint32_t helper_add_b(CPUTriCoreState *env, target_ulong r1, target_ulong r2) uint32_t helper_add_b(CPUTriCoreState *env, target_ulong r1, target_ulong r2)
{ {
int32_t b, i; int32_t b, i;

File diff suppressed because it is too large Load Diff

View File

@ -1245,10 +1245,10 @@ enum {
OPC2_32_RRR1_MADDS_Q_64_LL = 0x3d, OPC2_32_RRR1_MADDS_Q_64_LL = 0x3d,
OPC2_32_RRR1_MADDS_Q_32_UU = 0x24, OPC2_32_RRR1_MADDS_Q_32_UU = 0x24,
OPC2_32_RRR1_MADDS_Q_64_UU = 0x3c, OPC2_32_RRR1_MADDS_Q_64_UU = 0x3c,
OPC2_32_RRR1_MADDR_H_16_UL = 0x1e, OPC2_32_RRR1_MADDR_H_64_UL = 0x1e,
OPC2_32_RRR1_MADDRS_H_16_UL = 0x3e, OPC2_32_RRR1_MADDRS_H_64_UL = 0x3e,
OPC2_32_RRR1_MADDR_Q_32_L = 0x07, OPC2_32_RRR1_MADDR_Q_32_LL = 0x07,
OPC2_32_RRR1_MADDR_Q_32_U = 0x06, OPC2_32_RRR1_MADDR_Q_32_UU = 0x06,
OPC2_32_RRR1_MADDRS_Q_32_LL = 0x27, OPC2_32_RRR1_MADDRS_Q_32_LL = 0x27,
OPC2_32_RRR1_MADDRS_Q_32_UU = 0x26, OPC2_32_RRR1_MADDRS_Q_32_UU = 0x26,
}; };
@ -1371,7 +1371,7 @@ enum {
OPC2_32_RRR2_MADD_64 = 0x6a, OPC2_32_RRR2_MADD_64 = 0x6a,
OPC2_32_RRR2_MADDS_32 = 0x8a, OPC2_32_RRR2_MADDS_32 = 0x8a,
OPC2_32_RRR2_MADDS_64 = 0xea, OPC2_32_RRR2_MADDS_64 = 0xea,
OPC2_32_RRR2_MADD_U_32 = 0x68, OPC2_32_RRR2_MADD_U_64 = 0x68,
OPC2_32_RRR2_MADDS_U_32 = 0x88, OPC2_32_RRR2_MADDS_U_32 = 0x88,
OPC2_32_RRR2_MADDS_U_64 = 0xe8, OPC2_32_RRR2_MADDS_U_64 = 0xe8,
}; };