2020-06-13 10:53:11 +02:00
|
|
|
#include <stdint.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <86box/86box.h>
|
|
|
|
|
#include "cpu.h"
|
|
|
|
|
#include <86box/mem.h>
|
|
|
|
|
|
|
|
|
|
#include "codegen.h"
|
|
|
|
|
#include "codegen_accumulate.h"
|
|
|
|
|
|
|
|
|
|
static struct
|
|
|
|
|
{
|
|
|
|
|
int count;
|
|
|
|
|
uintptr_t dest_reg;
|
|
|
|
|
} acc_regs[] =
|
|
|
|
|
{
|
2020-07-12 20:01:16 +02:00
|
|
|
[ACCREG_cycles] = {0, (uintptr_t) &(cycles)}
|
2020-06-13 10:53:11 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void codegen_accumulate(int acc_reg, int delta)
|
|
|
|
|
{
|
|
|
|
|
acc_regs[acc_reg].count += delta;
|
2020-07-12 20:01:16 +02:00
|
|
|
|
2020-07-12 23:51:56 +02:00
|
|
|
if ((acc_reg == ACCREG_cycles) && (delta != 0)) {
|
2020-07-13 19:46:19 +02:00
|
|
|
if (delta == -1) {
|
|
|
|
|
/* -delta = 1 */
|
|
|
|
|
addbyte(0xff); /*inc dword ptr[&acycs]*/
|
|
|
|
|
addbyte(0x05);
|
|
|
|
|
addlong((uint32_t) (uintptr_t) &(acycs));
|
|
|
|
|
} else if (delta == 1) {
|
|
|
|
|
/* -delta = -1 */
|
|
|
|
|
addbyte(0xff); /*dec dword ptr[&acycs]*/
|
|
|
|
|
addbyte(0x0d);
|
|
|
|
|
addlong((uint32_t) (uintptr_t) &(acycs));
|
|
|
|
|
} else {
|
|
|
|
|
addbyte(0x81); /*ADD $acc_regs[c].count,acc_regs[c].dest*/
|
|
|
|
|
addbyte(0x05);
|
|
|
|
|
addlong((uint32_t) (uintptr_t) &(acycs));
|
|
|
|
|
addlong((uintptr_t) -delta);
|
|
|
|
|
}
|
2020-07-12 20:01:16 +02:00
|
|
|
}
|
2020-06-13 10:53:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void codegen_accumulate_flush(void)
|
|
|
|
|
{
|
2020-07-13 19:46:19 +02:00
|
|
|
if (acc_regs[0].count) {
|
|
|
|
|
addbyte(0x81); /*ADD $acc_regs[0].count,acc_regs[0].dest*/
|
|
|
|
|
addbyte(0x05);
|
|
|
|
|
addlong((uint32_t) acc_regs[0].dest_reg);
|
|
|
|
|
addlong(acc_regs[0].count);
|
|
|
|
|
}
|
2020-06-13 10:53:11 +02:00
|
|
|
|
2020-07-13 19:46:19 +02:00
|
|
|
acc_regs[0].count = 0;
|
2020-06-13 10:53:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void codegen_accumulate_reset()
|
|
|
|
|
{
|
2020-07-13 19:46:19 +02:00
|
|
|
acc_regs[0].count = 0;
|
2020-06-13 10:53:11 +02:00
|
|
|
}
|