summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/arm/dyncom/arm_dyncom_interpreter.cpp117
-rw-r--r--src/core/arm/interpreter/armemu.cpp14
-rw-r--r--src/core/arm/interpreter/armsupp.cpp8
-rw-r--r--src/core/arm/skyeye_common/armdefs.h2
-rw-r--r--src/core/arm/skyeye_common/armemu.h1
5 files changed, 90 insertions, 52 deletions
diff --git a/src/core/arm/dyncom/arm_dyncom_interpreter.cpp b/src/core/arm/dyncom/arm_dyncom_interpreter.cpp
index 7ba82503d..c5e885bcd 100644
--- a/src/core/arm/dyncom/arm_dyncom_interpreter.cpp
+++ b/src/core/arm/dyncom/arm_dyncom_interpreter.cpp
@@ -930,6 +930,8 @@ typedef struct _smlad_inst {
930 unsigned int Rd; 930 unsigned int Rd;
931 unsigned int Ra; 931 unsigned int Ra;
932 unsigned int Rn; 932 unsigned int Rn;
933 unsigned int op1;
934 unsigned int op2;
933} smlad_inst; 935} smlad_inst;
934 936
935typedef struct _smla_inst { 937typedef struct _smla_inst {
@@ -2313,25 +2315,40 @@ ARM_INST_PTR INTERPRETER_TRANSLATE(smla)(unsigned int inst, int index)
2313 2315
2314 return inst_base; 2316 return inst_base;
2315} 2317}
2316ARM_INST_PTR INTERPRETER_TRANSLATE(smlad)(unsigned int inst, int index){
2317 arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(smlad_inst));
2318 smlad_inst *inst_cream = (smlad_inst *)inst_base->component;
2319 2318
2320 inst_base->cond = BITS(inst, 28, 31); 2319ARM_INST_PTR INTERPRETER_TRANSLATE(smlad)(unsigned int inst, int index)
2321 inst_base->idx = index; 2320{
2322 inst_base->br = NON_BRANCH; 2321 arm_inst* const inst_base = (arm_inst*)AllocBuffer(sizeof(arm_inst) + sizeof(smlad_inst));
2322 smlad_inst* const inst_cream = (smlad_inst*)inst_base->component;
2323
2324 inst_base->cond = BITS(inst, 28, 31);
2325 inst_base->idx = index;
2326 inst_base->br = NON_BRANCH;
2323 inst_base->load_r15 = 0; 2327 inst_base->load_r15 = 0;
2324 2328
2325 inst_cream->m = BIT(inst, 4); 2329 inst_cream->m = BIT(inst, 5);
2326 inst_cream->Rn = BITS(inst, 0, 3); 2330 inst_cream->Rn = BITS(inst, 0, 3);
2327 inst_cream->Rm = BITS(inst, 8, 11); 2331 inst_cream->Rm = BITS(inst, 8, 11);
2328 inst_cream->Rd = BITS(inst, 16, 19); 2332 inst_cream->Rd = BITS(inst, 16, 19);
2329 inst_cream->Ra = BITS(inst, 12, 15); 2333 inst_cream->Ra = BITS(inst, 12, 15);
2334 inst_cream->op1 = BITS(inst, 20, 22);
2335 inst_cream->op2 = BITS(inst, 5, 7);
2330 2336
2331 if (CHECK_RM )
2332 inst_base->load_r15 = 1;
2333 return inst_base; 2337 return inst_base;
2334} 2338}
2339ARM_INST_PTR INTERPRETER_TRANSLATE(smuad)(unsigned int inst, int index)
2340{
2341 return INTERPRETER_TRANSLATE(smlad)(inst, index);
2342}
2343ARM_INST_PTR INTERPRETER_TRANSLATE(smusd)(unsigned int inst, int index)
2344{
2345 return INTERPRETER_TRANSLATE(smlad)(inst, index);
2346}
2347ARM_INST_PTR INTERPRETER_TRANSLATE(smlsd)(unsigned int inst, int index)
2348{
2349 return INTERPRETER_TRANSLATE(smlad)(inst, index);
2350}
2351
2335ARM_INST_PTR INTERPRETER_TRANSLATE(smlal)(unsigned int inst, int index) 2352ARM_INST_PTR INTERPRETER_TRANSLATE(smlal)(unsigned int inst, int index)
2336{ 2353{
2337 arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(umlal_inst)); 2354 arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(umlal_inst));
@@ -2355,12 +2372,10 @@ ARM_INST_PTR INTERPRETER_TRANSLATE(smlal)(unsigned int inst, int index)
2355ARM_INST_PTR INTERPRETER_TRANSLATE(smlalxy)(unsigned int inst, int index) { UNIMPLEMENTED_INSTRUCTION("SMLALXY"); } 2372ARM_INST_PTR INTERPRETER_TRANSLATE(smlalxy)(unsigned int inst, int index) { UNIMPLEMENTED_INSTRUCTION("SMLALXY"); }
2356ARM_INST_PTR INTERPRETER_TRANSLATE(smlald)(unsigned int inst, int index) { UNIMPLEMENTED_INSTRUCTION("SMLALD"); } 2373ARM_INST_PTR INTERPRETER_TRANSLATE(smlald)(unsigned int inst, int index) { UNIMPLEMENTED_INSTRUCTION("SMLALD"); }
2357ARM_INST_PTR INTERPRETER_TRANSLATE(smlaw)(unsigned int inst, int index) { UNIMPLEMENTED_INSTRUCTION("SMLAW"); } 2374ARM_INST_PTR INTERPRETER_TRANSLATE(smlaw)(unsigned int inst, int index) { UNIMPLEMENTED_INSTRUCTION("SMLAW"); }
2358ARM_INST_PTR INTERPRETER_TRANSLATE(smlsd)(unsigned int inst, int index) { UNIMPLEMENTED_INSTRUCTION("SMLSD"); }
2359ARM_INST_PTR INTERPRETER_TRANSLATE(smlsld)(unsigned int inst, int index) { UNIMPLEMENTED_INSTRUCTION("SMLSLD"); } 2375ARM_INST_PTR INTERPRETER_TRANSLATE(smlsld)(unsigned int inst, int index) { UNIMPLEMENTED_INSTRUCTION("SMLSLD"); }
2360ARM_INST_PTR INTERPRETER_TRANSLATE(smmla)(unsigned int inst, int index) { UNIMPLEMENTED_INSTRUCTION("SMMLA"); } 2376ARM_INST_PTR INTERPRETER_TRANSLATE(smmla)(unsigned int inst, int index) { UNIMPLEMENTED_INSTRUCTION("SMMLA"); }
2361ARM_INST_PTR INTERPRETER_TRANSLATE(smmls)(unsigned int inst, int index) { UNIMPLEMENTED_INSTRUCTION("SMMLS"); } 2377ARM_INST_PTR INTERPRETER_TRANSLATE(smmls)(unsigned int inst, int index) { UNIMPLEMENTED_INSTRUCTION("SMMLS"); }
2362ARM_INST_PTR INTERPRETER_TRANSLATE(smmul)(unsigned int inst, int index) { UNIMPLEMENTED_INSTRUCTION("SMMUL"); } 2378ARM_INST_PTR INTERPRETER_TRANSLATE(smmul)(unsigned int inst, int index) { UNIMPLEMENTED_INSTRUCTION("SMMUL"); }
2363ARM_INST_PTR INTERPRETER_TRANSLATE(smuad)(unsigned int inst, int index) { UNIMPLEMENTED_INSTRUCTION("SMUAD"); }
2364ARM_INST_PTR INTERPRETER_TRANSLATE(smul)(unsigned int inst, int index) 2379ARM_INST_PTR INTERPRETER_TRANSLATE(smul)(unsigned int inst, int index)
2365{ 2380{
2366 arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(smul_inst)); 2381 arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(smul_inst));
@@ -2423,7 +2438,6 @@ ARM_INST_PTR INTERPRETER_TRANSLATE(smulw)(unsigned int inst, int index)
2423 inst_base->load_r15 = 1; 2438 inst_base->load_r15 = 1;
2424 return inst_base; 2439 return inst_base;
2425} 2440}
2426ARM_INST_PTR INTERPRETER_TRANSLATE(smusd)(unsigned int inst, int index) { UNIMPLEMENTED_INSTRUCTION("SMUSD"); }
2427ARM_INST_PTR INTERPRETER_TRANSLATE(srs)(unsigned int inst, int index) { UNIMPLEMENTED_INSTRUCTION("SRS"); } 2441ARM_INST_PTR INTERPRETER_TRANSLATE(srs)(unsigned int inst, int index) { UNIMPLEMENTED_INSTRUCTION("SRS"); }
2428ARM_INST_PTR INTERPRETER_TRANSLATE(ssat)(unsigned int inst, int index) 2442ARM_INST_PTR INTERPRETER_TRANSLATE(ssat)(unsigned int inst, int index)
2429{ 2443{
@@ -5382,44 +5396,59 @@ unsigned InterpreterMainLoop(ARMul_State* state) {
5382 FETCH_INST; 5396 FETCH_INST;
5383 GOTO_NEXT_INST; 5397 GOTO_NEXT_INST;
5384 } 5398 }
5399
5385 SMLAD_INST: 5400 SMLAD_INST:
5401 SMLSD_INST:
5402 SMUAD_INST:
5403 SMUSD_INST:
5386 { 5404 {
5387 if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) { 5405 if (inst_base->cond == 0xE || CondPassed(cpu, inst_base->cond)) {
5388 smlad_inst *inst_cream = (smlad_inst *)inst_base->component; 5406 smlad_inst* const inst_cream = (smlad_inst*)inst_base->component;
5389 long long int rm = cpu->Reg[inst_cream->Rm]; 5407 const u8 op2 = inst_cream->op2;
5390 long long int rn = cpu->Reg[inst_cream->Rn];
5391 long long int ra = cpu->Reg[inst_cream->Ra];
5392 5408
5393 // See SMUAD 5409 u32 rm_val = cpu->Reg[inst_cream->Rm];
5394 if(inst_cream->Ra == 15) 5410 const u32 rn_val = cpu->Reg[inst_cream->Rn];
5395 CITRA_IGNORE_EXIT(-1);
5396 int operand2 = (inst_cream->m)? ROTATE_RIGHT_32(rm, 16):rm;
5397 int half_rn, half_operand2;
5398 5411
5399 half_rn = rn & 0xFFFF; 5412 if (inst_cream->m)
5400 half_rn = (half_rn & 0x8000)? (0xFFFF0000|half_rn) : half_rn; 5413 rm_val = (((rm_val & 0xFFFF) << 16) | (rm_val >> 16));
5401 5414
5402 half_operand2 = operand2 & 0xFFFF; 5415 const s16 rm_lo = (rm_val & 0xFFFF);
5403 half_operand2 = (half_operand2 & 0x8000)? (0xFFFF0000|half_operand2) : half_operand2; 5416 const s16 rm_hi = ((rm_val >> 16) & 0xFFFF);
5417 const s16 rn_lo = (rn_val & 0xFFFF);
5418 const s16 rn_hi = ((rn_val >> 16) & 0xFFFF);
5404 5419
5405 long long int product1 = half_rn * half_operand2; 5420 const u32 product1 = (rn_lo * rm_lo);
5421 const u32 product2 = (rn_hi * rm_hi);
5406 5422
5407 half_rn = (rn & 0xFFFF0000) >> 16; 5423 // SMUAD and SMLAD
5408 half_rn = (half_rn & 0x8000)? (0xFFFF0000|half_rn) : half_rn; 5424 if (BIT(op2, 1) == 0) {
5425 RD = (product1 + product2);
5409 5426
5410 half_operand2 = (operand2 & 0xFFFF0000) >> 16; 5427 if (inst_cream->Ra != 15) {
5411 half_operand2 = (half_operand2 & 0x8000)? (0xFFFF0000|half_operand2) : half_operand2; 5428 RD += cpu->Reg[inst_cream->Ra];
5412 5429
5413 long long int product2 = half_rn * half_operand2; 5430 if (ARMul_AddOverflowQ(product1 + product2, cpu->Reg[inst_cream->Ra]))
5431 cpu->Cpsr |= (1 << 27);
5432 }
5414 5433
5415 long long int signed_ra = (ra & 0x80000000)? (0xFFFFFFFF00000000LL) | ra : ra; 5434 if (ARMul_AddOverflowQ(product1, product2))
5416 long long int result = product1 + product2 + signed_ra; 5435 cpu->Cpsr |= (1 << 27);
5417 cpu->Reg[inst_cream->Rd] = result & 0xFFFFFFFF; 5436 }
5437 // SMUSD and SMLSD
5438 else {
5439 RD = (product1 - product2);
5418 5440
5419 // TODO: FIXME should check Signed overflow 5441 if (inst_cream->Ra != 15) {
5442 RD += cpu->Reg[inst_cream->Ra];
5443
5444 if (ARMul_AddOverflowQ(product1 - product2, cpu->Reg[inst_cream->Ra]))
5445 cpu->Cpsr |= (1 << 27);
5446 }
5447 }
5420 } 5448 }
5449
5421 cpu->Reg[15] += GET_INST_SIZE(cpu); 5450 cpu->Reg[15] += GET_INST_SIZE(cpu);
5422 INC_PC(sizeof(umlal_inst)); 5451 INC_PC(sizeof(smlad_inst));
5423 FETCH_INST; 5452 FETCH_INST;
5424 GOTO_NEXT_INST; 5453 GOTO_NEXT_INST;
5425 } 5454 }
@@ -5452,15 +5481,15 @@ unsigned InterpreterMainLoop(ARMul_State* state) {
5452 FETCH_INST; 5481 FETCH_INST;
5453 GOTO_NEXT_INST; 5482 GOTO_NEXT_INST;
5454 } 5483 }
5484
5455 SMLALXY_INST: 5485 SMLALXY_INST:
5456 SMLALD_INST: 5486 SMLALD_INST:
5457 SMLAW_INST: 5487 SMLAW_INST:
5458 SMLSD_INST:
5459 SMLSLD_INST: 5488 SMLSLD_INST:
5460 SMMLA_INST: 5489 SMMLA_INST:
5461 SMMLS_INST: 5490 SMMLS_INST:
5462 SMMUL_INST: 5491 SMMUL_INST:
5463 SMUAD_INST: 5492
5464 SMUL_INST: 5493 SMUL_INST:
5465 { 5494 {
5466 if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) { 5495 if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
@@ -5528,8 +5557,8 @@ unsigned InterpreterMainLoop(ARMul_State* state) {
5528 GOTO_NEXT_INST; 5557 GOTO_NEXT_INST;
5529 } 5558 }
5530 5559
5531 SMUSD_INST:
5532 SRS_INST: 5560 SRS_INST:
5561
5533 SSAT_INST: 5562 SSAT_INST:
5534 { 5563 {
5535 if (inst_base->cond == 0xE || CondPassed(cpu, inst_base->cond)) { 5564 if (inst_base->cond == 0xE || CondPassed(cpu, inst_base->cond)) {
diff --git a/src/core/arm/interpreter/armemu.cpp b/src/core/arm/interpreter/armemu.cpp
index 43b1ba40e..12166bf79 100644
--- a/src/core/arm/interpreter/armemu.cpp
+++ b/src/core/arm/interpreter/armemu.cpp
@@ -6470,17 +6470,23 @@ L_stm_s_takeabort:
6470 6470
6471 if (BITS(12, 15) != 15) { 6471 if (BITS(12, 15) != 15) {
6472 state->Reg[rd_idx] += state->Reg[ra_idx]; 6472 state->Reg[rd_idx] += state->Reg[ra_idx];
6473 ARMul_AddOverflowQ(state, product1 + product2, state->Reg[ra_idx]); 6473 if (ARMul_AddOverflowQ(product1 + product2, state->Reg[ra_idx]))
6474 SETQ;
6474 } 6475 }
6475 6476
6476 ARMul_AddOverflowQ(state, product1, product2); 6477 if (ARMul_AddOverflowQ(product1, product2))
6478 SETQ;
6477 } 6479 }
6478 // SMUSD and SMLSD 6480 // SMUSD and SMLSD
6479 else { 6481 else {
6480 state->Reg[rd_idx] = product1 - product2; 6482 state->Reg[rd_idx] = product1 - product2;
6481 6483
6482 if (BITS(12, 15) != 15) 6484 if (BITS(12, 15) != 15) {
6483 state->Reg[rd_idx] += state->Reg[ra_idx]; 6485 state->Reg[rd_idx] += state->Reg[ra_idx];
6486
6487 if (ARMul_AddOverflowQ(product1 - product2, state->Reg[ra_idx]))
6488 SETQ;
6489 }
6484 } 6490 }
6485 6491
6486 return 1; 6492 return 1;
diff --git a/src/core/arm/interpreter/armsupp.cpp b/src/core/arm/interpreter/armsupp.cpp
index 426b67831..eec34143e 100644
--- a/src/core/arm/interpreter/armsupp.cpp
+++ b/src/core/arm/interpreter/armsupp.cpp
@@ -453,12 +453,14 @@ ARMul_AddOverflow (ARMul_State * state, ARMword a, ARMword b, ARMword result)
453 ASSIGNV (AddOverflow (a, b, result)); 453 ASSIGNV (AddOverflow (a, b, result));
454} 454}
455 455
456/* Assigns the Q flag if the given result is considered an overflow from the addition of a and b */ 456// Returns true if the Q flag should be set as a result of overflow.
457void ARMul_AddOverflowQ(ARMul_State* state, ARMword a, ARMword b) 457bool ARMul_AddOverflowQ(ARMword a, ARMword b)
458{ 458{
459 u32 result = a + b; 459 u32 result = a + b;
460 if (((result ^ a) & (u32)0x80000000) && ((a ^ b) & (u32)0x80000000) == 0) 460 if (((result ^ a) & (u32)0x80000000) && ((a ^ b) & (u32)0x80000000) == 0)
461 SETQ; 461 return true;
462
463 return false;
462} 464}
463 465
464/* Assigns the C flag after an subtraction of a and b to give result. */ 466/* Assigns the C flag after an subtraction of a and b to give result. */
diff --git a/src/core/arm/skyeye_common/armdefs.h b/src/core/arm/skyeye_common/armdefs.h
index 8611d7392..c2c78cd5a 100644
--- a/src/core/arm/skyeye_common/armdefs.h
+++ b/src/core/arm/skyeye_common/armdefs.h
@@ -790,6 +790,8 @@ extern void ARMul_FixSPSR(ARMul_State*, ARMword, ARMword);
790extern void ARMul_ConsolePrint(ARMul_State*, const char*, ...); 790extern void ARMul_ConsolePrint(ARMul_State*, const char*, ...);
791extern void ARMul_SelectProcessor(ARMul_State*, unsigned); 791extern void ARMul_SelectProcessor(ARMul_State*, unsigned);
792 792
793extern bool ARMul_AddOverflowQ(ARMword, ARMword);
794
793extern u8 ARMul_SignedSaturatedAdd8(u8, u8); 795extern u8 ARMul_SignedSaturatedAdd8(u8, u8);
794extern u8 ARMul_SignedSaturatedSub8(u8, u8); 796extern u8 ARMul_SignedSaturatedSub8(u8, u8);
795extern u16 ARMul_SignedSaturatedAdd16(u16, u16); 797extern u16 ARMul_SignedSaturatedAdd16(u16, u16);
diff --git a/src/core/arm/skyeye_common/armemu.h b/src/core/arm/skyeye_common/armemu.h
index 3ea14b5a3..e1b286f0f 100644
--- a/src/core/arm/skyeye_common/armemu.h
+++ b/src/core/arm/skyeye_common/armemu.h
@@ -602,7 +602,6 @@ extern ARMword ARMul_SwitchMode (ARMul_State *, ARMword, ARMword);
602extern void ARMul_MSRCpsr (ARMul_State *, ARMword, ARMword); 602extern void ARMul_MSRCpsr (ARMul_State *, ARMword, ARMword);
603extern void ARMul_SubOverflow (ARMul_State *, ARMword, ARMword, ARMword); 603extern void ARMul_SubOverflow (ARMul_State *, ARMword, ARMword, ARMword);
604extern void ARMul_AddOverflow (ARMul_State *, ARMword, ARMword, ARMword); 604extern void ARMul_AddOverflow (ARMul_State *, ARMword, ARMword, ARMword);
605extern void ARMul_AddOverflowQ(ARMul_State*, ARMword, ARMword);
606extern void ARMul_SubCarry (ARMul_State *, ARMword, ARMword, ARMword); 605extern void ARMul_SubCarry (ARMul_State *, ARMword, ARMword, ARMword);
607extern void ARMul_AddCarry (ARMul_State *, ARMword, ARMword, ARMword); 606extern void ARMul_AddCarry (ARMul_State *, ARMword, ARMword, ARMword);
608extern tdstate ARMul_ThumbDecode (ARMul_State *, ARMword, ARMword, ARMword *); 607extern tdstate ARMul_ThumbDecode (ARMul_State *, ARMword, ARMword, ARMword *);