?? op_helper.c
字號:
if (((int32_t)T0 == INT32_MIN && (int32_t)T1 == (int32_t)-1) || (int32_t)T1 == 0) { T0 = UINT32_MAX * ((uint32_t)T0 >> 31); env->spr[SPR_MQ] = 0; } else { env->spr[SPR_MQ] = T0 % T1; T0 = (int32_t)T0 / (int32_t)T1; }}void do_POWER_divso (void){ if (((int32_t)T0 == INT32_MIN && (int32_t)T1 == (int32_t)-1) || (int32_t)T1 == 0) { T0 = UINT32_MAX * ((uint32_t)T0 >> 31); env->spr[SPR_MQ] = 0; xer_ov = 1; } else { T0 = (int32_t)T0 / (int32_t)T1; env->spr[SPR_MQ] = (int32_t)T0 % (int32_t)T1; xer_ov = 0; } xer_so |= xer_ov;}void do_POWER_dozo (void){ if ((int32_t)T1 > (int32_t)T0) { T2 = T0; T0 = T1 - T0; if (((uint32_t)(~T2) ^ (uint32_t)T1 ^ UINT32_MAX) & ((uint32_t)(~T2) ^ (uint32_t)T0) & (1UL << 31)) { xer_ov = 1; xer_so = 1; } else { xer_ov = 0; } } else { T0 = 0; xer_ov = 0; }}void do_POWER_maskg (void){ uint32_t ret; if ((uint32_t)T0 == (uint32_t)(T1 + 1)) { ret = UINT32_MAX; } else { ret = (UINT32_MAX >> ((uint32_t)T0)) ^ ((UINT32_MAX >> ((uint32_t)T1)) >> 1); if ((uint32_t)T0 > (uint32_t)T1) ret = ~ret; } T0 = ret;}void do_POWER_mulo (void){ uint64_t tmp; tmp = (uint64_t)T0 * (uint64_t)T1; env->spr[SPR_MQ] = tmp >> 32; T0 = tmp; if (tmp >> 32 != ((uint64_t)T0 >> 16) * ((uint64_t)T1 >> 16)) { xer_ov = 1; xer_so = 1; } else { xer_ov = 0; }}#if !defined (CONFIG_USER_ONLY)void do_POWER_rac (void){ mmu_ctx_t ctx; int nb_BATs; /* We don't have to generate many instances of this instruction, * as rac is supervisor only. */ /* XXX: FIX THIS: Pretend we have no BAT */ nb_BATs = env->nb_BATs; env->nb_BATs = 0; if (get_physical_address(env, &ctx, T0, 0, ACCESS_INT) == 0) T0 = ctx.raddr; env->nb_BATs = nb_BATs;}void do_POWER_rfsvc (void){ __do_rfi(env->lr, env->ctr, 0x0000FFFF, 0);}void do_store_hid0_601 (void){ uint32_t hid0; hid0 = env->spr[SPR_HID0]; if ((T0 ^ hid0) & 0x00000008) { /* Change current endianness */ env->hflags &= ~(1 << MSR_LE); env->hflags_nmsr &= ~(1 << MSR_LE); env->hflags_nmsr |= (1 << MSR_LE) & (((T0 >> 3) & 1) << MSR_LE); env->hflags |= env->hflags_nmsr; if (loglevel != 0) { fprintf(logfile, "%s: set endianness to %c => " ADDRX "\n", __func__, T0 & 0x8 ? 'l' : 'b', env->hflags); } } env->spr[SPR_HID0] = T0;}#endif/*****************************************************************************//* 602 specific instructions *//* mfrom is the most crazy instruction ever seen, imho ! *//* Real implementation uses a ROM table. Do the same */#define USE_MFROM_ROM_TABLEvoid do_op_602_mfrom (void){ if (likely(T0 < 602)) {#if defined(USE_MFROM_ROM_TABLE)#include "mfrom_table.c" T0 = mfrom_ROM_table[T0];#else double d; /* Extremly decomposed: * -T0 / 256 * T0 = 256 * log10(10 + 1.0) + 0.5 */ d = T0; d = float64_div(d, 256, &env->fp_status); d = float64_chs(d); d = exp10(d); // XXX: use float emulation function d = float64_add(d, 1.0, &env->fp_status); d = log10(d); // XXX: use float emulation function d = float64_mul(d, 256, &env->fp_status); d = float64_add(d, 0.5, &env->fp_status); T0 = float64_round_to_int(d, &env->fp_status);#endif } else { T0 = 0; }}/*****************************************************************************//* Embedded PowerPC specific helpers */void do_405_check_sat (void){ if (!likely((((uint32_t)T1 ^ (uint32_t)T2) >> 31) || !(((uint32_t)T0 ^ (uint32_t)T2) >> 31))) { /* Saturate result */ if (T2 >> 31) { T0 = INT32_MIN; } else { T0 = INT32_MAX; } }}/* XXX: to be improved to check access rights when in user-mode */void do_load_dcr (void){ target_ulong val; if (unlikely(env->dcr_env == NULL)) { if (loglevel != 0) { fprintf(logfile, "No DCR environment\n"); } do_raise_exception_err(POWERPC_EXCP_PROGRAM, POWERPC_EXCP_INVAL | POWERPC_EXCP_INVAL_INVAL); } else if (unlikely(ppc_dcr_read(env->dcr_env, T0, &val) != 0)) { if (loglevel != 0) { fprintf(logfile, "DCR read error %d %03x\n", (int)T0, (int)T0); } do_raise_exception_err(POWERPC_EXCP_PROGRAM, POWERPC_EXCP_INVAL | POWERPC_EXCP_PRIV_REG); } else { T0 = val; }}void do_store_dcr (void){ if (unlikely(env->dcr_env == NULL)) { if (loglevel != 0) { fprintf(logfile, "No DCR environment\n"); } do_raise_exception_err(POWERPC_EXCP_PROGRAM, POWERPC_EXCP_INVAL | POWERPC_EXCP_INVAL_INVAL); } else if (unlikely(ppc_dcr_write(env->dcr_env, T0, T1) != 0)) { if (loglevel != 0) { fprintf(logfile, "DCR write error %d %03x\n", (int)T0, (int)T0); } do_raise_exception_err(POWERPC_EXCP_PROGRAM, POWERPC_EXCP_INVAL | POWERPC_EXCP_PRIV_REG); }}#if !defined(CONFIG_USER_ONLY)void do_40x_rfci (void){ __do_rfi(env->spr[SPR_40x_SRR2], env->spr[SPR_40x_SRR3], ~((target_ulong)0xFFFF0000), 0);}void do_rfci (void){ __do_rfi(env->spr[SPR_BOOKE_CSRR0], SPR_BOOKE_CSRR1, ~((target_ulong)0x3FFF0000), 0);}void do_rfdi (void){ __do_rfi(env->spr[SPR_BOOKE_DSRR0], SPR_BOOKE_DSRR1, ~((target_ulong)0x3FFF0000), 0);}void do_rfmci (void){ __do_rfi(env->spr[SPR_BOOKE_MCSRR0], SPR_BOOKE_MCSRR1, ~((target_ulong)0x3FFF0000), 0);}void do_load_403_pb (int num){ T0 = env->pb[num];}void do_store_403_pb (int num){ if (likely(env->pb[num] != T0)) { env->pb[num] = T0; /* Should be optimized */ tlb_flush(env, 1); }}#endif/* 440 specific */void do_440_dlmzb (void){ target_ulong mask; int i; i = 1; for (mask = 0xFF000000; mask != 0; mask = mask >> 8) { if ((T0 & mask) == 0) goto done; i++; } for (mask = 0xFF000000; mask != 0; mask = mask >> 8) { if ((T1 & mask) == 0) break; i++; } done: T0 = i;}/* SPE extension helpers *//* Use a table to make this quicker */static uint8_t hbrev[16] = { 0x0, 0x8, 0x4, 0xC, 0x2, 0xA, 0x6, 0xE, 0x1, 0x9, 0x5, 0xD, 0x3, 0xB, 0x7, 0xF,};static always_inline uint8_t byte_reverse (uint8_t val){ return hbrev[val >> 4] | (hbrev[val & 0xF] << 4);}static always_inline uint32_t word_reverse (uint32_t val){ return byte_reverse(val >> 24) | (byte_reverse(val >> 16) << 8) | (byte_reverse(val >> 8) << 16) | (byte_reverse(val) << 24);}#define MASKBITS 16 // Random value - to be fixed (implementation dependant)void do_brinc (void){ uint32_t a, b, d, mask; mask = UINT32_MAX >> (32 - MASKBITS); a = T0 & mask; b = T1 & mask; d = word_reverse(1 + word_reverse(a | ~b)); T0 = (T0 & ~mask) | (d & b);}#define DO_SPE_OP2(name) \void do_ev##name (void) \{ \ T0_64 = ((uint64_t)_do_e##name(T0_64 >> 32, T1_64 >> 32) << 32) | \ (uint64_t)_do_e##name(T0_64, T1_64); \}#define DO_SPE_OP1(name) \void do_ev##name (void) \{ \ T0_64 = ((uint64_t)_do_e##name(T0_64 >> 32) << 32) | \ (uint64_t)_do_e##name(T0_64); \}/* Fixed-point vector arithmetic */static always_inline uint32_t _do_eabs (uint32_t val){ if ((val & 0x80000000) && val != 0x80000000) val -= val; return val;}static always_inline uint32_t _do_eaddw (uint32_t op1, uint32_t op2){ return op1 + op2;}static always_inline int _do_ecntlsw (uint32_t val){ if (val & 0x80000000) return clz32(~val); else return clz32(val);}static always_inline int _do_ecntlzw (uint32_t val){ return clz32(val);}static always_inline uint32_t _do_eneg (uint32_t val){ if (val != 0x80000000) val -= val; return val;}static always_inline uint32_t _do_erlw (uint32_t op1, uint32_t op2){ return rotl32(op1, op2);}static always_inline uint32_t _do_erndw (uint32_t val){ return (val + 0x000080000000) & 0xFFFF0000;}static always_inline uint32_t _do_eslw (uint32_t op1, uint32_t op2){ /* No error here: 6 bits are used */ return op1 << (op2 & 0x3F);}static always_inline int32_t _do_esrws (int32_t op1, uint32_t op2){ /* No error here: 6 bits are used */ return op1 >> (op2 & 0x3F);}static always_inline uint32_t _do_esrwu (uint32_t op1, uint32_t op2){ /* No error here: 6 bits are used */ return op1 >> (op2 & 0x3F);}static always_inline uint32_t _do_esubfw (uint32_t op1, uint32_t op2){ return op2 - op1;}/* evabs */DO_SPE_OP1(abs);/* evaddw */DO_SPE_OP2(addw);/* evcntlsw */DO_SPE_OP1(cntlsw);/* evcntlzw */DO_SPE_OP1(cntlzw);/* evneg */DO_SPE_OP1(neg);/* evrlw */DO_SPE_OP2(rlw);/* evrnd */DO_SPE_OP1(rndw);/* evslw */DO_SPE_OP2(slw);/* evsrws */DO_SPE_OP2(srws);/* evsrwu */DO_SPE_OP2(srwu);/* evsubfw */DO_SPE_OP2(subfw);/* evsel is a little bit more complicated... */static always_inline uint32_t _do_esel (uint32_t op1, uint32_t op2, int n){ if (n) return op1; else return op2;}void do_evsel (void){ T0_64 = ((uint64_t)_do_esel(T0_64 >> 32, T1_64 >> 32, T0 >> 3) << 32) | (uint64_t)_do_esel(T0_64, T1_64, (T0 >> 2) & 1);}/* Fixed-point vector comparisons */#define DO_SPE_CMP(name) \void do_ev##name (void) \{ \ T0 = _do_evcmp_merge((uint64_t)_do_e##name(T0_64 >> 32, \ T1_64 >> 32) << 32, \ _do_e##name(T0_64, T1_64)); \}static always_inline uint32_t _do_evcmp_merge (int t0, int t1){ return (t0 << 3) | (t1 << 2) | ((t0 | t1) << 1) | (t0 & t1);}static always_inline int _do_ecmpeq (uint32_t op1, uint32_t op2){ return op1 == op2 ? 1 : 0;}static always_inline int _do_ecmpgts (int32_t op1, int32_t op2){ return op1 > op2 ? 1 : 0;}static always_inline int _do_ecmpgtu (uint32_t op1, uint32_t op2){ return op1 > op2 ? 1 : 0;}static always_inline int _do_ecmplts (int32_t op1, int32_t op2){ return op1 < op2 ? 1 : 0;}static always_inline int _do_ecmpltu (uint32_t op1, uint32_t op2){ return op1 < op2 ? 1 : 0;}/* evcmpeq */DO_SPE_CMP(cmpeq);/* evcmpgts */DO_SPE_CMP(cmpgts);/* evcmpgtu */DO_SPE_CMP(cmpgtu);/* evcmplts */DO_SPE_CMP(cmplts);/* evcmpltu */DO_SPE_CMP(cmpltu);/* Single precision floating-point conversions from/to integer */static always_inline uint32_t _do_efscfsi (int32_t val){ union { uint32_t u; float32 f; } u; u.f = int32_to_float32(val, &env->spe_status); return u.u;}static always_inline uint32_t _do_efscfui (uint32_t val){ union { uint32_t u; float32 f; } u; u.f = uint32_to_float32(val, &env->spe_status); return u.u;}static always_inline int32_t _do_efsctsi (uint32_t val){ union { int32_t u; float32 f; } u; u.u = val; /* NaN are not treated the same way IEEE 754 does */ if (unlikely(isnan(u.f))) return 0; return float32_to_int32(u.f, &env->spe_status);}static always_inline uint32_t _do_efsctui (uint32_t val){ union { int32_t u; float32 f; } u; u.u = val; /* NaN are not treated the same way IEEE 754 does */ if (unlikely(isnan(u.f))) return 0; return float32_to_uint32(u.f, &env->spe_status);}static always_inline int32_t _do_efsctsiz (uint32_t val){ union { int32_t u; float32 f; } u; u.u = val; /* NaN are not treated the same way IEEE 754 does */ if (unlikely(isnan(u.f))) return 0; return float32_to_int32_round_to_zero(u.f, &env->spe_status);}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -