diff options
| author | 2015-01-02 18:21:45 -0500 | |
|---|---|---|
| committer | 2015-01-02 18:29:30 -0500 | |
| commit | 3337b846204c3d18fde4e28ad1558f5e73532ccc (patch) | |
| tree | 32689d9d8e3c8cb811682c9b025370fa0c332844 /src/core/arm/dyncom | |
| parent | Merge pull request #382 from lioncash/sx (diff) | |
| download | yuzu-3337b846204c3d18fde4e28ad1558f5e73532ccc.tar.gz yuzu-3337b846204c3d18fde4e28ad1558f5e73532ccc.tar.xz yuzu-3337b846204c3d18fde4e28ad1558f5e73532ccc.zip | |
dyncom: Implement SMLAD/SMUAD/SMLSD/SMUSD
Diffstat (limited to 'src/core/arm/dyncom')
| -rw-r--r-- | src/core/arm/dyncom/arm_dyncom_interpreter.cpp | 117 |
1 files changed, 73 insertions, 44 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 | ||
| 935 | typedef struct _smla_inst { | 937 | typedef 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 | } |
| 2316 | ARM_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); | 2319 | ARM_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 | } |
| 2339 | ARM_INST_PTR INTERPRETER_TRANSLATE(smuad)(unsigned int inst, int index) | ||
| 2340 | { | ||
| 2341 | return INTERPRETER_TRANSLATE(smlad)(inst, index); | ||
| 2342 | } | ||
| 2343 | ARM_INST_PTR INTERPRETER_TRANSLATE(smusd)(unsigned int inst, int index) | ||
| 2344 | { | ||
| 2345 | return INTERPRETER_TRANSLATE(smlad)(inst, index); | ||
| 2346 | } | ||
| 2347 | ARM_INST_PTR INTERPRETER_TRANSLATE(smlsd)(unsigned int inst, int index) | ||
| 2348 | { | ||
| 2349 | return INTERPRETER_TRANSLATE(smlad)(inst, index); | ||
| 2350 | } | ||
| 2351 | |||
| 2335 | ARM_INST_PTR INTERPRETER_TRANSLATE(smlal)(unsigned int inst, int index) | 2352 | ARM_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) | |||
| 2355 | ARM_INST_PTR INTERPRETER_TRANSLATE(smlalxy)(unsigned int inst, int index) { UNIMPLEMENTED_INSTRUCTION("SMLALXY"); } | 2372 | ARM_INST_PTR INTERPRETER_TRANSLATE(smlalxy)(unsigned int inst, int index) { UNIMPLEMENTED_INSTRUCTION("SMLALXY"); } |
| 2356 | ARM_INST_PTR INTERPRETER_TRANSLATE(smlald)(unsigned int inst, int index) { UNIMPLEMENTED_INSTRUCTION("SMLALD"); } | 2373 | ARM_INST_PTR INTERPRETER_TRANSLATE(smlald)(unsigned int inst, int index) { UNIMPLEMENTED_INSTRUCTION("SMLALD"); } |
| 2357 | ARM_INST_PTR INTERPRETER_TRANSLATE(smlaw)(unsigned int inst, int index) { UNIMPLEMENTED_INSTRUCTION("SMLAW"); } | 2374 | ARM_INST_PTR INTERPRETER_TRANSLATE(smlaw)(unsigned int inst, int index) { UNIMPLEMENTED_INSTRUCTION("SMLAW"); } |
| 2358 | ARM_INST_PTR INTERPRETER_TRANSLATE(smlsd)(unsigned int inst, int index) { UNIMPLEMENTED_INSTRUCTION("SMLSD"); } | ||
| 2359 | ARM_INST_PTR INTERPRETER_TRANSLATE(smlsld)(unsigned int inst, int index) { UNIMPLEMENTED_INSTRUCTION("SMLSLD"); } | 2375 | ARM_INST_PTR INTERPRETER_TRANSLATE(smlsld)(unsigned int inst, int index) { UNIMPLEMENTED_INSTRUCTION("SMLSLD"); } |
| 2360 | ARM_INST_PTR INTERPRETER_TRANSLATE(smmla)(unsigned int inst, int index) { UNIMPLEMENTED_INSTRUCTION("SMMLA"); } | 2376 | ARM_INST_PTR INTERPRETER_TRANSLATE(smmla)(unsigned int inst, int index) { UNIMPLEMENTED_INSTRUCTION("SMMLA"); } |
| 2361 | ARM_INST_PTR INTERPRETER_TRANSLATE(smmls)(unsigned int inst, int index) { UNIMPLEMENTED_INSTRUCTION("SMMLS"); } | 2377 | ARM_INST_PTR INTERPRETER_TRANSLATE(smmls)(unsigned int inst, int index) { UNIMPLEMENTED_INSTRUCTION("SMMLS"); } |
| 2362 | ARM_INST_PTR INTERPRETER_TRANSLATE(smmul)(unsigned int inst, int index) { UNIMPLEMENTED_INSTRUCTION("SMMUL"); } | 2378 | ARM_INST_PTR INTERPRETER_TRANSLATE(smmul)(unsigned int inst, int index) { UNIMPLEMENTED_INSTRUCTION("SMMUL"); } |
| 2363 | ARM_INST_PTR INTERPRETER_TRANSLATE(smuad)(unsigned int inst, int index) { UNIMPLEMENTED_INSTRUCTION("SMUAD"); } | ||
| 2364 | ARM_INST_PTR INTERPRETER_TRANSLATE(smul)(unsigned int inst, int index) | 2379 | ARM_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 | } |
| 2426 | ARM_INST_PTR INTERPRETER_TRANSLATE(smusd)(unsigned int inst, int index) { UNIMPLEMENTED_INSTRUCTION("SMUSD"); } | ||
| 2427 | ARM_INST_PTR INTERPRETER_TRANSLATE(srs)(unsigned int inst, int index) { UNIMPLEMENTED_INSTRUCTION("SRS"); } | 2441 | ARM_INST_PTR INTERPRETER_TRANSLATE(srs)(unsigned int inst, int index) { UNIMPLEMENTED_INSTRUCTION("SRS"); } |
| 2428 | ARM_INST_PTR INTERPRETER_TRANSLATE(ssat)(unsigned int inst, int index) | 2442 | ARM_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)) { |