/* Simulator instruction semantics for frvbf.
THIS FILE IS MACHINE GENERATED WITH CGEN.
Copyright 1996-2022 Free Software Foundation, Inc.
This file is part of the GNU simulators.
This file is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
It is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, see .
*/
#define WANT_CPU frvbf
#define WANT_CPU_FRVBF
#include "sim-main.h"
#include "cgen-mem.h"
#include "cgen-ops.h"
#undef GET_ATTR
#define GET_ATTR(cpu, num, attr) CGEN_ATTR_VALUE (NULL, abuf->idesc->attrs, CGEN_INSN_##attr)
/* This is used so that we can compile two copies of the semantic code,
one with full feature support and one without that runs fast(er).
FAST_P, when desired, is defined on the command line, -DFAST_P=1. */
#if FAST_P
#define SEM_FN_NAME(cpu,fn) XCONCAT3 (cpu,_semf_,fn)
#undef CGEN_TRACE_RESULT
#define CGEN_TRACE_RESULT(cpu, abuf, name, type, val)
#else
#define SEM_FN_NAME(cpu,fn) XCONCAT3 (cpu,_sem_,fn)
#endif
/* x-invalid: --invalid-- */
static SEM_PC
SEM_FN_NAME (frvbf,x_invalid) (SIM_CPU *current_cpu, SEM_ARG sem_arg)
{
#define FLD(f) abuf->fields.sfmt_empty.f
ARGBUF *abuf = SEM_ARGBUF (sem_arg);
int UNUSED written = 0;
IADDR UNUSED pc = abuf->addr;
SEM_PC vpc = SEM_NEXT_VPC (sem_arg, pc, 0);
{
/* Update the recorded pc in the cpu state struct.
Only necessary for WITH_SCACHE case, but to avoid the
conditional compilation .... */
SET_H_PC (pc);
/* Virtual insns have zero size. Overwrite vpc with address of next insn
using the default-insn-bitsize spec. When executing insns in parallel
we may want to queue the fault and continue execution. */
vpc = SEM_NEXT_VPC (sem_arg, pc, 4);
vpc = sim_engine_invalid_insn (current_cpu, pc, vpc);
}
return vpc;
#undef FLD
}
/* x-after: --after-- */
static SEM_PC
SEM_FN_NAME (frvbf,x_after) (SIM_CPU *current_cpu, SEM_ARG sem_arg)
{
#define FLD(f) abuf->fields.sfmt_empty.f
ARGBUF *abuf = SEM_ARGBUF (sem_arg);
int UNUSED written = 0;
IADDR UNUSED pc = abuf->addr;
SEM_PC vpc = SEM_NEXT_VPC (sem_arg, pc, 0);
{
#if WITH_SCACHE_PBB_FRVBF
frvbf_pbb_after (current_cpu, sem_arg);
#endif
}
return vpc;
#undef FLD
}
/* x-before: --before-- */
static SEM_PC
SEM_FN_NAME (frvbf,x_before) (SIM_CPU *current_cpu, SEM_ARG sem_arg)
{
#define FLD(f) abuf->fields.sfmt_empty.f
ARGBUF *abuf = SEM_ARGBUF (sem_arg);
int UNUSED written = 0;
IADDR UNUSED pc = abuf->addr;
SEM_PC vpc = SEM_NEXT_VPC (sem_arg, pc, 0);
{
#if WITH_SCACHE_PBB_FRVBF
frvbf_pbb_before (current_cpu, sem_arg);
#endif
}
return vpc;
#undef FLD
}
/* x-cti-chain: --cti-chain-- */
static SEM_PC
SEM_FN_NAME (frvbf,x_cti_chain) (SIM_CPU *current_cpu, SEM_ARG sem_arg)
{
#define FLD(f) abuf->fields.sfmt_empty.f
ARGBUF *abuf = SEM_ARGBUF (sem_arg);
int UNUSED written = 0;
IADDR UNUSED pc = abuf->addr;
SEM_PC vpc = SEM_NEXT_VPC (sem_arg, pc, 0);
{
#if WITH_SCACHE_PBB_FRVBF
#ifdef DEFINE_SWITCH
vpc = frvbf_pbb_cti_chain (current_cpu, sem_arg,
pbb_br_type, pbb_br_npc);
BREAK (sem);
#else
/* FIXME: Allow provision of explicit ifmt spec in insn spec. */
vpc = frvbf_pbb_cti_chain (current_cpu, sem_arg,
CPU_PBB_BR_TYPE (current_cpu),
CPU_PBB_BR_NPC (current_cpu));
#endif
#endif
}
return vpc;
#undef FLD
}
/* x-chain: --chain-- */
static SEM_PC
SEM_FN_NAME (frvbf,x_chain) (SIM_CPU *current_cpu, SEM_ARG sem_arg)
{
#define FLD(f) abuf->fields.sfmt_empty.f
ARGBUF *abuf = SEM_ARGBUF (sem_arg);
int UNUSED written = 0;
IADDR UNUSED pc = abuf->addr;
SEM_PC vpc = SEM_NEXT_VPC (sem_arg, pc, 0);
{
#if WITH_SCACHE_PBB_FRVBF
vpc = frvbf_pbb_chain (current_cpu, sem_arg);
#ifdef DEFINE_SWITCH
BREAK (sem);
#endif
#endif
}
return vpc;
#undef FLD
}
/* x-begin: --begin-- */
static SEM_PC
SEM_FN_NAME (frvbf,x_begin) (SIM_CPU *current_cpu, SEM_ARG sem_arg)
{
#define FLD(f) abuf->fields.sfmt_empty.f
ARGBUF *abuf = SEM_ARGBUF (sem_arg);
int UNUSED written = 0;
IADDR UNUSED pc = abuf->addr;
SEM_PC vpc = SEM_NEXT_VPC (sem_arg, pc, 0);
{
#if WITH_SCACHE_PBB_FRVBF
#if defined DEFINE_SWITCH || defined FAST_P
/* In the switch case FAST_P is a constant, allowing several optimizations
in any called inline functions. */
vpc = frvbf_pbb_begin (current_cpu, FAST_P);
#else
#if 0 /* cgen engine can't handle dynamic fast/full switching yet. */
vpc = frvbf_pbb_begin (current_cpu, STATE_RUN_FAST_P (CPU_STATE (current_cpu)));
#else
vpc = frvbf_pbb_begin (current_cpu, 0);
#endif
#endif
#endif
}
return vpc;
#undef FLD
}
/* add: add$pack $GRi,$GRj,$GRk */
static SEM_PC
SEM_FN_NAME (frvbf,add) (SIM_CPU *current_cpu, SEM_ARG sem_arg)
{
#define FLD(f) abuf->fields.sfmt_addcc.f
ARGBUF *abuf = SEM_ARGBUF (sem_arg);
int UNUSED written = 0;
IADDR UNUSED pc = abuf->addr;
SEM_PC vpc = SEM_NEXT_VPC (sem_arg, pc, 4);
{
SI opval = ADDSI (GET_H_GR (FLD (f_GRi)), GET_H_GR (FLD (f_GRj)));
sim_queue_fn_si_write (current_cpu, frvbf_h_gr_set, FLD (f_GRk), opval);
CGEN_TRACE_RESULT (current_cpu, abuf, "gr", 'x', opval);
}
return vpc;
#undef FLD
}
/* sub: sub$pack $GRi,$GRj,$GRk */
static SEM_PC
SEM_FN_NAME (frvbf,sub) (SIM_CPU *current_cpu, SEM_ARG sem_arg)
{
#define FLD(f) abuf->fields.sfmt_addcc.f
ARGBUF *abuf = SEM_ARGBUF (sem_arg);
int UNUSED written = 0;
IADDR UNUSED pc = abuf->addr;
SEM_PC vpc = SEM_NEXT_VPC (sem_arg, pc, 4);
{
SI opval = SUBSI (GET_H_GR (FLD (f_GRi)), GET_H_GR (FLD (f_GRj)));
sim_queue_fn_si_write (current_cpu, frvbf_h_gr_set, FLD (f_GRk), opval);
CGEN_TRACE_RESULT (current_cpu, abuf, "gr", 'x', opval);
}
return vpc;
#undef FLD
}
/* and: and$pack $GRi,$GRj,$GRk */
static SEM_PC
SEM_FN_NAME (frvbf,and) (SIM_CPU *current_cpu, SEM_ARG sem_arg)
{
#define FLD(f) abuf->fields.sfmt_addcc.f
ARGBUF *abuf = SEM_ARGBUF (sem_arg);
int UNUSED written = 0;
IADDR UNUSED pc = abuf->addr;
SEM_PC vpc = SEM_NEXT_VPC (sem_arg, pc, 4);
{
SI opval = ANDSI (GET_H_GR (FLD (f_GRi)), GET_H_GR (FLD (f_GRj)));
sim_queue_fn_si_write (current_cpu, frvbf_h_gr_set, FLD (f_GRk), opval);
CGEN_TRACE_RESULT (current_cpu, abuf, "gr", 'x', opval);
}
return vpc;
#undef FLD
}
/* or: or$pack $GRi,$GRj,$GRk */
static SEM_PC
SEM_FN_NAME (frvbf,or) (SIM_CPU *current_cpu, SEM_ARG sem_arg)
{
#define FLD(f) abuf->fields.sfmt_addcc.f
ARGBUF *abuf = SEM_ARGBUF (sem_arg);
int UNUSED written = 0;
IADDR UNUSED pc = abuf->addr;
SEM_PC vpc = SEM_NEXT_VPC (sem_arg, pc, 4);
{
SI opval = ORSI (GET_H_GR (FLD (f_GRi)), GET_H_GR (FLD (f_GRj)));
sim_queue_fn_si_write (current_cpu, frvbf_h_gr_set, FLD (f_GRk), opval);
CGEN_TRACE_RESULT (current_cpu, abuf, "gr", 'x', opval);
}
return vpc;
#undef FLD
}
/* xor: xor$pack $GRi,$GRj,$GRk */
static SEM_PC
SEM_FN_NAME (frvbf,xor) (SIM_CPU *current_cpu, SEM_ARG sem_arg)
{
#define FLD(f) abuf->fields.sfmt_addcc.f
ARGBUF *abuf = SEM_ARGBUF (sem_arg);
int UNUSED written = 0;
IADDR UNUSED pc = abuf->addr;
SEM_PC vpc = SEM_NEXT_VPC (sem_arg, pc, 4);
{
SI opval = XORSI (GET_H_GR (FLD (f_GRi)), GET_H_GR (FLD (f_GRj)));
sim_queue_fn_si_write (current_cpu, frvbf_h_gr_set, FLD (f_GRk), opval);
CGEN_TRACE_RESULT (current_cpu, abuf, "gr", 'x', opval);
}
return vpc;
#undef FLD
}
/* not: not$pack $GRj,$GRk */
static SEM_PC
SEM_FN_NAME (frvbf,not) (SIM_CPU *current_cpu, SEM_ARG sem_arg)
{
#define FLD(f) abuf->fields.sfmt_scutss.f
ARGBUF *abuf = SEM_ARGBUF (sem_arg);
int UNUSED written = 0;
IADDR UNUSED pc = abuf->addr;
SEM_PC vpc = SEM_NEXT_VPC (sem_arg, pc, 4);
{
SI opval = INVSI (GET_H_GR (FLD (f_GRj)));
sim_queue_fn_si_write (current_cpu, frvbf_h_gr_set, FLD (f_GRk), opval);
CGEN_TRACE_RESULT (current_cpu, abuf, "gr", 'x', opval);
}
return vpc;
#undef FLD
}
/* sdiv: sdiv$pack $GRi,$GRj,$GRk */
static SEM_PC
SEM_FN_NAME (frvbf,sdiv) (SIM_CPU *current_cpu, SEM_ARG sem_arg)
{
#define FLD(f) abuf->fields.sfmt_addcc.f
ARGBUF *abuf = SEM_ARGBUF (sem_arg);
int UNUSED written = 0;
IADDR UNUSED pc = abuf->addr;
SEM_PC vpc = SEM_NEXT_VPC (sem_arg, pc, 4);
{
frvbf_signed_integer_divide (current_cpu, GET_H_GR (FLD (f_GRi)), GET_H_GR (FLD (f_GRj)), FLD (f_GRk), 0);
; /*clobber*/
}
return vpc;
#undef FLD
}
/* nsdiv: nsdiv$pack $GRi,$GRj,$GRk */
static SEM_PC
SEM_FN_NAME (frvbf,nsdiv) (SIM_CPU *current_cpu, SEM_ARG sem_arg)
{
#define FLD(f) abuf->fields.sfmt_addcc.f
ARGBUF *abuf = SEM_ARGBUF (sem_arg);
int UNUSED written = 0;
IADDR UNUSED pc = abuf->addr;
SEM_PC vpc = SEM_NEXT_VPC (sem_arg, pc, 4);
{
frvbf_signed_integer_divide (current_cpu, GET_H_GR (FLD (f_GRi)), GET_H_GR (FLD (f_GRj)), FLD (f_GRk), 1);
; /*clobber*/
}
return vpc;
#undef FLD
}
/* udiv: udiv$pack $GRi,$GRj,$GRk */
static SEM_PC
SEM_FN_NAME (frvbf,udiv) (SIM_CPU *current_cpu, SEM_ARG sem_arg)
{
#define FLD(f) abuf->fields.sfmt_addcc.f
ARGBUF *abuf = SEM_ARGBUF (sem_arg);
int UNUSED written = 0;
IADDR UNUSED pc = abuf->addr;
SEM_PC vpc = SEM_NEXT_VPC (sem_arg, pc, 4);
{
frvbf_unsigned_integer_divide (current_cpu, GET_H_GR (FLD (f_GRi)), GET_H_GR (FLD (f_GRj)), FLD (f_GRk), 0);
; /*clobber*/
}
return vpc;
#undef FLD
}
/* nudiv: nudiv$pack $GRi,$GRj,$GRk */
static SEM_PC
SEM_FN_NAME (frvbf,nudiv) (SIM_CPU *current_cpu, SEM_ARG sem_arg)
{
#define FLD(f) abuf->fields.sfmt_addcc.f
ARGBUF *abuf = SEM_ARGBUF (sem_arg);
int UNUSED written = 0;
IADDR UNUSED pc = abuf->addr;
SEM_PC vpc = SEM_NEXT_VPC (sem_arg, pc, 4);
{
frvbf_unsigned_integer_divide (current_cpu, GET_H_GR (FLD (f_GRi)), GET_H_GR (FLD (f_GRj)), FLD (f_GRk), 1);
; /*clobber*/
}
return vpc;
#undef FLD
}
/* smul: smul$pack $GRi,$GRj,$GRdoublek */
static SEM_PC
SEM_FN_NAME (frvbf,smul) (SIM_CPU *current_cpu, SEM_ARG sem_arg)
{
#define FLD(f) abuf->fields.sfmt_smulcc.f
ARGBUF *abuf = SEM_ARGBUF (sem_arg);
int UNUSED written = 0;
IADDR UNUSED pc = abuf->addr;
SEM_PC vpc = SEM_NEXT_VPC (sem_arg, pc, 4);
{
DI opval = MULDI (EXTSIDI (GET_H_GR (FLD (f_GRi))), EXTSIDI (GET_H_GR (FLD (f_GRj))));
sim_queue_fn_di_write (current_cpu, frvbf_h_gr_double_set, FLD (f_GRk), opval);
CGEN_TRACE_RESULT (current_cpu, abuf, "gr_double", 'D', opval);
}
return vpc;
#undef FLD
}
/* umul: umul$pack $GRi,$GRj,$GRdoublek */
static SEM_PC
SEM_FN_NAME (frvbf,umul) (SIM_CPU *current_cpu, SEM_ARG sem_arg)
{
#define FLD(f) abuf->fields.sfmt_smulcc.f
ARGBUF *abuf = SEM_ARGBUF (sem_arg);
int UNUSED written = 0;
IADDR UNUSED pc = abuf->addr;
SEM_PC vpc = SEM_NEXT_VPC (sem_arg, pc, 4);
{
DI opval = MULDI (ZEXTSIDI (GET_H_GR (FLD (f_GRi))), ZEXTSIDI (GET_H_GR (FLD (f_GRj))));
sim_queue_fn_di_write (current_cpu, frvbf_h_gr_double_set, FLD (f_GRk), opval);
CGEN_TRACE_RESULT (current_cpu, abuf, "gr_double", 'D', opval);
}
return vpc;
#undef FLD
}
/* smu: smu$pack $GRi,$GRj */
static SEM_PC
SEM_FN_NAME (frvbf,smu) (SIM_CPU *current_cpu, SEM_ARG sem_arg)
{
#define FLD(f) abuf->fields.sfmt_smass.f
ARGBUF *abuf = SEM_ARGBUF (sem_arg);
int UNUSED written = 0;
IADDR UNUSED pc = abuf->addr;
SEM_PC vpc = SEM_NEXT_VPC (sem_arg, pc, 4);
{
DI opval = MULDI (EXTSIDI (GET_H_GR (FLD (f_GRi))), EXTSIDI (GET_H_GR (FLD (f_GRj))));
sim_queue_fn_di_write (current_cpu, frvbf_h_iacc0_set, ((UINT) 0), opval);
CGEN_TRACE_RESULT (current_cpu, abuf, "iacc0", 'D', opval);
}
return vpc;
#undef FLD
}
/* smass: smass$pack $GRi,$GRj */
static SEM_PC
SEM_FN_NAME (frvbf,smass) (SIM_CPU *current_cpu, SEM_ARG sem_arg)
{
#define FLD(f) abuf->fields.sfmt_smass.f
ARGBUF *abuf = SEM_ARGBUF (sem_arg);
int UNUSED written = 0;
IADDR UNUSED pc = abuf->addr;
SEM_PC vpc = SEM_NEXT_VPC (sem_arg, pc, 4);
{
DI opval = (ANDIF (ANDIF (GTDI (MULDI (EXTSIDI (GET_H_GR (FLD (f_GRi))), EXTSIDI (GET_H_GR (FLD (f_GRj)))), 0), GTDI (GET_H_IACC0 (((UINT) 0)), 0)), LTDI (SUBDI (MAKEDI (2147483647, 0xffffffff), MULDI (EXTSIDI (GET_H_GR (FLD (f_GRi))), EXTSIDI (GET_H_GR (FLD (f_GRj))))), GET_H_IACC0 (((UINT) 0))))) ? (MAKEDI (2147483647, 0xffffffff)) : (ANDIF (ANDIF (LTDI (MULDI (EXTSIDI (GET_H_GR (FLD (f_GRi))), EXTSIDI (GET_H_GR (FLD (f_GRj)))), 0), LTDI (GET_H_IACC0 (((UINT) 0)), 0)), GTDI (SUBDI (MAKEDI (0x80000000, 0), MULDI (EXTSIDI (GET_H_GR (FLD (f_GRi))), EXTSIDI (GET_H_GR (FLD (f_GRj))))), GET_H_IACC0 (((UINT) 0))))) ? (MAKEDI (0x80000000, 0)) : (ADDDI (GET_H_IACC0 (((UINT) 0)), MULDI (EXTSIDI (GET_H_GR (FLD (f_GRi))), EXTSIDI (GET_H_GR (FLD (f_GRj))))));
sim_queue_fn_di_write (current_cpu, frvbf_h_iacc0_set, ((UINT) 0), opval);
CGEN_TRACE_RESULT (current_cpu, abuf, "iacc0", 'D', opval);
}
return vpc;
#undef FLD
}
/* smsss: smsss$pack $GRi,$GRj */
static SEM_PC
SEM_FN_NAME (frvbf,smsss) (SIM_CPU *current_cpu, SEM_ARG sem_arg)
{
#define FLD(f) abuf->fields.sfmt_smass.f
ARGBUF *abuf = SEM_ARGBUF (sem_arg);
int UNUSED written = 0;
IADDR UNUSED pc = abuf->addr;
SEM_PC vpc = SEM_NEXT_VPC (sem_arg, pc, 4);
{
DI opval = (ANDIF (ANDIF (LTDI (MULDI (EXTSIDI (GET_H_GR (FLD (f_GRi))), EXTSIDI (GET_H_GR (FLD (f_GRj)))), 0), GTDI (GET_H_IACC0 (((UINT) 0)), 0)), LTDI (ADDDI (MAKEDI (2147483647, 0xffffffff), MULDI (EXTSIDI (GET_H_GR (FLD (f_GRi))), EXTSIDI (GET_H_GR (FLD (f_GRj))))), GET_H_IACC0 (((UINT) 0))))) ? (MAKEDI (2147483647, 0xffffffff)) : (ANDIF (ANDIF (GTDI (MULDI (EXTSIDI (GET_H_GR (FLD (f_GRi))), EXTSIDI (GET_H_GR (FLD (f_GRj)))), 0), LTDI (GET_H_IACC0 (((UINT) 0)), 0)), GTDI (ADDDI (MAKEDI (0x80000000, 0), MULDI (EXTSIDI (GET_H_GR (FLD (f_GRi))), EXTSIDI (GET_H_GR (FLD (f_GRj))))), GET_H_IACC0 (((UINT) 0))))) ? (MAKEDI (0x80000000, 0)) : (SUBDI (GET_H_IACC0 (((UINT) 0)), MULDI (EXTSIDI (GET_H_GR (FLD (f_GRi))), EXTSIDI (GET_H_GR (FLD (f_GRj))))));
sim_queue_fn_di_write (current_cpu, frvbf_h_iacc0_set, ((UINT) 0), opval);
CGEN_TRACE_RESULT (current_cpu, abuf, "iacc0", 'D', opval);
}
return vpc;
#undef FLD
}
/* sll: sll$pack $GRi,$GRj,$GRk */
static SEM_PC
SEM_FN_NAME (frvbf,sll) (SIM_CPU *current_cpu, SEM_ARG sem_arg)
{
#define FLD(f) abuf->fields.sfmt_addcc.f
ARGBUF *abuf = SEM_ARGBUF (sem_arg);
int UNUSED written = 0;
IADDR UNUSED pc = abuf->addr;
SEM_PC vpc = SEM_NEXT_VPC (sem_arg, pc, 4);
{
SI opval = SLLSI (GET_H_GR (FLD (f_GRi)), ANDSI (GET_H_GR (FLD (f_GRj)), 31));
sim_queue_fn_si_write (current_cpu, frvbf_h_gr_set, FLD (f_GRk), opval);
CGEN_TRACE_RESULT (current_cpu, abuf, "gr", 'x', opval);
}
return vpc;
#undef FLD
}
/* srl: srl$pack $GRi,$GRj,$GRk */
static SEM_PC
SEM_FN_NAME (frvbf,srl) (SIM_CPU *current_cpu, SEM_ARG sem_arg)
{
#define FLD(f) abuf->fields.sfmt_addcc.f
ARGBUF *abuf = SEM_ARGBUF (sem_arg);
int UNUSED written = 0;
IADDR UNUSED pc = abuf->addr;
SEM_PC vpc = SEM_NEXT_VPC (sem_arg, pc, 4);
{
SI opval = SRLSI (GET_H_GR (FLD (f_GRi)), ANDSI (GET_H_GR (FLD (f_GRj)), 31));
sim_queue_fn_si_write (current_cpu, frvbf_h_gr_set, FLD (f_GRk), opval);
CGEN_TRACE_RESULT (current_cpu, abuf, "gr", 'x', opval);
}
return vpc;
#undef FLD
}
/* sra: sra$pack $GRi,$GRj,$GRk */
static SEM_PC
SEM_FN_NAME (frvbf,sra) (SIM_CPU *current_cpu, SEM_ARG sem_arg)
{
#define FLD(f) abuf->fields.sfmt_addcc.f
ARGBUF *abuf = SEM_ARGBUF (sem_arg);
int UNUSED written = 0;
IADDR UNUSED pc = abuf->addr;
SEM_PC vpc = SEM_NEXT_VPC (sem_arg, pc, 4);
{
SI opval = SRASI (GET_H_GR (FLD (f_GRi)), ANDSI (GET_H_GR (FLD (f_GRj)), 31));
sim_queue_fn_si_write (current_cpu, frvbf_h_gr_set, FLD (f_GRk), opval);
CGEN_TRACE_RESULT (current_cpu, abuf, "gr", 'x', opval);
}
return vpc;
#undef FLD
}
/* slass: slass$pack $GRi,$GRj,$GRk */
static SEM_PC
SEM_FN_NAME (frvbf,slass) (SIM_CPU *current_cpu, SEM_ARG sem_arg)
{
#define FLD(f) abuf->fields.sfmt_addcc.f
ARGBUF *abuf = SEM_ARGBUF (sem_arg);
int UNUSED written = 0;
IADDR UNUSED pc = abuf->addr;
SEM_PC vpc = SEM_NEXT_VPC (sem_arg, pc, 4);
{
SI opval = frvbf_shift_left_arith_saturate (current_cpu, GET_H_GR (FLD (f_GRi)), GET_H_GR (FLD (f_GRj)));
sim_queue_fn_si_write (current_cpu, frvbf_h_gr_set, FLD (f_GRk), opval);
CGEN_TRACE_RESULT (current_cpu, abuf, "gr", 'x', opval);
}
return vpc;
#undef FLD
}
/* scutss: scutss$pack $GRj,$GRk */
static SEM_PC
SEM_FN_NAME (frvbf,scutss) (SIM_CPU *current_cpu, SEM_ARG sem_arg)
{
#define FLD(f) abuf->fields.sfmt_scutss.f
ARGBUF *abuf = SEM_ARGBUF (sem_arg);
int UNUSED written = 0;
IADDR UNUSED pc = abuf->addr;
SEM_PC vpc = SEM_NEXT_VPC (sem_arg, pc, 4);
{
SI opval = frvbf_iacc_cut (current_cpu, GET_H_IACC0 (((UINT) 0)), GET_H_GR (FLD (f_GRj)));
sim_queue_fn_si_write (current_cpu, frvbf_h_gr_set, FLD (f_GRk), opval);
CGEN_TRACE_RESULT (current_cpu, abuf, "gr", 'x', opval);
}
return vpc;
#undef FLD
}
/* scan: scan$pack $GRi,$GRj,$GRk */
static SEM_PC
SEM_FN_NAME (frvbf,scan) (SIM_CPU *current_cpu, SEM_ARG sem_arg)
{
#define FLD(f) abuf->fields.sfmt_addcc.f
ARGBUF *abuf = SEM_ARGBUF (sem_arg);
int UNUSED written = 0;
IADDR UNUSED pc = abuf->addr;
SEM_PC vpc = SEM_NEXT_VPC (sem_arg, pc, 4);
{
SI tmp_tmp1;
SI tmp_tmp2;
tmp_tmp1 = GET_H_GR (FLD (f_GRi));
tmp_tmp2 = SRASI (GET_H_GR (FLD (f_GRj)), 1);
{
SI opval = frvbf_scan_result (current_cpu, XORSI (tmp_tmp1, tmp_tmp2));
sim_queue_fn_si_write (current_cpu, frvbf_h_gr_set, FLD (f_GRk), opval);
CGEN_TRACE_RESULT (current_cpu, abuf, "gr", 'x', opval);
}
}
return vpc;
#undef FLD
}
/* cadd: cadd$pack $GRi,$GRj,$GRk,$CCi,$cond */
static SEM_PC
SEM_FN_NAME (frvbf,cadd) (SIM_CPU *current_cpu, SEM_ARG sem_arg)
{
#define FLD(f) abuf->fields.sfmt_cswap.f
ARGBUF *abuf = SEM_ARGBUF (sem_arg);
int UNUSED written = 0;
IADDR UNUSED pc = abuf->addr;
SEM_PC vpc = SEM_NEXT_VPC (sem_arg, pc, 4);
if (EQQI (CPU (h_cccr[FLD (f_CCi)]), ORSI (FLD (f_cond), 2))) {
{
SI opval = ADDSI (GET_H_GR (FLD (f_GRi)), GET_H_GR (FLD (f_GRj)));
sim_queue_fn_si_write (current_cpu, frvbf_h_gr_set, FLD (f_GRk), opval);
written |= (1 << 4);
CGEN_TRACE_RESULT (current_cpu, abuf, "gr", 'x', opval);
}
}
abuf->written = written;
return vpc;
#undef FLD
}
/* csub: csub$pack $GRi,$GRj,$GRk,$CCi,$cond */
static SEM_PC
SEM_FN_NAME (frvbf,csub) (SIM_CPU *current_cpu, SEM_ARG sem_arg)
{
#define FLD(f) abuf->fields.sfmt_cswap.f
ARGBUF *abuf = SEM_ARGBUF (sem_arg);
int UNUSED written = 0;
IADDR UNUSED pc = abuf->addr;
SEM_PC vpc = SEM_NEXT_VPC (sem_arg, pc, 4);
if (EQQI (CPU (h_cccr[FLD (f_CCi)]), ORSI (FLD (f_cond), 2))) {
{
SI opval = SUBSI (GET_H_GR (FLD (f_GRi)), GET_H_GR (FLD (f_GRj)));
sim_queue_fn_si_write (current_cpu, frvbf_h_gr_set, FLD (f_GRk), opval);
written |= (1 << 4);
CGEN_TRACE_RESULT (current_cpu, abuf, "gr", 'x', opval);
}
}
abuf->written = written;
return vpc;
#undef FLD
}
/* cand: cand$pack $GRi,$GRj,$GRk,$CCi,$cond */
static SEM_PC
SEM_FN_NAME (frvbf,cand) (SIM_CPU *current_cpu, SEM_ARG sem_arg)
{
#define FLD(f) abuf->fields.sfmt_cswap.f
ARGBUF *abuf = SEM_ARGBUF (sem_arg);
int UNUSED written = 0;
IADDR UNUSED pc = abuf->addr;
SEM_PC vpc = SEM_NEXT_VPC (sem_arg, pc, 4);
if (EQQI (CPU (h_cccr[FLD (f_CCi)]), ORSI (FLD (f_cond), 2))) {
{
SI opval = ANDSI (GET_H_GR (FLD (f_GRi)), GET_H_GR (FLD (f_GRj)));
sim_queue_fn_si_write (current_cpu, frvbf_h_gr_set, FLD (f_GRk), opval);
written |= (1 << 4);
CGEN_TRACE_RESULT (current_cpu, abuf, "gr", 'x', opval);
}
}
abuf->written = written;
return vpc;
#undef FLD
}
/* cor: cor$pack $GRi,$GRj,$GRk,$CCi,$cond */
static SEM_PC
SEM_FN_NAME (frvbf,cor) (SIM_CPU *current_cpu, SEM_ARG sem_arg)
{
#define FLD(f) abuf->fields.sfmt_cswap.f
ARGBUF *abuf = SEM_ARGBUF (sem_arg);
int UNUSED written = 0;
IADDR UNUSED pc = abuf->addr;
SEM_PC vpc = SEM_NEXT_VPC (sem_arg, pc, 4);
if (EQQI (CPU (h_cccr[FLD (f_CCi)]), ORSI (FLD (f_cond), 2))) {
{
SI opval = ORSI (GET_H_GR (FLD (f_GRi)), GET_H_GR (FLD (f_GRj)));
sim_queue_fn_si_write (current_cpu, frvbf_h_gr_set, FLD (f_GRk), opval);
written |= (1 << 4);
CGEN_TRACE_RESULT (current_cpu, abuf, "gr", 'x', opval);
}
}
abuf->written = written;
return vpc;
#undef FLD
}
/* cxor: cxor$pack $GRi,$GRj,$GRk,$CCi,$cond */
static SEM_PC
SEM_FN_NAME (frvbf,cxor) (SIM_CPU *current_cpu, SEM_ARG sem_arg)
{
#define FLD(f) abuf->fields.sfmt_cswap.f
ARGBUF *abuf = SEM_ARGBUF (sem_arg);
int UNUSED written = 0;
IADDR UNUSED pc = abuf->addr;
SEM_PC vpc = SEM_NEXT_VPC (sem_arg, pc, 4);
if (EQQI (CPU (h_cccr[FLD (f_CCi)]), ORSI (FLD (f_cond), 2))) {
{
SI opval = XORSI (GET_H_GR (FLD (f_GRi)), GET_H_GR (FLD (f_GRj)));
sim_queue_fn_si_write (current_cpu, frvbf_h_gr_set, FLD (f_GRk), opval);
written |= (1 << 4);
CGEN_TRACE_RESULT (current_cpu, abuf, "gr", 'x', opval);
}
}
abuf->written = written;
return vpc;
#undef FLD
}
/* cnot: cnot$pack $GRj,$GRk,$CCi,$cond */
static SEM_PC
SEM_FN_NAME (frvbf,cnot) (SIM_CPU *current_cpu, SEM_ARG sem_arg)
{
#define FLD(f) abuf->fields.sfmt_cswap.f
ARGBUF *abuf = SEM_ARGBUF (sem_arg);
int UNUSED written = 0;
IADDR UNUSED pc = abuf->addr;
SEM_PC vpc = SEM_NEXT_VPC (sem_arg, pc, 4);
if (EQQI (CPU (h_cccr[FLD (f_CCi)]), ORSI (FLD (f_cond), 2))) {
{
SI opval = INVSI (GET_H_GR (FLD (f_GRj)));
sim_queue_fn_si_write (current_cpu, frvbf_h_gr_set, FLD (f_GRk), opval);
written |= (1 << 3);
CGEN_TRACE_RESULT (current_cpu, abuf, "gr", 'x', opval);
}
}
abuf->written = written;
return vpc;
#undef FLD
}
/* csmul: csmul$pack $GRi,$GRj,$GRdoublek,$CCi,$cond */
static SEM_PC
SEM_FN_NAME (frvbf,csmul) (SIM_CPU *current_cpu, SEM_ARG sem_arg)
{
#define FLD(f) abuf->fields.sfmt_clddu.f
ARGBUF *abuf = SEM_ARGBUF (sem_arg);
int UNUSED written = 0;
IADDR UNUSED pc = abuf->addr;
SEM_PC vpc = SEM_NEXT_VPC (sem_arg, pc, 4);
if (EQQI (CPU (h_cccr[FLD (f_CCi)]), ORSI (FLD (f_cond), 2))) {
{
DI opval = MULDI (EXTSIDI (GET_H_GR (FLD (f_GRi))), EXTSIDI (GET_H_GR (FLD (f_GRj))));
sim_queue_fn_di_write (current_cpu, frvbf_h_gr_double_set, FLD (f_GRk), opval);
written |= (1 << 4);
CGEN_TRACE_RESULT (current_cpu, abuf, "gr_double", 'D', opval);
}
}
abuf->written = written;
return vpc;
#undef FLD
}
/* csdiv: csdiv$pack $GRi,$GRj,$GRk,$CCi,$cond */
static SEM_PC
SEM_FN_NAME (frvbf,csdiv) (SIM_CPU *current_cpu, SEM_ARG sem_arg)
{
#define FLD(f) abuf->fields.sfmt_cswap.f
ARGBUF *abuf = SEM_ARGBUF (sem_arg);
int UNUSED written = 0;
IADDR UNUSED pc = abuf->addr;
SEM_PC vpc = SEM_NEXT_VPC (sem_arg, pc, 4);
if (EQQI (CPU (h_cccr[FLD (f_CCi)]), ORSI (FLD (f_cond), 2))) {
{
frvbf_signed_integer_divide (current_cpu, GET_H_GR (FLD (f_GRi)), GET_H_GR (FLD (f_GRj)), FLD (f_GRk), 0);
; /*clobber*/
}
}
abuf->written = written;
return vpc;
#undef FLD
}
/* cudiv: cudiv$pack $GRi,$GRj,$GRk,$CCi,$cond */
static SEM_PC
SEM_FN_NAME (frvbf,cudiv) (SIM_CPU *current_cpu, SEM_ARG sem_arg)
{
#define FLD(f) abuf->fields.sfmt_cswap.f
ARGBUF *abuf = SEM_ARGBUF (sem_arg);
int UNUSED written = 0;
IADDR UNUSED pc = abuf->addr;
SEM_PC vpc = SEM_NEXT_VPC (sem_arg, pc, 4);
if (EQQI (CPU (h_cccr[FLD (f_CCi)]), ORSI (FLD (f_cond), 2))) {
{
frvbf_unsigned_integer_divide (current_cpu, GET_H_GR (FLD (f_GRi)), GET_H_GR (FLD (f_GRj)), FLD (f_GRk), 0);
; /*clobber*/
}
}
abuf->written = written;
return vpc;
#undef FLD
}
/* csll: csll$pack $GRi,$GRj,$GRk,$CCi,$cond */
static SEM_PC
SEM_FN_NAME (frvbf,csll) (SIM_CPU *current_cpu, SEM_ARG sem_arg)
{
#define FLD(f) abuf->fields.sfmt_cswap.f
ARGBUF *abuf = SEM_ARGBUF (sem_arg);
int UNUSED written = 0;
IADDR UNUSED pc = abuf->addr;
SEM_PC vpc = SEM_NEXT_VPC (sem_arg, pc, 4);
if (EQQI (CPU (h_cccr[FLD (f_CCi)]), ORSI (FLD (f_cond), 2))) {
{
SI opval = SLLSI (GET_H_GR (FLD (f_GRi)), ANDSI (GET_H_GR (FLD (f_GRj)), 31));
sim_queue_fn_si_write (current_cpu, frvbf_h_gr_set, FLD (f_GRk), opval);
written |= (1 << 4);
CGEN_TRACE_RESULT (current_cpu, abuf, "gr", 'x', opval);
}
}
abuf->written = written;
return vpc;
#undef FLD
}
/* csrl: csrl$pack $GRi,$GRj,$GRk,$CCi,$cond */
static SEM_PC
SEM_FN_NAME (frvbf,csrl) (SIM_CPU *current_cpu, SEM_ARG sem_arg)
{
#define FLD(f) abuf->fields.sfmt_cswap.f
ARGBUF *abuf = SEM_ARGBUF (sem_arg);
int UNUSED written = 0;
IADDR UNUSED pc = abuf->addr;
SEM_PC vpc = SEM_NEXT_VPC (sem_arg, pc, 4);
if (EQQI (CPU (h_cccr[FLD (f_CCi)]), ORSI (FLD (f_cond), 2))) {
{
SI opval = SRLSI (GET_H_GR (FLD (f_GRi)), ANDSI (GET_H_GR (FLD (f_GRj)), 31));
sim_queue_fn_si_write (current_cpu, frvbf_h_gr_set, FLD (f_GRk), opval);
written |= (1 << 4);
CGEN_TRACE_RESULT (current_cpu, abuf, "gr", 'x', opval);
}
}
abuf->written = written;
return vpc;
#undef FLD
}
/* csra: csra$pack $GRi,$GRj,$GRk,$CCi,$cond */
static SEM_PC
SEM_FN_NAME (frvbf,csra) (SIM_CPU *current_cpu, SEM_ARG sem_arg)
{
#define FLD(f) abuf->fields.sfmt_cswap.f
ARGBUF *abuf = SEM_ARGBUF (sem_arg);
int UNUSED written = 0;
IADDR UNUSED pc = abuf->addr;
SEM_PC vpc = SEM_NEXT_VPC (sem_arg, pc, 4);
if (EQQI (CPU (h_cccr[FLD (f_CCi)]), ORSI (FLD (f_cond), 2))) {
{
SI opval = SRASI (GET_H_GR (FLD (f_GRi)), ANDSI (GET_H_GR (FLD (f_GRj)), 31));
sim_queue_fn_si_write (current_cpu, frvbf_h_gr_set, FLD (f_GRk), opval);
written |= (1 << 4);
CGEN_TRACE_RESULT (current_cpu, abuf, "gr", 'x', opval);
}
}
abuf->written = written;
return vpc;
#undef FLD
}
/* cscan: cscan$pack $GRi,$GRj,$GRk,$CCi,$cond */
static SEM_PC
SEM_FN_NAME (frvbf,cscan) (SIM_CPU *current_cpu, SEM_ARG sem_arg)
{
#define FLD(f) abuf->fields.sfmt_cswap.f
ARGBUF *abuf = SEM_ARGBUF (sem_arg);
int UNUSED written = 0;
IADDR UNUSED pc = abuf->addr;
SEM_PC vpc = SEM_NEXT_VPC (sem_arg, pc, 4);
if (EQQI (CPU (h_cccr[FLD (f_CCi)]), ORSI (FLD (f_cond), 2))) {
{
SI tmp_tmp1;
SI tmp_tmp2;
tmp_tmp1 = GET_H_GR (FLD (f_GRi));
tmp_tmp2 = SRASI (GET_H_GR (FLD (f_GRj)), 1);
{
SI opval = frvbf_scan_result (current_cpu, XORSI (tmp_tmp1, tmp_tmp2));
sim_queue_fn_si_write (current_cpu, frvbf_h_gr_set, FLD (f_GRk), opval);
written |= (1 << 4);
CGEN_TRACE_RESULT (current_cpu, abuf, "gr", 'x', opval);
}
}
}
abuf->written = written;
return vpc;
#undef FLD
}
/* addcc: addcc$pack $GRi,$GRj,$GRk,$ICCi_1 */
static SEM_PC
SEM_FN_NAME (frvbf,addcc) (SIM_CPU *current_cpu, SEM_ARG sem_arg)
{
#define FLD(f) abuf->fields.sfmt_addcc.f
ARGBUF *abuf = SEM_ARGBUF (sem_arg);
int UNUSED written = 0;
IADDR UNUSED pc = abuf->addr;
SEM_PC vpc = SEM_NEXT_VPC (sem_arg, pc, 4);
{
BI tmp_tmp;
QI tmp_cc;
SI tmp_result;
tmp_cc = CPU (h_iccr[FLD (f_ICCi_1)]);
tmp_tmp = ADDOFSI (GET_H_GR (FLD (f_GRi)), GET_H_GR (FLD (f_GRj)), 0);
if (EQBI (tmp_tmp, 0)) {
tmp_cc = ANDQI (tmp_cc, 13);
} else {
tmp_cc = ORQI (tmp_cc, 2);
}
tmp_tmp = ADDCFSI (GET_H_GR (FLD (f_GRi)), GET_H_GR (FLD (f_GRj)), 0);
if (EQBI (tmp_tmp, 0)) {
tmp_cc = ANDQI (tmp_cc, 14);
} else {
tmp_cc = ORQI (tmp_cc, 1);
}
tmp_result = ADDSI (GET_H_GR (FLD (f_GRi)), GET_H_GR (FLD (f_GRj)));
if (EQSI (tmp_result, 0)) {
tmp_cc = ORQI (ANDQI (tmp_cc, 7), 4);
} else {
if (LTSI (tmp_result, 0)) {
tmp_cc = ORQI (ANDQI (tmp_cc, 11), 8);
} else {
tmp_cc = ANDQI (tmp_cc, 3);
}
}
{
SI opval = tmp_result;
sim_queue_fn_si_write (current_cpu, frvbf_h_gr_set, FLD (f_GRk), opval);
CGEN_TRACE_RESULT (current_cpu, abuf, "gr", 'x', opval);
}
{
UQI opval = tmp_cc;
sim_queue_qi_write (current_cpu, & CPU (h_iccr[FLD (f_ICCi_1)]), opval);
CGEN_TRACE_RESULT (current_cpu, abuf, "iccr", 'x', opval);
}
}
return vpc;
#undef FLD
}
/* subcc: subcc$pack $GRi,$GRj,$GRk,$ICCi_1 */
static SEM_PC
SEM_FN_NAME (frvbf,subcc) (SIM_CPU *current_cpu, SEM_ARG sem_arg)
{
#define FLD(f) abuf->fields.sfmt_addcc.f
ARGBUF *abuf = SEM_ARGBUF (sem_arg);
int UNUSED written = 0;
IADDR UNUSED pc = abuf->addr;
SEM_PC vpc = SEM_NEXT_VPC (sem_arg, pc, 4);
{
BI tmp_tmp;
QI tmp_cc;
SI tmp_result;
tmp_cc = CPU (h_iccr[FLD (f_ICCi_1)]);
tmp_tmp = SUBOFSI (GET_H_GR (FLD (f_GRi)), GET_H_GR (FLD (f_GRj)), 0);
if (EQBI (tmp_tmp, 0)) {
tmp_cc = ANDQI (tmp_cc, 13);
} else {
tmp_cc = ORQI (tmp_cc, 2);
}
tmp_tmp =
* UnsupportedOperationException if remove() is called). To create a modifiable
* Collection, you must in addition provide an implementation of the
* add(Object) method and the Iterator returned by iterator() must provide an
* implementation of remove(). Other methods should be overridden if the
* backing data structure allows for a more efficient implementation. The
* precise implementation used by AbstractCollection is documented, so that
* subclasses can tell which methods could be implemented more efficiently.
* <p>
*
* The programmer should provide a no-argument constructor, and one that
* accepts another Collection, as recommended by the Collection interface.
* Unfortunately, there is no way to enforce this in Java.
*
* @author Original author unknown
* @author Bryce McKinlay
* @author Eric Blake (ebb9@email.byu.edu)
* @author Tom Tromey (tromey@redhat.com)
* @author Andrew John Hughes (gnu_andrew@member.fsf.org)
* @see Collection
* @see AbstractSet
* @see AbstractList
* @since 1.2
* @status updated to 1.4
*/
public abstract class AbstractCollection<E>
implements Collection<E>, Iterable<E>
{
/**
* The main constructor, for use by subclasses.
*/
protected AbstractCollection()
{
}
/**
* Return an Iterator over this collection. The iterator must provide the
* hasNext and next methods and should in addition provide remove if the
* collection is modifiable.
*
* @return an iterator
*/
public abstract Iterator<E> iterator();
/**
* Return the number of elements in this collection. If there are more than
* Integer.MAX_VALUE elements, return Integer.MAX_VALUE.
*
* @return the size
*/
public abstract int size();
/**
* Add an object to the collection (optional operation). This implementation
* always throws an UnsupportedOperationException - it should be
* overridden if the collection is to be modifiable. If the collection
* does not accept duplicates, simply return false. Collections may specify
* limitations on what may be added.
*
* @param o the object to add
* @return true if the add operation caused the Collection to change
* @throws UnsupportedOperationException if the add operation is not
* supported on this collection
* @throws NullPointerException if the collection does not support null
* @throws ClassCastException if the object is of the wrong type
* @throws IllegalArgumentException if some aspect of the object prevents
* it from being added
*/
public boolean add(E o)
{
throw new UnsupportedOperationException();
}
/**
* Add all the elements of a given collection to this collection (optional
* operation). This implementation obtains an Iterator over the given
* collection and iterates over it, adding each element with the
* add(Object) method (thus this method will fail with an
* UnsupportedOperationException if the add method does). The behavior is
* unspecified if the specified collection is modified during the iteration,
* including the special case of trying addAll(this) on a non-empty
* collection.
*
* @param c the collection to add the elements of to this collection
* @return true if the add operation caused the Collection to change
* @throws UnsupportedOperationException if the add operation is not
* supported on this collection
* @throws NullPointerException if the specified collection is null
* @throws ClassCastException if the type of any element in c is
* not a valid type for addition.
* @throws IllegalArgumentException if some aspect of any element
* in c prevents it being added.
* @throws NullPointerException if any element in c is null and this
* collection doesn't allow null values.
* @see #add(Object)
*/
public boolean addAll(Collection<? extends E> c)
{
Iterator<? extends E> itr = c.iterator();
boolean modified = false;
int pos = c.size();
while (--pos >= 0)
modified |= add(itr.next());
return modified;
}
/**
* Remove all elements from the collection (optional operation). This
* implementation obtains an iterator over the collection and calls next
* and remove on it repeatedly (thus this method will fail with an
* UnsupportedOperationException if the Iterator's remove method does)
* until there are no more elements to remove.
* Many implementations will have a faster way of doing this.
*
* @throws UnsupportedOperationException if the Iterator returned by
* iterator does not provide an implementation of remove
* @see Iterator#remove()
*/
public void clear()
{
Iterator<E> itr = iterator();
int pos = size();
while (--pos >= 0)
{
itr.next();
itr.remove();
}
}
/**
* Test whether this collection contains a given object. That is, if the
* collection has an element e such that (o == null ? e == null :
* o.equals(e)). This implementation obtains an iterator over the collection
* and iterates over it, testing each element for equality with the given
* object. If it is equal, true is returned. Otherwise false is returned when
* the end of the collection is reached.
*
* @param o the object to remove from this collection
* @return true if this collection contains an object equal to o
*/
public boolean contains(Object o)
{
Iterator<E> itr = iterator();
int pos = size();
while (--pos >= 0)
if (equals(o, itr.next()))
return true;
return false;
}
/**
* Tests whether this collection contains all the elements in a given
* collection. This implementation iterates over the given collection,
* testing whether each element is contained in this collection. If any one
* is not, false is returned. Otherwise true is returned.
*
* @param c the collection to test against
* @return true if this collection contains all the elements in the given
* collection
* @throws NullPointerException if the given collection is null
* @see #contains(Object)
*/
public boolean containsAll(Collection<?> c)
{
Iterator<?> itr = c.iterator();
int pos = c.size();
while (--pos >= 0)
if (!contains(itr.next()))
return false;
return true;
}
/**
* Test whether this collection is empty. This implementation returns
* size() == 0.
*
* @return true if this collection is empty.
* @see #size()
*/
public boolean isEmpty()
{
return size() == 0;
}
/**
* Remove a single instance of an object from this collection (optional
* operation). That is, remove one element e such that
* <code>(o == null ? e == null : o.equals(e))</code>, if such an element
* exists. This implementation obtains an iterator over the collection
* and iterates over it, testing each element for equality with the given
* object. If it is equal, it is removed by the iterator's remove method
* (thus this method will fail with an UnsupportedOperationException if
* the Iterator's remove method does). After the first element has been
* removed, true is returned; if the end of the collection is reached, false
* is returned.
*
* @param o the object to remove from this collection
* @return true if the remove operation caused the Collection to change, or
* equivalently if the collection did contain o.
* @throws UnsupportedOperationException if this collection's Iterator
* does not support the remove method
* @see Iterator#remove()
*/
public boolean remove(Object o)
{
Iterator<E> itr = iterator();
int pos = size();
while (--pos >= 0)
if (equals(o, itr.next()))
{
itr.remove();
return true;
}
return false;
}
/**
* Remove from this collection all its elements that are contained in a given
* collection (optional operation). This implementation iterates over this
* collection, and for each element tests if it is contained in the given
* collection. If so, it is removed by the Iterator's remove method (thus
* this method will fail with an UnsupportedOperationException if the
* Iterator's remove method does).
*
* @param c the collection to remove the elements of
* @return true if the remove operation caused the Collection to change
* @throws UnsupportedOperationException if this collection's Iterator
* does not support the remove method
* @throws NullPointerException if the collection, c, is null.
* @see Iterator#remove()
*/
public boolean removeAll(Collection<?> c)
{
return removeAllInternal(c);
}
/**
* Remove from this collection all its elements that are contained in a given
* collection (optional operation). This implementation iterates over this
* collection, and for each element tests if it is contained in the given
* collection. If so, it is removed by the Iterator's remove method (thus
* this method will fail with an UnsupportedOperationException if the
* Iterator's remove method does). This method is necessary for ArrayList,
* which cannot publicly override removeAll but can optimize this call.
*
* @param c the collection to remove the elements of
* @return true if the remove operation caused the Collection to change
* @throws UnsupportedOperationException if this collection's Iterator
* does not support the remove method
* @throws NullPointerException if the collection, c, is null.
* @see Iterator#remove()
*/
// Package visible for use throughout java.util.
boolean removeAllInternal(Collection<?> c)
{
Iterator<E> itr = iterator();
boolean modified = false;
int pos = size();
while (--pos >= 0)
if (c.contains(itr.next()))
{
itr.remove();
modified = true;
}
return modified;
}
/**
* Remove from this collection all its elements that are not contained in a
* given collection (optional operation). This implementation iterates over
* this collection, and for each element tests if it is contained in the
* given collection. If not, it is removed by the Iterator's remove method
* (thus this method will fail with an UnsupportedOperationException if
* the Iterator's remove method does).
*
* @param c the collection to retain the elements of
* @return true if the remove operation caused the Collection to change
* @throws UnsupportedOperationException if this collection's Iterator
* does not support the remove method
* @throws NullPointerException if the collection, c, is null.
* @see Iterator#remove()
*/
public boolean retainAll(Collection<?> c)
{
return retainAllInternal(c);
}
/**
* Remove from this collection all its elements that are not contained in a
* given collection (optional operation). This implementation iterates over
* this collection, and for each element tests if it is contained in the
* given collection. If not, it is removed by the Iterator's remove method
* (thus this method will fail with an UnsupportedOperationException if
* the Iterator's remove method does). This method is necessary for
* ArrayList, which cannot publicly override retainAll but can optimize
* this call.
*
* @param c the collection to retain the elements of
* @return true if the remove operation caused the Collection to change
* @throws UnsupportedOperationException if this collection's Iterator
* does not support the remove method
* @throws NullPointerException if the collection, c, is null.
* @see Iterator#remove()
*/
// Package visible for use throughout java.util.
boolean retainAllInternal(Collection<?> c)
{
Iterator<E> itr = iterator();
boolean modified = false;
int pos = size();
while (--pos >= 0)
if (!c.contains(itr.next()))
{
itr.remove();
modified = true;
}
return modified;
}
/**
* Return an array containing the elements of this collection. This
* implementation creates an Object array of size size() and then iterates
* over the collection, setting each element of the array from the value
* returned by the iterator. The returned array is safe, and is not backed
* by the collection.
*
* @return an array containing the elements of this collection
*/
public Object[] toArray()
{
Iterator<E> itr = iterator();
int size = size();
Object[] a = new Object[size];
for (int pos = 0; pos < size; pos++)
a[pos] = itr.next();
return a;
}
/**
* Copy the collection into a given array if it will fit, or into a
* dynamically created array of the same run-time type as the given array if
* not. If there is space remaining in the array, the first element after the
* end of the collection is set to null (this is only useful if the
* collection is known to contain no null elements, however). This
* implementation first tests whether the given array is large enough to hold
* all the elements of the collection. If not, the reflection API is used to
* allocate a new array of the same run-time type. Next an iterator is
* obtained over the collection and the elements are placed in the array as
* they are returned by the iterator. Finally the first spare element, if
* any, of the array is set to null, and the created array is returned.
* The returned array is safe; it is not backed by the collection. Note that
* null may not mark the last element, if the collection allows null
* elements.
*
* @param a the array to copy into, or of the correct run-time type
* @return the array that was produced
* @throws NullPointerException if the given array is null
* @throws ArrayStoreException if the type of the array precludes holding
* one of the elements of the Collection
*/
public <T> T[] toArray(T[] a)
{
int size = size();
if (a.length < size)
a = (T[]) Array.newInstance(a.getClass().getComponentType(),
size);
else if (a.length > size)
a[size] = null;
Iterator<E> itr = iterator();
for (int pos = 0; pos < size; pos++)
a[pos] = (T) (itr.next());
return a;
}
/**
* Creates a String representation of the Collection. The string returned is
* of the form "[a, b, ...]" where a and b etc are the results of calling
* toString on the elements of the collection. This implementation obtains an
* Iterator over the Collection and adds each element to a StringBuffer as it
* is returned by the iterator. "<this>" is inserted when the collection
* contains itself (only works for direct containment, not for collections
* inside collections).
*
* @return a String representation of the Collection
*/
public String toString()
{
Iterator itr = iterator();
StringBuffer r = new StringBuffer("[");
boolean hasNext = itr.hasNext();
while (hasNext)
{
Object o = itr.next();
if (o == this)
r.append("<this>");
else
r.append(o);
hasNext = itr.hasNext();
if (hasNext)
r.append(", ");
}
r.append("]");
return r.toString();
}
/**
* Compare two objects according to Collection semantics.
*
* @param o1 the first object
* @param o2 the second object
* @return o1 == null ? o2 == null : o1.equals(o2)
*/
// Package visible for use throughout java.util.
// It may be inlined since it is final.
static final boolean equals(Object o1, Object o2)
{
return o1 == null ? o2 == null : o1.equals(o2);
}
/**
* Hash an object according to Collection semantics.
*
* @param o the object to hash
* @return o1 == null ? 0 : o1.hashCode()
*/
// Package visible for use throughout java.util.
// It may be inlined since it is final.
static final int hashCode(Object o)
{
return o == null ? 0 : o.hashCode();
}
}