project
stringclasses 2
values | commit_id
stringlengths 40
40
| target
int64 0
1
| func
stringlengths 26
142k
| idx
int64 0
27.3k
|
---|---|---|---|---|
FFmpeg | b88be742fac7a77a8095e8155ba8790db4b77568 | 1 | static void encode_quant_matrix(VC2EncContext *s)
{
int level, custom_quant_matrix = 0;
if (s->wavelet_depth > 4 || s->quant_matrix != VC2_QM_DEF)
custom_quant_matrix = 1;
put_bits(&s->pb, 1, custom_quant_matrix);
if (custom_quant_matrix) {
init_custom_qm(s);
put_vc2_ue_uint(&s->pb, s->quant[0][0]);
for (level = 0; level < s->wavelet_depth; level++) {
put_vc2_ue_uint(&s->pb, s->quant[level][1]);
put_vc2_ue_uint(&s->pb, s->quant[level][2]);
put_vc2_ue_uint(&s->pb, s->quant[level][3]);
}
} else {
for (level = 0; level < s->wavelet_depth; level++) {
s->quant[level][0] = ff_dirac_default_qmat[s->wavelet_idx][level][0];
s->quant[level][1] = ff_dirac_default_qmat[s->wavelet_idx][level][1];
s->quant[level][2] = ff_dirac_default_qmat[s->wavelet_idx][level][2];
s->quant[level][3] = ff_dirac_default_qmat[s->wavelet_idx][level][3];
}
}
}
| 3,424 |
FFmpeg | f42b3195d3f2692a4dfc0a8668bb4ac35301f2ed | 1 | static void fix_bitshift(ShortenContext *s, int32_t *buffer)
{
int i;
if (s->bitshift != 0)
for (i = 0; i < s->blocksize; i++)
buffer[s->nwrap + i] <<= s->bitshift;
}
| 3,425 |
qemu | 7bdfd907e7072e380f325e735d99677df53f00ec | 1 | static void wav_capture_destroy (void *opaque)
{
WAVState *wav = opaque;
AUD_del_capture (wav->cap, wav);
} | 3,426 |
qemu | a32354e206895400d17c3de9a8df1de96d3df289 | 1 | static uint32_t m5206_mbar_readw(void *opaque, target_phys_addr_t offset)
{
m5206_mbar_state *s = (m5206_mbar_state *)opaque;
int width;
offset &= 0x3ff;
if (offset > 0x200) {
hw_error("Bad MBAR read offset 0x%x", (int)offset);
}
width = m5206_mbar_width[offset >> 2];
if (width > 2) {
uint32_t val;
val = m5206_mbar_readl(opaque, offset & ~3);
if ((offset & 3) == 0)
val >>= 16;
return val & 0xffff;
} else if (width < 2) {
uint16_t val;
val = m5206_mbar_readb(opaque, offset) << 8;
val |= m5206_mbar_readb(opaque, offset + 1);
return val;
}
return m5206_mbar_read(s, offset, 2);
}
| 3,427 |
qemu | 42e4126b793d15ec40f3a84017e1d8afecda1b6d | 1 | uint32_t pci_data_read(PCIBus *s, uint32_t addr, int len)
{
PCIDevice *pci_dev = pci_dev_find_by_addr(s, addr);
uint32_t config_addr = addr & (PCI_CONFIG_SPACE_SIZE - 1);
uint32_t val;
assert(len == 1 || len == 2 || len == 4);
if (!pci_dev) {
return ~0x0;
}
val = pci_dev->config_read(pci_dev, config_addr, len);
PCI_DPRINTF("%s: %s: addr=%02"PRIx32" val=%08"PRIx32" len=%d\n",
__func__, pci_dev->name, config_addr, val, len);
return val;
}
| 3,428 |
FFmpeg | 0424e052f83adc422d8a746e3cdc5ab6bc28679e | 1 | static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size){
MpegEncContext * const s = &h->s;
AVCodecContext * const avctx= s->avctx;
int buf_index=0;
H264Context *hx; ///< thread context
int context_count = 0;
int next_avc= h->is_avc ? 0 : buf_size;
h->max_contexts = (HAVE_THREADS && (s->avctx->active_thread_type&FF_THREAD_SLICE)) ? avctx->thread_count : 1;
#if 0
int i;
for(i=0; i<50; i++){
av_log(NULL, AV_LOG_ERROR,"%02X ", buf[i]);
}
#endif
if(!(s->flags2 & CODEC_FLAG2_CHUNKS)){
h->current_slice = 0;
if (!s->first_field)
s->current_picture_ptr= NULL;
ff_h264_reset_sei(h);
}
for(;;){
int consumed;
int dst_length;
int bit_length;
const uint8_t *ptr;
int i, nalsize = 0;
int err;
if(buf_index >= next_avc) {
if(buf_index >= buf_size) break;
nalsize = 0;
for(i = 0; i < h->nal_length_size; i++)
nalsize = (nalsize << 8) | buf[buf_index++];
if(nalsize <= 0 || nalsize > buf_size - buf_index){
av_log(h->s.avctx, AV_LOG_ERROR, "AVC: nal size %d\n", nalsize);
break;
}
next_avc= buf_index + nalsize;
} else {
// start code prefix search
for(; buf_index + 3 < next_avc; buf_index++){
// This should always succeed in the first iteration.
if(buf[buf_index] == 0 && buf[buf_index+1] == 0 && buf[buf_index+2] == 1)
break;
}
if(buf_index+3 >= buf_size) break;
buf_index+=3;
if(buf_index >= next_avc) continue;
}
hx = h->thread_context[context_count];
ptr= ff_h264_decode_nal(hx, buf + buf_index, &dst_length, &consumed, next_avc - buf_index);
if (ptr==NULL || dst_length < 0){
return -1;
}
i= buf_index + consumed;
if((s->workaround_bugs & FF_BUG_AUTODETECT) && i+3<next_avc &&
buf[i]==0x00 && buf[i+1]==0x00 && buf[i+2]==0x01 && buf[i+3]==0xE0)
s->workaround_bugs |= FF_BUG_TRUNCATED;
if(!(s->workaround_bugs & FF_BUG_TRUNCATED)){
while(ptr[dst_length - 1] == 0 && dst_length > 0)
dst_length--;
}
bit_length= !dst_length ? 0 : (8*dst_length - ff_h264_decode_rbsp_trailing(h, ptr + dst_length - 1));
if(s->avctx->debug&FF_DEBUG_STARTCODE){
av_log(h->s.avctx, AV_LOG_DEBUG, "NAL %d/%d at %d/%d length %d\n", hx->nal_unit_type, hx->nal_ref_idc, buf_index, buf_size, dst_length);
}
if (h->is_avc && (nalsize != consumed) && nalsize){
av_log(h->s.avctx, AV_LOG_DEBUG, "AVC: Consumed only %d bytes instead of %d\n", consumed, nalsize);
}
buf_index += consumed;
//FIXME do not discard SEI id
if(avctx->skip_frame >= AVDISCARD_NONREF && h->nal_ref_idc == 0)
continue;
again:
err = 0;
switch(hx->nal_unit_type){
case NAL_IDR_SLICE:
if (h->nal_unit_type != NAL_IDR_SLICE) {
av_log(h->s.avctx, AV_LOG_ERROR, "Invalid mix of idr and non-idr slices");
return -1;
}
idr(h); //FIXME ensure we don't loose some frames if there is reordering
case NAL_SLICE:
init_get_bits(&hx->s.gb, ptr, bit_length);
hx->intra_gb_ptr=
hx->inter_gb_ptr= &hx->s.gb;
hx->s.data_partitioning = 0;
if((err = decode_slice_header(hx, h)))
break;
s->current_picture_ptr->key_frame |=
(hx->nal_unit_type == NAL_IDR_SLICE) ||
(h->sei_recovery_frame_cnt >= 0);
if (h->current_slice == 1) {
if(!(s->flags2 & CODEC_FLAG2_CHUNKS)) {
decode_postinit(h);
}
if (s->avctx->hwaccel && s->avctx->hwaccel->start_frame(s->avctx, NULL, 0) < 0)
return -1;
if(CONFIG_H264_VDPAU_DECODER && s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU)
ff_vdpau_h264_picture_start(s);
}
if(hx->redundant_pic_count==0
&& (avctx->skip_frame < AVDISCARD_NONREF || hx->nal_ref_idc)
&& (avctx->skip_frame < AVDISCARD_BIDIR || hx->slice_type_nos!=AV_PICTURE_TYPE_B)
&& (avctx->skip_frame < AVDISCARD_NONKEY || hx->slice_type_nos==AV_PICTURE_TYPE_I)
&& avctx->skip_frame < AVDISCARD_ALL){
if(avctx->hwaccel) {
if (avctx->hwaccel->decode_slice(avctx, &buf[buf_index - consumed], consumed) < 0)
return -1;
}else
if(CONFIG_H264_VDPAU_DECODER && s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU){
static const uint8_t start_code[] = {0x00, 0x00, 0x01};
ff_vdpau_add_data_chunk(s, start_code, sizeof(start_code));
ff_vdpau_add_data_chunk(s, &buf[buf_index - consumed], consumed );
}else
context_count++;
}
break;
case NAL_DPA:
init_get_bits(&hx->s.gb, ptr, bit_length);
hx->intra_gb_ptr=
hx->inter_gb_ptr= NULL;
if ((err = decode_slice_header(hx, h)) < 0)
break;
hx->s.data_partitioning = 1;
break;
case NAL_DPB:
init_get_bits(&hx->intra_gb, ptr, bit_length);
hx->intra_gb_ptr= &hx->intra_gb;
break;
case NAL_DPC:
init_get_bits(&hx->inter_gb, ptr, bit_length);
hx->inter_gb_ptr= &hx->inter_gb;
if(hx->redundant_pic_count==0 && hx->intra_gb_ptr && hx->s.data_partitioning
&& s->context_initialized
&& (avctx->skip_frame < AVDISCARD_NONREF || hx->nal_ref_idc)
&& (avctx->skip_frame < AVDISCARD_BIDIR || hx->slice_type_nos!=AV_PICTURE_TYPE_B)
&& (avctx->skip_frame < AVDISCARD_NONKEY || hx->slice_type_nos==AV_PICTURE_TYPE_I)
&& avctx->skip_frame < AVDISCARD_ALL)
context_count++;
break;
case NAL_SEI:
init_get_bits(&s->gb, ptr, bit_length);
ff_h264_decode_sei(h);
break;
case NAL_SPS:
init_get_bits(&s->gb, ptr, bit_length);
ff_h264_decode_seq_parameter_set(h);
if(s->flags& CODEC_FLAG_LOW_DELAY ||
(h->sps.bitstream_restriction_flag && !h->sps.num_reorder_frames))
s->low_delay=1;
if(avctx->has_b_frames < 2)
avctx->has_b_frames= !s->low_delay;
if (avctx->bits_per_raw_sample != h->sps.bit_depth_luma) {
if (h->sps.bit_depth_luma >= 8 && h->sps.bit_depth_luma <= 10) {
avctx->bits_per_raw_sample = h->sps.bit_depth_luma;
h->pixel_shift = h->sps.bit_depth_luma > 8;
ff_h264dsp_init(&h->h264dsp, h->sps.bit_depth_luma);
ff_h264_pred_init(&h->hpc, s->codec_id, h->sps.bit_depth_luma);
dsputil_init(&s->dsp, s->avctx);
} else {
av_log(avctx, AV_LOG_DEBUG, "Unsupported bit depth: %d\n", h->sps.bit_depth_luma);
return -1;
}
}
break;
case NAL_PPS:
init_get_bits(&s->gb, ptr, bit_length);
ff_h264_decode_picture_parameter_set(h, bit_length);
break;
case NAL_AUD:
case NAL_END_SEQUENCE:
case NAL_END_STREAM:
case NAL_FILLER_DATA:
case NAL_SPS_EXT:
case NAL_AUXILIARY_SLICE:
break;
default:
av_log(avctx, AV_LOG_DEBUG, "Unknown NAL code: %d (%d bits)\n", hx->nal_unit_type, bit_length);
}
if(context_count == h->max_contexts) {
execute_decode_slices(h, context_count);
context_count = 0;
}
if (err < 0)
av_log(h->s.avctx, AV_LOG_ERROR, "decode_slice_header error\n");
else if(err == 1) {
/* Slice could not be decoded in parallel mode, copy down
* NAL unit stuff to context 0 and restart. Note that
* rbsp_buffer is not transferred, but since we no longer
* run in parallel mode this should not be an issue. */
h->nal_unit_type = hx->nal_unit_type;
h->nal_ref_idc = hx->nal_ref_idc;
hx = h;
goto again;
}
}
if(context_count)
execute_decode_slices(h, context_count);
return buf_index;
}
| 3,429 |
FFmpeg | 4c7b023d56e09a78a587d036db1b64bf7c493b3d | 0 | static int nvdec_vc1_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
{
NVDECContext *ctx = avctx->internal->hwaccel_priv_data;
void *tmp;
tmp = av_fast_realloc(ctx->slice_offsets, &ctx->slice_offsets_allocated,
(ctx->nb_slices + 1) * sizeof(*ctx->slice_offsets));
if (!tmp)
return AVERROR(ENOMEM);
ctx->slice_offsets = tmp;
if (!ctx->bitstream)
ctx->bitstream = (uint8_t*)buffer;
ctx->slice_offsets[ctx->nb_slices] = buffer - ctx->bitstream;
ctx->bitstream_len += size;
ctx->nb_slices++;
return 0;
}
| 3,430 |
qemu | 0919ac787641db11024912651f3bc5764d4f1286 | 0 | static void omap2_inth_write(void *opaque, target_phys_addr_t addr,
uint64_t value, unsigned size)
{
struct omap_intr_handler_s *s = (struct omap_intr_handler_s *) opaque;
int offset = addr;
int bank_no, line_no;
struct omap_intr_handler_bank_s *bank = NULL;
if ((offset & 0xf80) == 0x80) {
bank_no = (offset & 0x60) >> 5;
if (bank_no < s->nbanks) {
offset &= ~0x60;
bank = &s->bank[bank_no];
}
}
switch (offset) {
case 0x10: /* INTC_SYSCONFIG */
s->autoidle &= 4;
s->autoidle |= (value & 1) << 2;
if (value & 2) /* SOFTRESET */
omap_inth_reset(s);
return;
case 0x48: /* INTC_CONTROL */
s->mask = (value & 4) ? 0 : ~0; /* GLOBALMASK */
if (value & 2) { /* NEWFIQAGR */
qemu_set_irq(s->parent_intr[1], 0);
s->new_agr[1] = ~0;
omap_inth_update(s, 1);
}
if (value & 1) { /* NEWIRQAGR */
qemu_set_irq(s->parent_intr[0], 0);
s->new_agr[0] = ~0;
omap_inth_update(s, 0);
}
return;
case 0x4c: /* INTC_PROTECTION */
/* TODO: Make a bitmap (or sizeof(char)map) of access privileges
* for every register, see Chapter 3 and 4 for privileged mode. */
if (value & 1)
fprintf(stderr, "%s: protection mode enable attempt\n",
__FUNCTION__);
return;
case 0x50: /* INTC_IDLE */
s->autoidle &= ~3;
s->autoidle |= value & 3;
return;
/* Per-bank registers */
case 0x84: /* INTC_MIR */
bank->mask = value;
omap_inth_update(s, 0);
omap_inth_update(s, 1);
return;
case 0x88: /* INTC_MIR_CLEAR */
bank->mask &= ~value;
omap_inth_update(s, 0);
omap_inth_update(s, 1);
return;
case 0x8c: /* INTC_MIR_SET */
bank->mask |= value;
return;
case 0x90: /* INTC_ISR_SET */
bank->irqs |= bank->swi |= value;
omap_inth_update(s, 0);
omap_inth_update(s, 1);
return;
case 0x94: /* INTC_ISR_CLEAR */
bank->swi &= ~value;
bank->irqs = bank->swi & bank->inputs;
return;
/* Per-line registers */
case 0x100 ... 0x300: /* INTC_ILR */
bank_no = (offset - 0x100) >> 7;
if (bank_no > s->nbanks)
break;
bank = &s->bank[bank_no];
line_no = (offset & 0x7f) >> 2;
bank->priority[line_no] = (value >> 2) & 0x3f;
bank->fiq &= ~(1 << line_no);
bank->fiq |= (value & 1) << line_no;
return;
case 0x00: /* INTC_REVISION */
case 0x14: /* INTC_SYSSTATUS */
case 0x40: /* INTC_SIR_IRQ */
case 0x44: /* INTC_SIR_FIQ */
case 0x80: /* INTC_ITR */
case 0x98: /* INTC_PENDING_IRQ */
case 0x9c: /* INTC_PENDING_FIQ */
OMAP_RO_REG(addr);
return;
}
OMAP_BAD_REG(addr);
}
| 3,431 |
qemu | aea390e4be652d5b5457771d25eded0dba14fe37 | 0 | static bool pte32_match(target_ulong pte0, target_ulong pte1,
bool secondary, target_ulong ptem)
{
return (pte0 & HPTE32_V_VALID)
&& (secondary == !!(pte0 & HPTE32_V_SECONDARY))
&& HPTE32_V_COMPARE(pte0, ptem);
}
| 3,432 |
qemu | ee951a37d8873bff7aa58e23222dfd984111b6cb | 0 | static int hpet_init(SysBusDevice *dev)
{
HPETState *s = FROM_SYSBUS(HPETState, dev);
int i, iomemtype;
HPETTimer *timer;
if (hpet_cfg.count == UINT8_MAX) {
/* first instance */
hpet_cfg.count = 0;
}
if (hpet_cfg.count == 8) {
fprintf(stderr, "Only 8 instances of HPET is allowed\n");
return -1;
}
s->hpet_id = hpet_cfg.count++;
for (i = 0; i < HPET_NUM_IRQ_ROUTES; i++) {
sysbus_init_irq(dev, &s->irqs[i]);
}
if (s->num_timers < HPET_MIN_TIMERS) {
s->num_timers = HPET_MIN_TIMERS;
} else if (s->num_timers > HPET_MAX_TIMERS) {
s->num_timers = HPET_MAX_TIMERS;
}
for (i = 0; i < HPET_MAX_TIMERS; i++) {
timer = &s->timer[i];
timer->qemu_timer = qemu_new_timer(vm_clock, hpet_timer, timer);
timer->tn = i;
timer->state = s;
}
/* 64-bit main counter; LegacyReplacementRoute. */
s->capability = 0x8086a001ULL;
s->capability |= (s->num_timers - 1) << HPET_ID_NUM_TIM_SHIFT;
s->capability |= ((HPET_CLK_PERIOD) << 32);
isa_reserve_irq(RTC_ISA_IRQ);
qdev_init_gpio_in(&dev->qdev, hpet_handle_rtc_irq, 1);
/* HPET Area */
iomemtype = cpu_register_io_memory(hpet_ram_read,
hpet_ram_write, s,
DEVICE_NATIVE_ENDIAN);
sysbus_init_mmio(dev, 0x400, iomemtype);
return 0;
}
| 3,433 |
qemu | 3941bf6fb1c98a39bf8a0cfb4feacaef2a23d0db | 0 | static int send_png_rect(VncState *vs, int x, int y, int w, int h,
QDict *palette)
{
png_byte color_type;
png_structp png_ptr;
png_infop info_ptr;
png_colorp png_palette = NULL;
size_t offset;
int level = tight_conf[vs->tight_compression].raw_zlib_level;
uint8_t *buf;
int dy;
png_ptr = png_create_write_struct_2(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL,
NULL, vnc_png_malloc, vnc_png_free);
if (png_ptr == NULL)
return -1;
info_ptr = png_create_info_struct(png_ptr);
if (info_ptr == NULL) {
png_destroy_write_struct(&png_ptr, NULL);
return -1;
}
png_set_write_fn(png_ptr, (void *) vs, png_write_data, png_flush_data);
png_set_compression_level(png_ptr, level);
if (palette) {
color_type = PNG_COLOR_TYPE_PALETTE;
} else {
color_type = PNG_COLOR_TYPE_RGB;
}
png_set_IHDR(png_ptr, info_ptr, w, h,
8, color_type, PNG_INTERLACE_NONE,
PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
if (color_type == PNG_COLOR_TYPE_PALETTE) {
struct palette_cb_priv priv;
png_palette = png_malloc(png_ptr, sizeof(*png_palette) *
qdict_size(palette));
priv.vs = vs;
priv.png_palette = png_palette;
qdict_iter(palette, write_png_palette, &priv);
png_set_PLTE(png_ptr, info_ptr, png_palette, qdict_size(palette));
offset = vs->tight.offset;
if (vs->clientds.pf.bytes_per_pixel == 4) {
tight_encode_indexed_rect32(vs->tight.buffer, w * h, palette);
} else {
tight_encode_indexed_rect16(vs->tight.buffer, w * h, palette);
}
}
png_write_info(png_ptr, info_ptr);
buffer_reserve(&vs->tight_png, 2048);
buf = qemu_malloc(w * 3);
for (dy = 0; dy < h; dy++)
{
if (color_type == PNG_COLOR_TYPE_PALETTE) {
memcpy(buf, vs->tight.buffer + (dy * w), w);
} else {
rgb_prepare_row(vs, buf, x, y + dy, w);
}
png_write_row(png_ptr, buf);
}
qemu_free(buf);
png_write_end(png_ptr, NULL);
if (color_type == PNG_COLOR_TYPE_PALETTE) {
png_free(png_ptr, png_palette);
}
png_destroy_write_struct(&png_ptr, &info_ptr);
vnc_write_u8(vs, VNC_TIGHT_PNG << 4);
tight_send_compact_size(vs, vs->tight_png.offset);
vnc_write(vs, vs->tight_png.buffer, vs->tight_png.offset);
buffer_reset(&vs->tight_png);
return 1;
}
| 3,434 |
qemu | ac531cb6e542b1e61d668604adf9dc5306a948c0 | 0 | START_TEST(qdict_put_exists_test)
{
int value;
const char *key = "exists";
qdict_put(tests_dict, key, qint_from_int(1));
qdict_put(tests_dict, key, qint_from_int(2));
value = qdict_get_int(tests_dict, key);
fail_unless(value == 2);
fail_unless(qdict_size(tests_dict) == 1);
}
| 3,435 |
qemu | a8170e5e97ad17ca169c64ba87ae2f53850dab4c | 0 | static void gt64120_writel (void *opaque, target_phys_addr_t addr,
uint64_t val, unsigned size)
{
GT64120State *s = opaque;
PCIHostState *phb = PCI_HOST_BRIDGE(s);
uint32_t saddr;
if (!(s->regs[GT_CPU] & 0x00001000))
val = bswap32(val);
saddr = (addr & 0xfff) >> 2;
switch (saddr) {
/* CPU Configuration */
case GT_CPU:
s->regs[GT_CPU] = val;
break;
case GT_MULTI:
/* Read-only register as only one GT64xxx is present on the CPU bus */
break;
/* CPU Address Decode */
case GT_PCI0IOLD:
s->regs[GT_PCI0IOLD] = val & 0x00007fff;
s->regs[GT_PCI0IOREMAP] = val & 0x000007ff;
gt64120_pci_mapping(s);
break;
case GT_PCI0M0LD:
s->regs[GT_PCI0M0LD] = val & 0x00007fff;
s->regs[GT_PCI0M0REMAP] = val & 0x000007ff;
break;
case GT_PCI0M1LD:
s->regs[GT_PCI0M1LD] = val & 0x00007fff;
s->regs[GT_PCI0M1REMAP] = val & 0x000007ff;
break;
case GT_PCI1IOLD:
s->regs[GT_PCI1IOLD] = val & 0x00007fff;
s->regs[GT_PCI1IOREMAP] = val & 0x000007ff;
break;
case GT_PCI1M0LD:
s->regs[GT_PCI1M0LD] = val & 0x00007fff;
s->regs[GT_PCI1M0REMAP] = val & 0x000007ff;
break;
case GT_PCI1M1LD:
s->regs[GT_PCI1M1LD] = val & 0x00007fff;
s->regs[GT_PCI1M1REMAP] = val & 0x000007ff;
break;
case GT_PCI0IOHD:
s->regs[saddr] = val & 0x0000007f;
gt64120_pci_mapping(s);
break;
case GT_PCI0M0HD:
case GT_PCI0M1HD:
case GT_PCI1IOHD:
case GT_PCI1M0HD:
case GT_PCI1M1HD:
s->regs[saddr] = val & 0x0000007f;
break;
case GT_ISD:
s->regs[saddr] = val & 0x00007fff;
gt64120_isd_mapping(s);
break;
case GT_PCI0IOREMAP:
case GT_PCI0M0REMAP:
case GT_PCI0M1REMAP:
case GT_PCI1IOREMAP:
case GT_PCI1M0REMAP:
case GT_PCI1M1REMAP:
s->regs[saddr] = val & 0x000007ff;
break;
/* CPU Error Report */
case GT_CPUERR_ADDRLO:
case GT_CPUERR_ADDRHI:
case GT_CPUERR_DATALO:
case GT_CPUERR_DATAHI:
case GT_CPUERR_PARITY:
/* Read-only registers, do nothing */
break;
/* CPU Sync Barrier */
case GT_PCI0SYNC:
case GT_PCI1SYNC:
/* Read-only registers, do nothing */
break;
/* SDRAM and Device Address Decode */
case GT_SCS0LD:
case GT_SCS0HD:
case GT_SCS1LD:
case GT_SCS1HD:
case GT_SCS2LD:
case GT_SCS2HD:
case GT_SCS3LD:
case GT_SCS3HD:
case GT_CS0LD:
case GT_CS0HD:
case GT_CS1LD:
case GT_CS1HD:
case GT_CS2LD:
case GT_CS2HD:
case GT_CS3LD:
case GT_CS3HD:
case GT_BOOTLD:
case GT_BOOTHD:
case GT_ADERR:
/* SDRAM Configuration */
case GT_SDRAM_CFG:
case GT_SDRAM_OPMODE:
case GT_SDRAM_BM:
case GT_SDRAM_ADDRDECODE:
/* Accept and ignore SDRAM interleave configuration */
s->regs[saddr] = val;
break;
/* Device Parameters */
case GT_DEV_B0:
case GT_DEV_B1:
case GT_DEV_B2:
case GT_DEV_B3:
case GT_DEV_BOOT:
/* Not implemented */
DPRINTF ("Unimplemented device register offset 0x%x\n", saddr << 2);
break;
/* ECC */
case GT_ECC_ERRDATALO:
case GT_ECC_ERRDATAHI:
case GT_ECC_MEM:
case GT_ECC_CALC:
case GT_ECC_ERRADDR:
/* Read-only registers, do nothing */
break;
/* DMA Record */
case GT_DMA0_CNT:
case GT_DMA1_CNT:
case GT_DMA2_CNT:
case GT_DMA3_CNT:
case GT_DMA0_SA:
case GT_DMA1_SA:
case GT_DMA2_SA:
case GT_DMA3_SA:
case GT_DMA0_DA:
case GT_DMA1_DA:
case GT_DMA2_DA:
case GT_DMA3_DA:
case GT_DMA0_NEXT:
case GT_DMA1_NEXT:
case GT_DMA2_NEXT:
case GT_DMA3_NEXT:
case GT_DMA0_CUR:
case GT_DMA1_CUR:
case GT_DMA2_CUR:
case GT_DMA3_CUR:
/* Not implemented */
DPRINTF ("Unimplemented DMA register offset 0x%x\n", saddr << 2);
break;
/* DMA Channel Control */
case GT_DMA0_CTRL:
case GT_DMA1_CTRL:
case GT_DMA2_CTRL:
case GT_DMA3_CTRL:
/* Not implemented */
DPRINTF ("Unimplemented DMA register offset 0x%x\n", saddr << 2);
break;
/* DMA Arbiter */
case GT_DMA_ARB:
/* Not implemented */
DPRINTF ("Unimplemented DMA register offset 0x%x\n", saddr << 2);
break;
/* Timer/Counter */
case GT_TC0:
case GT_TC1:
case GT_TC2:
case GT_TC3:
case GT_TC_CONTROL:
/* Not implemented */
DPRINTF ("Unimplemented timer register offset 0x%x\n", saddr << 2);
break;
/* PCI Internal */
case GT_PCI0_CMD:
case GT_PCI1_CMD:
s->regs[saddr] = val & 0x0401fc0f;
break;
case GT_PCI0_TOR:
case GT_PCI0_BS_SCS10:
case GT_PCI0_BS_SCS32:
case GT_PCI0_BS_CS20:
case GT_PCI0_BS_CS3BT:
case GT_PCI1_IACK:
case GT_PCI0_IACK:
case GT_PCI0_BARE:
case GT_PCI0_PREFMBR:
case GT_PCI0_SCS10_BAR:
case GT_PCI0_SCS32_BAR:
case GT_PCI0_CS20_BAR:
case GT_PCI0_CS3BT_BAR:
case GT_PCI0_SSCS10_BAR:
case GT_PCI0_SSCS32_BAR:
case GT_PCI0_SCS3BT_BAR:
case GT_PCI1_TOR:
case GT_PCI1_BS_SCS10:
case GT_PCI1_BS_SCS32:
case GT_PCI1_BS_CS20:
case GT_PCI1_BS_CS3BT:
case GT_PCI1_BARE:
case GT_PCI1_PREFMBR:
case GT_PCI1_SCS10_BAR:
case GT_PCI1_SCS32_BAR:
case GT_PCI1_CS20_BAR:
case GT_PCI1_CS3BT_BAR:
case GT_PCI1_SSCS10_BAR:
case GT_PCI1_SSCS32_BAR:
case GT_PCI1_SCS3BT_BAR:
case GT_PCI1_CFGADDR:
case GT_PCI1_CFGDATA:
/* not implemented */
break;
case GT_PCI0_CFGADDR:
phb->config_reg = val & 0x80fffffc;
break;
case GT_PCI0_CFGDATA:
if (!(s->regs[GT_PCI0_CMD] & 1) && (phb->config_reg & 0x00fff800)) {
val = bswap32(val);
}
if (phb->config_reg & (1u << 31)) {
pci_data_write(phb->bus, phb->config_reg, val, 4);
}
break;
/* Interrupts */
case GT_INTRCAUSE:
/* not really implemented */
s->regs[saddr] = ~(~(s->regs[saddr]) | ~(val & 0xfffffffe));
s->regs[saddr] |= !!(s->regs[saddr] & 0xfffffffe);
DPRINTF("INTRCAUSE %" PRIx64 "\n", val);
break;
case GT_INTRMASK:
s->regs[saddr] = val & 0x3c3ffffe;
DPRINTF("INTRMASK %" PRIx64 "\n", val);
break;
case GT_PCI0_ICMASK:
s->regs[saddr] = val & 0x03fffffe;
DPRINTF("ICMASK %" PRIx64 "\n", val);
break;
case GT_PCI0_SERR0MASK:
s->regs[saddr] = val & 0x0000003f;
DPRINTF("SERR0MASK %" PRIx64 "\n", val);
break;
/* Reserved when only PCI_0 is configured. */
case GT_HINTRCAUSE:
case GT_CPU_INTSEL:
case GT_PCI0_INTSEL:
case GT_HINTRMASK:
case GT_PCI0_HICMASK:
case GT_PCI1_SERR1MASK:
/* not implemented */
break;
/* SDRAM Parameters */
case GT_SDRAM_B0:
case GT_SDRAM_B1:
case GT_SDRAM_B2:
case GT_SDRAM_B3:
/* We don't simulate electrical parameters of the SDRAM.
Accept, but ignore the values. */
s->regs[saddr] = val;
break;
default:
DPRINTF ("Bad register offset 0x%x\n", (int)addr);
break;
}
}
| 3,438 |
qemu | 36e60ef6ac5d8a262d0fbeedfdb2b588514cb1ea | 0 | static void tcg_constant_folding(TCGContext *s)
{
int oi, oi_next, nb_temps, nb_globals;
/* Array VALS has an element for each temp.
If this temp holds a constant then its value is kept in VALS' element.
If this temp is a copy of other ones then the other copies are
available through the doubly linked circular list. */
nb_temps = s->nb_temps;
nb_globals = s->nb_globals;
reset_all_temps(nb_temps);
for (oi = s->gen_first_op_idx; oi >= 0; oi = oi_next) {
tcg_target_ulong mask, partmask, affected;
int nb_oargs, nb_iargs, i;
TCGArg tmp;
TCGOp * const op = &s->gen_op_buf[oi];
TCGArg * const args = &s->gen_opparam_buf[op->args];
TCGOpcode opc = op->opc;
const TCGOpDef *def = &tcg_op_defs[opc];
oi_next = op->next;
if (opc == INDEX_op_call) {
nb_oargs = op->callo;
nb_iargs = op->calli;
} else {
nb_oargs = def->nb_oargs;
nb_iargs = def->nb_iargs;
}
/* Do copy propagation */
for (i = nb_oargs; i < nb_oargs + nb_iargs; i++) {
if (temps[args[i]].state == TCG_TEMP_COPY) {
args[i] = find_better_copy(s, args[i]);
}
}
/* For commutative operations make constant second argument */
switch (opc) {
CASE_OP_32_64(add):
CASE_OP_32_64(mul):
CASE_OP_32_64(and):
CASE_OP_32_64(or):
CASE_OP_32_64(xor):
CASE_OP_32_64(eqv):
CASE_OP_32_64(nand):
CASE_OP_32_64(nor):
CASE_OP_32_64(muluh):
CASE_OP_32_64(mulsh):
swap_commutative(args[0], &args[1], &args[2]);
break;
CASE_OP_32_64(brcond):
if (swap_commutative(-1, &args[0], &args[1])) {
args[2] = tcg_swap_cond(args[2]);
}
break;
CASE_OP_32_64(setcond):
if (swap_commutative(args[0], &args[1], &args[2])) {
args[3] = tcg_swap_cond(args[3]);
}
break;
CASE_OP_32_64(movcond):
if (swap_commutative(-1, &args[1], &args[2])) {
args[5] = tcg_swap_cond(args[5]);
}
/* For movcond, we canonicalize the "false" input reg to match
the destination reg so that the tcg backend can implement
a "move if true" operation. */
if (swap_commutative(args[0], &args[4], &args[3])) {
args[5] = tcg_invert_cond(args[5]);
}
break;
CASE_OP_32_64(add2):
swap_commutative(args[0], &args[2], &args[4]);
swap_commutative(args[1], &args[3], &args[5]);
break;
CASE_OP_32_64(mulu2):
CASE_OP_32_64(muls2):
swap_commutative(args[0], &args[2], &args[3]);
break;
case INDEX_op_brcond2_i32:
if (swap_commutative2(&args[0], &args[2])) {
args[4] = tcg_swap_cond(args[4]);
}
break;
case INDEX_op_setcond2_i32:
if (swap_commutative2(&args[1], &args[3])) {
args[5] = tcg_swap_cond(args[5]);
}
break;
default:
break;
}
/* Simplify expressions for "shift/rot r, 0, a => movi r, 0",
and "sub r, 0, a => neg r, a" case. */
switch (opc) {
CASE_OP_32_64(shl):
CASE_OP_32_64(shr):
CASE_OP_32_64(sar):
CASE_OP_32_64(rotl):
CASE_OP_32_64(rotr):
if (temps[args[1]].state == TCG_TEMP_CONST
&& temps[args[1]].val == 0) {
tcg_opt_gen_movi(s, op, args, args[0], 0);
continue;
}
break;
CASE_OP_32_64(sub):
{
TCGOpcode neg_op;
bool have_neg;
if (temps[args[2]].state == TCG_TEMP_CONST) {
/* Proceed with possible constant folding. */
break;
}
if (opc == INDEX_op_sub_i32) {
neg_op = INDEX_op_neg_i32;
have_neg = TCG_TARGET_HAS_neg_i32;
} else {
neg_op = INDEX_op_neg_i64;
have_neg = TCG_TARGET_HAS_neg_i64;
}
if (!have_neg) {
break;
}
if (temps[args[1]].state == TCG_TEMP_CONST
&& temps[args[1]].val == 0) {
op->opc = neg_op;
reset_temp(args[0]);
args[1] = args[2];
continue;
}
}
break;
CASE_OP_32_64(xor):
CASE_OP_32_64(nand):
if (temps[args[1]].state != TCG_TEMP_CONST
&& temps[args[2]].state == TCG_TEMP_CONST
&& temps[args[2]].val == -1) {
i = 1;
goto try_not;
}
break;
CASE_OP_32_64(nor):
if (temps[args[1]].state != TCG_TEMP_CONST
&& temps[args[2]].state == TCG_TEMP_CONST
&& temps[args[2]].val == 0) {
i = 1;
goto try_not;
}
break;
CASE_OP_32_64(andc):
if (temps[args[2]].state != TCG_TEMP_CONST
&& temps[args[1]].state == TCG_TEMP_CONST
&& temps[args[1]].val == -1) {
i = 2;
goto try_not;
}
break;
CASE_OP_32_64(orc):
CASE_OP_32_64(eqv):
if (temps[args[2]].state != TCG_TEMP_CONST
&& temps[args[1]].state == TCG_TEMP_CONST
&& temps[args[1]].val == 0) {
i = 2;
goto try_not;
}
break;
try_not:
{
TCGOpcode not_op;
bool have_not;
if (def->flags & TCG_OPF_64BIT) {
not_op = INDEX_op_not_i64;
have_not = TCG_TARGET_HAS_not_i64;
} else {
not_op = INDEX_op_not_i32;
have_not = TCG_TARGET_HAS_not_i32;
}
if (!have_not) {
break;
}
op->opc = not_op;
reset_temp(args[0]);
args[1] = args[i];
continue;
}
default:
break;
}
/* Simplify expression for "op r, a, const => mov r, a" cases */
switch (opc) {
CASE_OP_32_64(add):
CASE_OP_32_64(sub):
CASE_OP_32_64(shl):
CASE_OP_32_64(shr):
CASE_OP_32_64(sar):
CASE_OP_32_64(rotl):
CASE_OP_32_64(rotr):
CASE_OP_32_64(or):
CASE_OP_32_64(xor):
CASE_OP_32_64(andc):
if (temps[args[1]].state != TCG_TEMP_CONST
&& temps[args[2]].state == TCG_TEMP_CONST
&& temps[args[2]].val == 0) {
tcg_opt_gen_mov(s, op, args, args[0], args[1]);
continue;
}
break;
CASE_OP_32_64(and):
CASE_OP_32_64(orc):
CASE_OP_32_64(eqv):
if (temps[args[1]].state != TCG_TEMP_CONST
&& temps[args[2]].state == TCG_TEMP_CONST
&& temps[args[2]].val == -1) {
tcg_opt_gen_mov(s, op, args, args[0], args[1]);
continue;
}
break;
default:
break;
}
/* Simplify using known-zero bits. Currently only ops with a single
output argument is supported. */
mask = -1;
affected = -1;
switch (opc) {
CASE_OP_32_64(ext8s):
if ((temps[args[1]].mask & 0x80) != 0) {
break;
}
CASE_OP_32_64(ext8u):
mask = 0xff;
goto and_const;
CASE_OP_32_64(ext16s):
if ((temps[args[1]].mask & 0x8000) != 0) {
break;
}
CASE_OP_32_64(ext16u):
mask = 0xffff;
goto and_const;
case INDEX_op_ext32s_i64:
if ((temps[args[1]].mask & 0x80000000) != 0) {
break;
}
case INDEX_op_ext32u_i64:
mask = 0xffffffffU;
goto and_const;
CASE_OP_32_64(and):
mask = temps[args[2]].mask;
if (temps[args[2]].state == TCG_TEMP_CONST) {
and_const:
affected = temps[args[1]].mask & ~mask;
}
mask = temps[args[1]].mask & mask;
break;
CASE_OP_32_64(andc):
/* Known-zeros does not imply known-ones. Therefore unless
args[2] is constant, we can't infer anything from it. */
if (temps[args[2]].state == TCG_TEMP_CONST) {
mask = ~temps[args[2]].mask;
goto and_const;
}
/* But we certainly know nothing outside args[1] may be set. */
mask = temps[args[1]].mask;
break;
case INDEX_op_sar_i32:
if (temps[args[2]].state == TCG_TEMP_CONST) {
tmp = temps[args[2]].val & 31;
mask = (int32_t)temps[args[1]].mask >> tmp;
}
break;
case INDEX_op_sar_i64:
if (temps[args[2]].state == TCG_TEMP_CONST) {
tmp = temps[args[2]].val & 63;
mask = (int64_t)temps[args[1]].mask >> tmp;
}
break;
case INDEX_op_shr_i32:
if (temps[args[2]].state == TCG_TEMP_CONST) {
tmp = temps[args[2]].val & 31;
mask = (uint32_t)temps[args[1]].mask >> tmp;
}
break;
case INDEX_op_shr_i64:
if (temps[args[2]].state == TCG_TEMP_CONST) {
tmp = temps[args[2]].val & 63;
mask = (uint64_t)temps[args[1]].mask >> tmp;
}
break;
case INDEX_op_trunc_shr_i32:
mask = (uint64_t)temps[args[1]].mask >> args[2];
break;
CASE_OP_32_64(shl):
if (temps[args[2]].state == TCG_TEMP_CONST) {
tmp = temps[args[2]].val & (TCG_TARGET_REG_BITS - 1);
mask = temps[args[1]].mask << tmp;
}
break;
CASE_OP_32_64(neg):
/* Set to 1 all bits to the left of the rightmost. */
mask = -(temps[args[1]].mask & -temps[args[1]].mask);
break;
CASE_OP_32_64(deposit):
mask = deposit64(temps[args[1]].mask, args[3], args[4],
temps[args[2]].mask);
break;
CASE_OP_32_64(or):
CASE_OP_32_64(xor):
mask = temps[args[1]].mask | temps[args[2]].mask;
break;
CASE_OP_32_64(setcond):
case INDEX_op_setcond2_i32:
mask = 1;
break;
CASE_OP_32_64(movcond):
mask = temps[args[3]].mask | temps[args[4]].mask;
break;
CASE_OP_32_64(ld8u):
mask = 0xff;
break;
CASE_OP_32_64(ld16u):
mask = 0xffff;
break;
case INDEX_op_ld32u_i64:
mask = 0xffffffffu;
break;
CASE_OP_32_64(qemu_ld):
{
TCGMemOpIdx oi = args[nb_oargs + nb_iargs];
TCGMemOp mop = get_memop(oi);
if (!(mop & MO_SIGN)) {
mask = (2ULL << ((8 << (mop & MO_SIZE)) - 1)) - 1;
}
}
break;
default:
break;
}
/* 32-bit ops generate 32-bit results. For the result is zero test
below, we can ignore high bits, but for further optimizations we
need to record that the high bits contain garbage. */
partmask = mask;
if (!(def->flags & TCG_OPF_64BIT)) {
mask |= ~(tcg_target_ulong)0xffffffffu;
partmask &= 0xffffffffu;
affected &= 0xffffffffu;
}
if (partmask == 0) {
assert(nb_oargs == 1);
tcg_opt_gen_movi(s, op, args, args[0], 0);
continue;
}
if (affected == 0) {
assert(nb_oargs == 1);
tcg_opt_gen_mov(s, op, args, args[0], args[1]);
continue;
}
/* Simplify expression for "op r, a, 0 => movi r, 0" cases */
switch (opc) {
CASE_OP_32_64(and):
CASE_OP_32_64(mul):
CASE_OP_32_64(muluh):
CASE_OP_32_64(mulsh):
if ((temps[args[2]].state == TCG_TEMP_CONST
&& temps[args[2]].val == 0)) {
tcg_opt_gen_movi(s, op, args, args[0], 0);
continue;
}
break;
default:
break;
}
/* Simplify expression for "op r, a, a => mov r, a" cases */
switch (opc) {
CASE_OP_32_64(or):
CASE_OP_32_64(and):
if (temps_are_copies(args[1], args[2])) {
tcg_opt_gen_mov(s, op, args, args[0], args[1]);
continue;
}
break;
default:
break;
}
/* Simplify expression for "op r, a, a => movi r, 0" cases */
switch (opc) {
CASE_OP_32_64(andc):
CASE_OP_32_64(sub):
CASE_OP_32_64(xor):
if (temps_are_copies(args[1], args[2])) {
tcg_opt_gen_movi(s, op, args, args[0], 0);
continue;
}
break;
default:
break;
}
/* Propagate constants through copy operations and do constant
folding. Constants will be substituted to arguments by register
allocator where needed and possible. Also detect copies. */
switch (opc) {
CASE_OP_32_64(mov):
tcg_opt_gen_mov(s, op, args, args[0], args[1]);
break;
CASE_OP_32_64(movi):
tcg_opt_gen_movi(s, op, args, args[0], args[1]);
break;
CASE_OP_32_64(not):
CASE_OP_32_64(neg):
CASE_OP_32_64(ext8s):
CASE_OP_32_64(ext8u):
CASE_OP_32_64(ext16s):
CASE_OP_32_64(ext16u):
case INDEX_op_ext32s_i64:
case INDEX_op_ext32u_i64:
if (temps[args[1]].state == TCG_TEMP_CONST) {
tmp = do_constant_folding(opc, temps[args[1]].val, 0);
tcg_opt_gen_movi(s, op, args, args[0], tmp);
break;
}
goto do_default;
case INDEX_op_trunc_shr_i32:
if (temps[args[1]].state == TCG_TEMP_CONST) {
tmp = do_constant_folding(opc, temps[args[1]].val, args[2]);
tcg_opt_gen_movi(s, op, args, args[0], tmp);
break;
}
goto do_default;
CASE_OP_32_64(add):
CASE_OP_32_64(sub):
CASE_OP_32_64(mul):
CASE_OP_32_64(or):
CASE_OP_32_64(and):
CASE_OP_32_64(xor):
CASE_OP_32_64(shl):
CASE_OP_32_64(shr):
CASE_OP_32_64(sar):
CASE_OP_32_64(rotl):
CASE_OP_32_64(rotr):
CASE_OP_32_64(andc):
CASE_OP_32_64(orc):
CASE_OP_32_64(eqv):
CASE_OP_32_64(nand):
CASE_OP_32_64(nor):
CASE_OP_32_64(muluh):
CASE_OP_32_64(mulsh):
CASE_OP_32_64(div):
CASE_OP_32_64(divu):
CASE_OP_32_64(rem):
CASE_OP_32_64(remu):
if (temps[args[1]].state == TCG_TEMP_CONST
&& temps[args[2]].state == TCG_TEMP_CONST) {
tmp = do_constant_folding(opc, temps[args[1]].val,
temps[args[2]].val);
tcg_opt_gen_movi(s, op, args, args[0], tmp);
break;
}
goto do_default;
CASE_OP_32_64(deposit):
if (temps[args[1]].state == TCG_TEMP_CONST
&& temps[args[2]].state == TCG_TEMP_CONST) {
tmp = deposit64(temps[args[1]].val, args[3], args[4],
temps[args[2]].val);
tcg_opt_gen_movi(s, op, args, args[0], tmp);
break;
}
goto do_default;
CASE_OP_32_64(setcond):
tmp = do_constant_folding_cond(opc, args[1], args[2], args[3]);
if (tmp != 2) {
tcg_opt_gen_movi(s, op, args, args[0], tmp);
break;
}
goto do_default;
CASE_OP_32_64(brcond):
tmp = do_constant_folding_cond(opc, args[0], args[1], args[2]);
if (tmp != 2) {
if (tmp) {
reset_all_temps(nb_temps);
op->opc = INDEX_op_br;
args[0] = args[3];
} else {
tcg_op_remove(s, op);
}
break;
}
goto do_default;
CASE_OP_32_64(movcond):
tmp = do_constant_folding_cond(opc, args[1], args[2], args[5]);
if (tmp != 2) {
tcg_opt_gen_mov(s, op, args, args[0], args[4-tmp]);
break;
}
goto do_default;
case INDEX_op_add2_i32:
case INDEX_op_sub2_i32:
if (temps[args[2]].state == TCG_TEMP_CONST
&& temps[args[3]].state == TCG_TEMP_CONST
&& temps[args[4]].state == TCG_TEMP_CONST
&& temps[args[5]].state == TCG_TEMP_CONST) {
uint32_t al = temps[args[2]].val;
uint32_t ah = temps[args[3]].val;
uint32_t bl = temps[args[4]].val;
uint32_t bh = temps[args[5]].val;
uint64_t a = ((uint64_t)ah << 32) | al;
uint64_t b = ((uint64_t)bh << 32) | bl;
TCGArg rl, rh;
TCGOp *op2 = insert_op_before(s, op, INDEX_op_movi_i32, 2);
TCGArg *args2 = &s->gen_opparam_buf[op2->args];
if (opc == INDEX_op_add2_i32) {
a += b;
} else {
a -= b;
}
rl = args[0];
rh = args[1];
tcg_opt_gen_movi(s, op, args, rl, (uint32_t)a);
tcg_opt_gen_movi(s, op2, args2, rh, (uint32_t)(a >> 32));
/* We've done all we need to do with the movi. Skip it. */
oi_next = op2->next;
break;
}
goto do_default;
case INDEX_op_mulu2_i32:
if (temps[args[2]].state == TCG_TEMP_CONST
&& temps[args[3]].state == TCG_TEMP_CONST) {
uint32_t a = temps[args[2]].val;
uint32_t b = temps[args[3]].val;
uint64_t r = (uint64_t)a * b;
TCGArg rl, rh;
TCGOp *op2 = insert_op_before(s, op, INDEX_op_movi_i32, 2);
TCGArg *args2 = &s->gen_opparam_buf[op2->args];
rl = args[0];
rh = args[1];
tcg_opt_gen_movi(s, op, args, rl, (uint32_t)r);
tcg_opt_gen_movi(s, op2, args2, rh, (uint32_t)(r >> 32));
/* We've done all we need to do with the movi. Skip it. */
oi_next = op2->next;
break;
}
goto do_default;
case INDEX_op_brcond2_i32:
tmp = do_constant_folding_cond2(&args[0], &args[2], args[4]);
if (tmp != 2) {
if (tmp) {
do_brcond_true:
reset_all_temps(nb_temps);
op->opc = INDEX_op_br;
args[0] = args[5];
} else {
do_brcond_false:
tcg_op_remove(s, op);
}
} else if ((args[4] == TCG_COND_LT || args[4] == TCG_COND_GE)
&& temps[args[2]].state == TCG_TEMP_CONST
&& temps[args[3]].state == TCG_TEMP_CONST
&& temps[args[2]].val == 0
&& temps[args[3]].val == 0) {
/* Simplify LT/GE comparisons vs zero to a single compare
vs the high word of the input. */
do_brcond_high:
reset_all_temps(nb_temps);
op->opc = INDEX_op_brcond_i32;
args[0] = args[1];
args[1] = args[3];
args[2] = args[4];
args[3] = args[5];
} else if (args[4] == TCG_COND_EQ) {
/* Simplify EQ comparisons where one of the pairs
can be simplified. */
tmp = do_constant_folding_cond(INDEX_op_brcond_i32,
args[0], args[2], TCG_COND_EQ);
if (tmp == 0) {
goto do_brcond_false;
} else if (tmp == 1) {
goto do_brcond_high;
}
tmp = do_constant_folding_cond(INDEX_op_brcond_i32,
args[1], args[3], TCG_COND_EQ);
if (tmp == 0) {
goto do_brcond_false;
} else if (tmp != 1) {
goto do_default;
}
do_brcond_low:
reset_all_temps(nb_temps);
op->opc = INDEX_op_brcond_i32;
args[1] = args[2];
args[2] = args[4];
args[3] = args[5];
} else if (args[4] == TCG_COND_NE) {
/* Simplify NE comparisons where one of the pairs
can be simplified. */
tmp = do_constant_folding_cond(INDEX_op_brcond_i32,
args[0], args[2], TCG_COND_NE);
if (tmp == 0) {
goto do_brcond_high;
} else if (tmp == 1) {
goto do_brcond_true;
}
tmp = do_constant_folding_cond(INDEX_op_brcond_i32,
args[1], args[3], TCG_COND_NE);
if (tmp == 0) {
goto do_brcond_low;
} else if (tmp == 1) {
goto do_brcond_true;
}
goto do_default;
} else {
goto do_default;
}
break;
case INDEX_op_setcond2_i32:
tmp = do_constant_folding_cond2(&args[1], &args[3], args[5]);
if (tmp != 2) {
do_setcond_const:
tcg_opt_gen_movi(s, op, args, args[0], tmp);
} else if ((args[5] == TCG_COND_LT || args[5] == TCG_COND_GE)
&& temps[args[3]].state == TCG_TEMP_CONST
&& temps[args[4]].state == TCG_TEMP_CONST
&& temps[args[3]].val == 0
&& temps[args[4]].val == 0) {
/* Simplify LT/GE comparisons vs zero to a single compare
vs the high word of the input. */
do_setcond_high:
reset_temp(args[0]);
temps[args[0]].mask = 1;
op->opc = INDEX_op_setcond_i32;
args[1] = args[2];
args[2] = args[4];
args[3] = args[5];
} else if (args[5] == TCG_COND_EQ) {
/* Simplify EQ comparisons where one of the pairs
can be simplified. */
tmp = do_constant_folding_cond(INDEX_op_setcond_i32,
args[1], args[3], TCG_COND_EQ);
if (tmp == 0) {
goto do_setcond_const;
} else if (tmp == 1) {
goto do_setcond_high;
}
tmp = do_constant_folding_cond(INDEX_op_setcond_i32,
args[2], args[4], TCG_COND_EQ);
if (tmp == 0) {
goto do_setcond_high;
} else if (tmp != 1) {
goto do_default;
}
do_setcond_low:
reset_temp(args[0]);
temps[args[0]].mask = 1;
op->opc = INDEX_op_setcond_i32;
args[2] = args[3];
args[3] = args[5];
} else if (args[5] == TCG_COND_NE) {
/* Simplify NE comparisons where one of the pairs
can be simplified. */
tmp = do_constant_folding_cond(INDEX_op_setcond_i32,
args[1], args[3], TCG_COND_NE);
if (tmp == 0) {
goto do_setcond_high;
} else if (tmp == 1) {
goto do_setcond_const;
}
tmp = do_constant_folding_cond(INDEX_op_setcond_i32,
args[2], args[4], TCG_COND_NE);
if (tmp == 0) {
goto do_setcond_low;
} else if (tmp == 1) {
goto do_setcond_const;
}
goto do_default;
} else {
goto do_default;
}
break;
case INDEX_op_call:
if (!(args[nb_oargs + nb_iargs + 1]
& (TCG_CALL_NO_READ_GLOBALS | TCG_CALL_NO_WRITE_GLOBALS))) {
for (i = 0; i < nb_globals; i++) {
reset_temp(i);
}
}
goto do_reset_output;
default:
do_default:
/* Default case: we know nothing about operation (or were unable
to compute the operation result) so no propagation is done.
We trash everything if the operation is the end of a basic
block, otherwise we only trash the output args. "mask" is
the non-zero bits mask for the first output arg. */
if (def->flags & TCG_OPF_BB_END) {
reset_all_temps(nb_temps);
} else {
do_reset_output:
for (i = 0; i < nb_oargs; i++) {
reset_temp(args[i]);
/* Save the corresponding known-zero bits mask for the
first output argument (only one supported so far). */
if (i == 0) {
temps[args[i]].mask = mask;
}
}
}
break;
}
}
}
| 3,439 |
FFmpeg | 0242351390643d176b10600c2eb854414f9559e6 | 0 | static inline void qpel_motion(MpegEncContext *s,
uint8_t *dest_y,
uint8_t *dest_cb,
uint8_t *dest_cr,
int field_based, int bottom_field,
int field_select, uint8_t **ref_picture,
op_pixels_func (*pix_op)[4],
qpel_mc_func (*qpix_op)[16],
int motion_x, int motion_y, int h)
{
uint8_t *ptr_y, *ptr_cb, *ptr_cr;
int dxy, uvdxy, mx, my, src_x, src_y, uvsrc_x, uvsrc_y, v_edge_pos;
ptrdiff_t linesize, uvlinesize;
dxy = ((motion_y & 3) << 2) | (motion_x & 3);
src_x = s->mb_x * 16 + (motion_x >> 2);
src_y = s->mb_y * (16 >> field_based) + (motion_y >> 2);
v_edge_pos = s->v_edge_pos >> field_based;
linesize = s->linesize << field_based;
uvlinesize = s->uvlinesize << field_based;
if (field_based) {
mx = motion_x / 2;
my = motion_y >> 1;
} else if (s->workaround_bugs & FF_BUG_QPEL_CHROMA2) {
static const int rtab[8] = { 0, 0, 1, 1, 0, 0, 0, 1 };
mx = (motion_x >> 1) + rtab[motion_x & 7];
my = (motion_y >> 1) + rtab[motion_y & 7];
} else if (s->workaround_bugs & FF_BUG_QPEL_CHROMA) {
mx = (motion_x >> 1) | (motion_x & 1);
my = (motion_y >> 1) | (motion_y & 1);
} else {
mx = motion_x / 2;
my = motion_y / 2;
}
mx = (mx >> 1) | (mx & 1);
my = (my >> 1) | (my & 1);
uvdxy = (mx & 1) | ((my & 1) << 1);
mx >>= 1;
my >>= 1;
uvsrc_x = s->mb_x * 8 + mx;
uvsrc_y = s->mb_y * (8 >> field_based) + my;
ptr_y = ref_picture[0] + src_y * linesize + src_x;
ptr_cb = ref_picture[1] + uvsrc_y * uvlinesize + uvsrc_x;
ptr_cr = ref_picture[2] + uvsrc_y * uvlinesize + uvsrc_x;
if ((unsigned)src_x > FFMAX(s->h_edge_pos - (motion_x & 3) - 16, 0) ||
(unsigned)src_y > FFMAX(v_edge_pos - (motion_y & 3) - h, 0)) {
s->vdsp.emulated_edge_mc(s->sc.edge_emu_buffer, ptr_y,
s->linesize, s->linesize,
17, 17 + field_based,
src_x, src_y << field_based,
s->h_edge_pos, s->v_edge_pos);
ptr_y = s->sc.edge_emu_buffer;
if (!CONFIG_GRAY || !(s->avctx->flags & AV_CODEC_FLAG_GRAY)) {
uint8_t *uvbuf = s->sc.edge_emu_buffer + 18 * s->linesize;
s->vdsp.emulated_edge_mc(uvbuf, ptr_cb,
s->uvlinesize, s->uvlinesize,
9, 9 + field_based,
uvsrc_x, uvsrc_y << field_based,
s->h_edge_pos >> 1, s->v_edge_pos >> 1);
s->vdsp.emulated_edge_mc(uvbuf + 16, ptr_cr,
s->uvlinesize, s->uvlinesize,
9, 9 + field_based,
uvsrc_x, uvsrc_y << field_based,
s->h_edge_pos >> 1, s->v_edge_pos >> 1);
ptr_cb = uvbuf;
ptr_cr = uvbuf + 16;
}
}
if (!field_based)
qpix_op[0][dxy](dest_y, ptr_y, linesize);
else {
if (bottom_field) {
dest_y += s->linesize;
dest_cb += s->uvlinesize;
dest_cr += s->uvlinesize;
}
if (field_select) {
ptr_y += s->linesize;
ptr_cb += s->uvlinesize;
ptr_cr += s->uvlinesize;
}
// damn interlaced mode
// FIXME boundary mirroring is not exactly correct here
qpix_op[1][dxy](dest_y, ptr_y, linesize);
qpix_op[1][dxy](dest_y + 8, ptr_y + 8, linesize);
}
if (!CONFIG_GRAY || !(s->avctx->flags & AV_CODEC_FLAG_GRAY)) {
pix_op[1][uvdxy](dest_cr, ptr_cr, uvlinesize, h >> 1);
pix_op[1][uvdxy](dest_cb, ptr_cb, uvlinesize, h >> 1);
}
}
| 3,441 |
qemu | ac2567b59d9e4afbcc31c71840d7fe8ef4eee857 | 0 | void do_m68k_simcall(CPUM68KState *env, int nr)
{
uint32_t *args;
args = (uint32_t *)(env->aregs[7] + 4);
switch (nr) {
case SYS_EXIT:
exit(ARG(0));
case SYS_READ:
check_err(env, read(ARG(0), (void *)ARG(1), ARG(2)));
break;
case SYS_WRITE:
check_err(env, write(ARG(0), (void *)ARG(1), ARG(2)));
break;
case SYS_OPEN:
check_err(env, open((char *)ARG(0), translate_openflags(ARG(1)),
ARG(2)));
break;
case SYS_CLOSE:
{
/* Ignore attempts to close stdin/out/err. */
int fd = ARG(0);
if (fd > 2)
check_err(env, close(fd));
else
check_err(env, 0);
break;
}
case SYS_BRK:
{
int32_t ret;
ret = do_brk((void *)ARG(0));
if (ret == -ENOMEM)
ret = -1;
check_err(env, ret);
}
break;
case SYS_FSTAT:
{
struct stat s;
int rc;
struct m86k_sim_stat *p;
rc = check_err(env, fstat(ARG(0), &s));
if (rc == 0) {
p = (struct m86k_sim_stat *)ARG(1);
p->sim_st_dev = tswap16(s.st_dev);
p->sim_st_ino = tswap16(s.st_ino);
p->sim_st_mode = tswap32(s.st_mode);
p->sim_st_nlink = tswap16(s.st_nlink);
p->sim_st_uid = tswap16(s.st_uid);
p->sim_st_gid = tswap16(s.st_gid);
p->sim_st_rdev = tswap16(s.st_rdev);
p->sim_st_size = tswap32(s.st_size);
p->sim_st_atime = tswap32(s.st_atime);
p->sim_st_mtime = tswap32(s.st_mtime);
p->sim_st_ctime = tswap32(s.st_ctime);
p->sim_st_blksize = tswap32(s.st_blksize);
p->sim_st_blocks = tswap32(s.st_blocks);
}
}
break;
case SYS_ISATTY:
check_err(env, isatty(ARG(0)));
break;
case SYS_LSEEK:
check_err(env, lseek(ARG(0), (int32_t)ARG(1), ARG(2)));
break;
default:
cpu_abort(env, "Unsupported m68k sim syscall %d\n", nr);
}
}
| 3,442 |
qemu | 2569da0cb64506ea05323544c26f3aaffbf3f9fe | 0 | static void do_change(const char *device, const char *target, const char *fmt)
{
if (strcmp(device, "vnc") == 0) {
do_change_vnc(target);
} else {
do_change_block(device, target, fmt);
}
}
| 3,443 |
qemu | c2b38b277a7882a592f4f2ec955084b2b756daaa | 0 | aio_ctx_dispatch(GSource *source,
GSourceFunc callback,
gpointer user_data)
{
AioContext *ctx = (AioContext *) source;
assert(callback == NULL);
aio_dispatch(ctx, true);
return true;
}
| 3,444 |
qemu | e70377dfa4bbc2e101066ca35675bed4129c5a8c | 0 | S390PCIBusDevice *s390_pci_find_dev_by_fid(uint32_t fid)
{
S390PCIBusDevice *pbdev;
int i;
S390pciState *s = s390_get_phb();
for (i = 0; i < PCI_SLOT_MAX; i++) {
pbdev = s->pbdev[i];
if (pbdev && pbdev->fid == fid) {
return pbdev;
}
}
return NULL;
}
| 3,445 |
qemu | 59b060be184aff59cfa101c937c8139e66f452f2 | 0 | int qcrypto_pbkdf2_count_iters(QCryptoHashAlgorithm hash,
const uint8_t *key, size_t nkey,
const uint8_t *salt, size_t nsalt,
Error **errp)
{
uint8_t out[32];
long long int iterations = (1 << 15);
unsigned long long delta_ms, start_ms, end_ms;
while (1) {
if (qcrypto_pbkdf2_get_thread_cpu(&start_ms, errp) < 0) {
return -1;
}
if (qcrypto_pbkdf2(hash,
key, nkey,
salt, nsalt,
iterations,
out, sizeof(out),
errp) < 0) {
return -1;
}
if (qcrypto_pbkdf2_get_thread_cpu(&end_ms, errp) < 0) {
return -1;
}
delta_ms = end_ms - start_ms;
if (delta_ms > 500) {
break;
} else if (delta_ms < 100) {
iterations = iterations * 10;
} else {
iterations = (iterations * 1000 / delta_ms);
}
}
iterations = iterations * 1000 / delta_ms;
if (iterations > INT32_MAX) {
error_setg(errp, "Iterations %lld too large for a 32-bit int",
iterations);
return -1;
}
return iterations;
}
| 3,446 |
qemu | 7a0e58fa648736a75f2a6943afd2ab08ea15b8e0 | 0 | bool write_cpustate_to_list(ARMCPU *cpu)
{
/* Write the coprocessor state from cpu->env to the (index,value) list. */
int i;
bool ok = true;
for (i = 0; i < cpu->cpreg_array_len; i++) {
uint32_t regidx = kvm_to_cpreg_id(cpu->cpreg_indexes[i]);
const ARMCPRegInfo *ri;
ri = get_arm_cp_reginfo(cpu->cp_regs, regidx);
if (!ri) {
ok = false;
continue;
}
if (ri->type & ARM_CP_NO_MIGRATE) {
continue;
}
cpu->cpreg_values[i] = read_raw_cp_reg(&cpu->env, ri);
}
return ok;
}
| 3,447 |
qemu | 17e2377abf16c3951d7d34521ceade4d7dc31d01 | 0 | void *qemu_malloc(size_t size)
{
return malloc(size);
}
| 3,448 |
FFmpeg | d6737539e77e78fca9a04914d51996cfd1ccc55c | 0 | static void intra_predict_plane_16x16_msa(uint8_t *src, int32_t stride)
{
uint8_t lpcnt;
int32_t res0, res1, res2, res3;
uint64_t load0, load1;
v16i8 shf_mask = { 7, 8, 6, 9, 5, 10, 4, 11, 3, 12, 2, 13, 1, 14, 0, 15 };
v8i16 short_multiplier = { 1, 2, 3, 4, 5, 6, 7, 8 };
v4i32 int_multiplier = { 0, 1, 2, 3 };
v16u8 src_top = { 0 };
v8i16 vec9, vec10;
v4i32 vec0, vec1, vec2, vec3, vec4, vec5, vec6, vec7, vec8, res_add;
load0 = LD(src - (stride + 1));
load1 = LD(src - (stride + 1) + 9);
INSERT_D2_UB(load0, load1, src_top);
src_top = (v16u8) __msa_vshf_b(shf_mask, (v16i8) src_top, (v16i8) src_top);
vec9 = __msa_hsub_u_h(src_top, src_top);
vec9 *= short_multiplier;
vec8 = __msa_hadd_s_w(vec9, vec9);
res_add = (v4i32) __msa_hadd_s_d(vec8, vec8);
res0 = __msa_copy_s_w(res_add, 0) + __msa_copy_s_w(res_add, 2);
res1 = (src[8 * stride - 1] - src[6 * stride - 1]) +
2 * (src[9 * stride - 1] - src[5 * stride - 1]) +
3 * (src[10 * stride - 1] - src[4 * stride - 1]) +
4 * (src[11 * stride - 1] - src[3 * stride - 1]) +
5 * (src[12 * stride - 1] - src[2 * stride - 1]) +
6 * (src[13 * stride - 1] - src[stride - 1]) +
7 * (src[14 * stride - 1] - src[-1]) +
8 * (src[15 * stride - 1] - src[-1 * stride - 1]);
res0 *= 5;
res1 *= 5;
res0 = (res0 + 32) >> 6;
res1 = (res1 + 32) >> 6;
res3 = 7 * (res0 + res1);
res2 = 16 * (src[15 * stride - 1] + src[-stride + 15] + 1);
res2 -= res3;
vec8 = __msa_fill_w(res0);
vec4 = __msa_fill_w(res2);
vec5 = __msa_fill_w(res1);
vec6 = vec8 * 4;
vec7 = vec8 * int_multiplier;
for (lpcnt = 16; lpcnt--;) {
vec0 = vec7;
vec0 += vec4;
vec1 = vec0 + vec6;
vec2 = vec1 + vec6;
vec3 = vec2 + vec6;
SRA_4V(vec0, vec1, vec2, vec3, 5);
PCKEV_H2_SH(vec1, vec0, vec3, vec2, vec9, vec10);
CLIP_SH2_0_255(vec9, vec10);
PCKEV_ST_SB(vec9, vec10, src);
src += stride;
vec4 += vec5;
}
}
| 3,450 |
FFmpeg | 2a351f6c5521c199b4285e4e42f2321e312170bd | 0 | static int ff_filter_frame_framed(AVFilterLink *link, AVFrame *frame)
{
int (*filter_frame)(AVFilterLink *, AVFrame *);
AVFilterContext *dstctx = link->dst;
AVFilterPad *dst = link->dstpad;
AVFrame *out = NULL;
int ret;
AVFilterCommand *cmd= link->dst->command_queue;
int64_t pts;
if (link->closed) {
av_frame_free(&frame);
return AVERROR_EOF;
}
if (!(filter_frame = dst->filter_frame))
filter_frame = default_filter_frame;
/* copy the frame if needed */
if (dst->needs_writable && !av_frame_is_writable(frame)) {
av_log(link->dst, AV_LOG_DEBUG, "Copying data in avfilter.\n");
switch (link->type) {
case AVMEDIA_TYPE_VIDEO:
out = ff_get_video_buffer(link, link->w, link->h);
break;
case AVMEDIA_TYPE_AUDIO:
out = ff_get_audio_buffer(link, frame->nb_samples);
break;
default:
ret = AVERROR(EINVAL);
goto fail;
}
if (!out) {
ret = AVERROR(ENOMEM);
goto fail;
}
ret = av_frame_copy_props(out, frame);
if (ret < 0)
goto fail;
switch (link->type) {
case AVMEDIA_TYPE_VIDEO:
av_image_copy(out->data, out->linesize, (const uint8_t **)frame->data, frame->linesize,
frame->format, frame->width, frame->height);
break;
case AVMEDIA_TYPE_AUDIO:
av_samples_copy(out->extended_data, frame->extended_data,
0, 0, frame->nb_samples,
av_get_channel_layout_nb_channels(frame->channel_layout),
frame->format);
break;
default:
ret = AVERROR(EINVAL);
goto fail;
}
av_frame_free(&frame);
} else
out = frame;
while(cmd && cmd->time <= out->pts * av_q2d(link->time_base)){
av_log(link->dst, AV_LOG_DEBUG,
"Processing command time:%f command:%s arg:%s\n",
cmd->time, cmd->command, cmd->arg);
avfilter_process_command(link->dst, cmd->command, cmd->arg, 0, 0, cmd->flags);
ff_command_queue_pop(link->dst);
cmd= link->dst->command_queue;
}
pts = out->pts;
if (dstctx->enable_str) {
int64_t pos = av_frame_get_pkt_pos(out);
dstctx->var_values[VAR_N] = link->frame_count;
dstctx->var_values[VAR_T] = pts == AV_NOPTS_VALUE ? NAN : pts * av_q2d(link->time_base);
dstctx->var_values[VAR_W] = link->w;
dstctx->var_values[VAR_H] = link->h;
dstctx->var_values[VAR_POS] = pos == -1 ? NAN : pos;
dstctx->is_disabled = fabs(av_expr_eval(dstctx->enable, dstctx->var_values, NULL)) < 0.5;
if (dstctx->is_disabled &&
(dstctx->filter->flags & AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC))
filter_frame = default_filter_frame;
}
ret = filter_frame(link, out);
link->frame_count++;
link->frame_requested = 0;
ff_update_link_current_pts(link, pts);
return ret;
fail:
av_frame_free(&out);
av_frame_free(&frame);
return ret;
}
| 3,451 |
FFmpeg | 155ec6edf82692bcf3a5f87d2bc697404f4e5aaf | 0 | static void predict_plane(SnowContext *s, DWTELEM *buf, int plane_index, int add){
Plane *p= &s->plane[plane_index];
const int mb_w= s->mb_band.width;
const int mb_h= s->mb_band.height;
const int mb_stride= s->mb_band.stride;
int x, y, mb_x, mb_y;
int scale = plane_index ? s->mv_scale : 2*s->mv_scale;
int block_w = plane_index ? 8 : 16;
uint8_t *obmc = plane_index ? obmc16 : obmc32;
int obmc_stride= plane_index ? 16 : 32;
int ref_stride= s->last_picture.linesize[plane_index];
uint8_t *ref = s->last_picture.data[plane_index];
int w= p->width;
int h= p->height;
if(s->avctx->debug&512){
for(y=0; y<h; y++){
for(x=0; x<w; x++){
if(add) buf[x + y*w]+= 128*256;
else buf[x + y*w]-= 128*256;
}
}
return;
}
for(mb_y=-1; mb_y<=mb_h; mb_y++){
for(mb_x=-1; mb_x<=mb_w; mb_x++){
int index= clip(mb_x, 0, mb_w-1) + clip(mb_y, 0, mb_h-1)*mb_stride;
add_xblock(buf, ref, obmc,
block_w*mb_x - block_w/2,
block_w*mb_y - block_w/2,
2*block_w, 2*block_w,
s->mv_band[0].buf[index]*scale, s->mv_band[1].buf[index]*scale,
w, h,
w, ref_stride, obmc_stride,
s->mb_band.buf[index], add);
}
}
}
| 3,453 |
qemu | 107e4b352cc309f9bd7588ef1a44549200620078 | 1 | static void rocker_test_dma_ctrl(Rocker *r, uint32_t val)
{
PCIDevice *dev = PCI_DEVICE(r);
char *buf;
int i;
buf = g_malloc(r->test_dma_size);
if (!buf) {
DPRINTF("test dma buffer alloc failed");
return;
}
switch (val) {
case ROCKER_TEST_DMA_CTRL_CLEAR:
memset(buf, 0, r->test_dma_size);
break;
case ROCKER_TEST_DMA_CTRL_FILL:
memset(buf, 0x96, r->test_dma_size);
break;
case ROCKER_TEST_DMA_CTRL_INVERT:
pci_dma_read(dev, r->test_dma_addr, buf, r->test_dma_size);
for (i = 0; i < r->test_dma_size; i++) {
buf[i] = ~buf[i];
}
break;
default:
DPRINTF("not test dma control val=0x%08x\n", val);
goto err_out;
}
pci_dma_write(dev, r->test_dma_addr, buf, r->test_dma_size);
rocker_msix_irq(r, ROCKER_MSIX_VEC_TEST);
err_out:
g_free(buf);
}
| 3,454 |
qemu | 2d896b454a0e19ec4c1ddbb0e0b65b7e54fcedf3 | 1 | xilinx_pcie_init(MemoryRegion *sys_mem, uint32_t bus_nr,
hwaddr cfg_base, uint64_t cfg_size,
hwaddr mmio_base, uint64_t mmio_size,
qemu_irq irq, bool link_up)
{
DeviceState *dev;
MemoryRegion *cfg, *mmio;
dev = qdev_create(NULL, TYPE_XILINX_PCIE_HOST);
qdev_prop_set_uint32(dev, "bus_nr", bus_nr);
qdev_prop_set_uint64(dev, "cfg_base", cfg_base);
qdev_prop_set_uint64(dev, "cfg_size", cfg_size);
qdev_prop_set_uint64(dev, "mmio_base", mmio_base);
qdev_prop_set_uint64(dev, "mmio_size", mmio_size);
qdev_prop_set_bit(dev, "link_up", link_up);
qdev_init_nofail(dev);
cfg = sysbus_mmio_get_region(SYS_BUS_DEVICE(dev), 0);
memory_region_add_subregion_overlap(sys_mem, cfg_base, cfg, 0);
mmio = sysbus_mmio_get_region(SYS_BUS_DEVICE(dev), 1);
memory_region_add_subregion_overlap(sys_mem, 0, mmio, 0);
qdev_connect_gpio_out_named(dev, "interrupt_out", 0, irq);
return XILINX_PCIE_HOST(dev);
}
| 3,455 |
qemu | f5f601afcec6c1081128fe5a0f831788ca9f56ed | 1 | long do_sigreturn(CPUMIPSState *regs)
{
struct sigframe *frame;
abi_ulong frame_addr;
sigset_t blocked;
target_sigset_t target_set;
int i;
#if defined(DEBUG_SIGNAL)
fprintf(stderr, "do_sigreturn\n");
#endif
frame_addr = regs->active_tc.gpr[29];
if (!lock_user_struct(VERIFY_READ, frame, frame_addr, 1))
goto badframe;
for(i = 0; i < TARGET_NSIG_WORDS; i++) {
if(__get_user(target_set.sig[i], &frame->sf_mask.sig[i]))
goto badframe;
}
target_to_host_sigset_internal(&blocked, &target_set);
do_sigprocmask(SIG_SETMASK, &blocked, NULL);
restore_sigcontext(regs, &frame->sf_sc);
#if 0
/*
* Don't let your children do this ...
*/
__asm__ __volatile__(
"move\t$29, %0\n\t"
"j\tsyscall_exit"
:/* no outputs */
:"r" (®s));
/* Unreached */
#endif
regs->active_tc.PC = regs->CP0_EPC;
mips_set_hflags_isa_mode_from_pc(regs);
/* I am not sure this is right, but it seems to work
* maybe a problem with nested signals ? */
regs->CP0_EPC = 0;
return -TARGET_QEMU_ESIGRETURN;
badframe:
force_sig(TARGET_SIGSEGV/*, current*/);
return 0;
}
| 3,457 |
qemu | ac58fe7b2c67a9be142beacd4c6ee51f3264d90f | 1 | static void pmac_dma_read(BlockBackend *blk,
int64_t offset, unsigned int bytes,
void (*cb)(void *opaque, int ret), void *opaque)
{
DBDMA_io *io = opaque;
MACIOIDEState *m = io->opaque;
IDEState *s = idebus_active_if(&m->bus);
dma_addr_t dma_addr, dma_len;
void *mem;
int64_t sector_num;
int nsector;
uint64_t align = BDRV_SECTOR_SIZE;
size_t head_bytes, tail_bytes;
qemu_iovec_destroy(&io->iov);
qemu_iovec_init(&io->iov, io->len / MACIO_PAGE_SIZE + 1);
sector_num = (offset >> 9);
nsector = (io->len >> 9);
MACIO_DPRINTF("--- DMA read transfer (0x%" HWADDR_PRIx ",0x%x): "
"sector_num: %" PRId64 ", nsector: %d\n", io->addr, io->len,
sector_num, nsector);
dma_addr = io->addr;
dma_len = io->len;
mem = dma_memory_map(&address_space_memory, dma_addr, &dma_len,
DMA_DIRECTION_FROM_DEVICE);
if (offset & (align - 1)) {
head_bytes = offset & (align - 1);
MACIO_DPRINTF("--- DMA unaligned head: sector %" PRId64 ", "
"discarding %zu bytes\n", sector_num, head_bytes);
qemu_iovec_add(&io->iov, &io->remainder, head_bytes);
bytes += offset & (align - 1);
offset = offset & ~(align - 1);
}
qemu_iovec_add(&io->iov, mem, io->len);
if ((offset + bytes) & (align - 1)) {
tail_bytes = (offset + bytes) & (align - 1);
MACIO_DPRINTF("--- DMA unaligned tail: sector %" PRId64 ", "
"discarding bytes %zu\n", sector_num, tail_bytes);
qemu_iovec_add(&io->iov, &io->remainder, align - tail_bytes);
bytes = ROUND_UP(bytes, align);
}
s->io_buffer_size -= io->len;
s->io_buffer_index += io->len;
io->len = 0;
MACIO_DPRINTF("--- Block read transfer - sector_num: %" PRIx64 " "
"nsector: %x\n", (offset >> 9), (bytes >> 9));
m->aiocb = blk_aio_readv(blk, (offset >> 9), &io->iov, (bytes >> 9),
cb, io);
}
| 3,458 |
FFmpeg | fdc94db37e89165964fdf34f1cd7632e44108bd0 | 1 | static void sbr_qmf_analysis(AVFixedDSPContext *dsp, FFTContext *mdct,
#else
static void sbr_qmf_analysis(AVFloatDSPContext *dsp, FFTContext *mdct,
#endif /* USE_FIXED */
SBRDSPContext *sbrdsp, const INTFLOAT *in, INTFLOAT *x,
INTFLOAT z[320], INTFLOAT W[2][32][32][2], int buf_idx)
{
int i;
int j;
memcpy(x , x+1024, (320-32)*sizeof(x[0]));
memcpy(x+288, in, 1024*sizeof(x[0]));
for (i = 0; i < 32; i++) { // numTimeSlots*RATE = 16*2 as 960 sample frames
// are not supported
dsp->vector_fmul_reverse(z, sbr_qmf_window_ds, x, 320);
sbrdsp->sum64x5(z);
sbrdsp->qmf_pre_shuffle(z);
mdct->imdct_half(mdct, z, z+64);
sbrdsp->qmf_post_shuffle(W[buf_idx][i], z);
x += 32;
| 3,459 |
qemu | aa48dd9319dcee78ec17f4d516fb7bfc62b1a4d2 | 1 | static CPUArchState *find_cpu(uint32_t thread_id)
{
CPUState *cpu;
cpu = qemu_get_cpu(thread_id);
if (cpu == NULL) {
return NULL;
}
return cpu->env_ptr;
}
| 3,462 |
FFmpeg | 7cbb32e461cdbe8b745d560c1700c711ba5933cc | 1 | static void find_block_motion(DeshakeContext *deshake, uint8_t *src1,
uint8_t *src2, int cx, int cy, int stride,
MotionVector *mv)
{
int x, y;
int diff;
int smallest = INT_MAX;
int tmp, tmp2;
#define CMP(i, j) deshake->c.sad[0](deshake, src1 + cy * stride + cx, \
src2 + (j) * stride + (i), stride, \
deshake->blocksize)
if (deshake->search == EXHAUSTIVE) {
// Compare every possible position - this is sloooow!
for (y = -deshake->ry; y <= deshake->ry; y++) {
for (x = -deshake->rx; x <= deshake->rx; x++) {
diff = CMP(cx - x, cy - y);
if (diff < smallest) {
smallest = diff;
mv->x = x;
mv->y = y;
}
}
}
} else if (deshake->search == SMART_EXHAUSTIVE) {
// Compare every other possible position and find the best match
for (y = -deshake->ry + 1; y < deshake->ry - 2; y += 2) {
for (x = -deshake->rx + 1; x < deshake->rx - 2; x += 2) {
diff = CMP(cx - x, cy - y);
if (diff < smallest) {
smallest = diff;
mv->x = x;
mv->y = y;
}
}
}
// Hone in on the specific best match around the match we found above
tmp = mv->x;
tmp2 = mv->y;
for (y = tmp2 - 1; y <= tmp2 + 1; y++) {
for (x = tmp - 1; x <= tmp + 1; x++) {
if (x == tmp && y == tmp2)
continue;
diff = CMP(cx - x, cy - y);
if (diff < smallest) {
smallest = diff;
mv->x = x;
mv->y = y;
}
}
}
}
if (smallest > 512) {
mv->x = -1;
mv->y = -1;
}
emms_c();
//av_log(NULL, AV_LOG_ERROR, "%d\n", smallest);
//av_log(NULL, AV_LOG_ERROR, "Final: (%d, %d) = %d x %d\n", cx, cy, mv->x, mv->y);
}
| 3,463 |
qemu | 50ab0e0908d592b8bda56c2d7495e1190d734b0b | 1 | static void replication_close(BlockDriverState *bs)
{
BDRVReplicationState *s = bs->opaque;
if (s->replication_state == BLOCK_REPLICATION_RUNNING) {
replication_stop(s->rs, false, NULL);
if (s->mode == REPLICATION_MODE_SECONDARY) {
g_free(s->top_id);
replication_remove(s->rs);
| 3,465 |
qemu | 36ad0e948e15d8d86c8dec1c17a8588d87b0107d | 1 | static int kvm_irqchip_create(KVMState *s)
{
QemuOptsList *list = qemu_find_opts("machine");
int ret;
if (QTAILQ_EMPTY(&list->head) ||
!qemu_opt_get_bool(QTAILQ_FIRST(&list->head),
"kernel_irqchip", true) ||
!kvm_check_extension(s, KVM_CAP_IRQCHIP)) {
return 0;
}
ret = kvm_vm_ioctl(s, KVM_CREATE_IRQCHIP);
if (ret < 0) {
fprintf(stderr, "Create kernel irqchip failed\n");
return ret;
}
kvm_kernel_irqchip = true;
/* If we have an in-kernel IRQ chip then we must have asynchronous
* interrupt delivery (though the reverse is not necessarily true)
*/
kvm_async_interrupts_allowed = true;
kvm_halt_in_kernel_allowed = true;
kvm_init_irq_routing(s);
return 0;
}
| 3,466 |
qemu | b4ba67d9a702507793c2724e56f98e9b0f7be02b | 1 | uint32_t qpci_io_readl(QPCIDevice *dev, void *data)
{
uintptr_t addr = (uintptr_t)data;
if (addr < QPCI_PIO_LIMIT) {
return dev->bus->pio_readl(dev->bus, addr);
} else {
uint32_t val;
dev->bus->memread(dev->bus, addr, &val, sizeof(val));
return le32_to_cpu(val);
}
}
| 3,467 |
qemu | 2222e0a633070f7f3eafcc9d0e95e7f1a4e6fe36 | 1 | static void hid_keyboard_process_keycode(HIDState *hs)
{
uint8_t hid_code, index, key;
int i, keycode, slot;
if (hs->n == 0) {
return;
slot = hs->head & QUEUE_MASK; QUEUE_INCR(hs->head); hs->n--;
keycode = hs->kbd.keycodes[slot];
key = keycode & 0x7f;
index = key | ((hs->kbd.modifiers & (1 << 8)) >> 1);
hid_code = hid_usage_keys[index];
hs->kbd.modifiers &= ~(1 << 8);
switch (hid_code) {
case 0x00:
return;
case 0xe0:
assert(key == 0x1d);
if (hs->kbd.modifiers & (1 << 9)) {
/* The hid_codes for the 0xe1/0x1d scancode sequence are 0xe9/0xe0.
* Here we're processing the second hid_code. By dropping bit 9
* and setting bit 8, the scancode after 0x1d will access the
* second half of the table.
*/
hs->kbd.modifiers ^= (1 << 8) | (1 << 9);
return;
/* fall through to process Ctrl_L */
case 0xe1 ... 0xe7:
/* Ctrl_L/Ctrl_R, Shift_L/Shift_R, Alt_L/Alt_R, Win_L/Win_R.
* Handle releases here, or fall through to process presses.
*/
if (keycode & (1 << 7)) {
hs->kbd.modifiers &= ~(1 << (hid_code & 0x0f));
return;
/* fall through */
case 0xe8 ... 0xe9:
/* USB modifiers are just 1 byte long. Bits 8 and 9 of
* hs->kbd.modifiers implement a state machine that detects the
* 0xe0 and 0xe1/0x1d sequences. These bits do not follow the
* usual rules where bit 7 marks released keys; they are cleared
* elsewhere in the function as the state machine dictates.
*/
hs->kbd.modifiers |= 1 << (hid_code & 0x0f);
return;
case 0xea ... 0xef:
abort();
default:
break;
if (keycode & (1 << 7)) {
for (i = hs->kbd.keys - 1; i >= 0; i--) {
if (hs->kbd.key[i] == hid_code) {
hs->kbd.key[i] = hs->kbd.key[-- hs->kbd.keys];
hs->kbd.key[hs->kbd.keys] = 0x00;
break;
if (i < 0) {
return;
} else {
for (i = hs->kbd.keys - 1; i >= 0; i--) {
if (hs->kbd.key[i] == hid_code) {
break;
if (i < 0) {
if (hs->kbd.keys < sizeof(hs->kbd.key)) {
hs->kbd.key[hs->kbd.keys++] = hid_code;
} else {
return; | 3,468 |
FFmpeg | 4c7b023d56e09a78a587d036db1b64bf7c493b3d | 0 | static int nvdec_vc1_start_frame(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
{
VC1Context *v = avctx->priv_data;
MpegEncContext *s = &v->s;
NVDECContext *ctx = avctx->internal->hwaccel_priv_data;
CUVIDPICPARAMS *pp = &ctx->pic_params;
FrameDecodeData *fdd;
NVDECFrame *cf;
AVFrame *cur_frame = s->current_picture.f;
int ret;
ret = ff_nvdec_start_frame(avctx, cur_frame);
if (ret < 0)
return ret;
fdd = (FrameDecodeData*)cur_frame->private_ref->data;
cf = (NVDECFrame*)fdd->hwaccel_priv;
*pp = (CUVIDPICPARAMS) {
.PicWidthInMbs = (cur_frame->width + 15) / 16,
.FrameHeightInMbs = (cur_frame->height + 15) / 16,
.CurrPicIdx = cf->idx,
.field_pic_flag = v->field_mode,
.bottom_field_flag = v->cur_field_type,
.second_field = v->second_field,
.intra_pic_flag = s->pict_type == AV_PICTURE_TYPE_I ||
s->pict_type == AV_PICTURE_TYPE_BI,
.ref_pic_flag = s->pict_type == AV_PICTURE_TYPE_I ||
s->pict_type == AV_PICTURE_TYPE_P,
.CodecSpecific.vc1 = {
.ForwardRefIdx = get_ref_idx(s->last_picture.f),
.BackwardRefIdx = get_ref_idx(s->next_picture.f),
.FrameWidth = cur_frame->width,
.FrameHeight = cur_frame->height,
.intra_pic_flag = s->pict_type == AV_PICTURE_TYPE_I ||
s->pict_type == AV_PICTURE_TYPE_BI,
.ref_pic_flag = s->pict_type == AV_PICTURE_TYPE_I ||
s->pict_type == AV_PICTURE_TYPE_P,
.progressive_fcm = v->fcm == 0,
.profile = v->profile,
.postprocflag = v->postprocflag,
.pulldown = v->broadcast,
.interlace = v->interlace,
.tfcntrflag = v->tfcntrflag,
.finterpflag = v->finterpflag,
.psf = v->psf,
.multires = v->multires,
.syncmarker = v->resync_marker,
.rangered = v->rangered,
.maxbframes = s->max_b_frames,
.panscan_flag = v->panscanflag,
.refdist_flag = v->refdist_flag,
.extended_mv = v->extended_mv,
.dquant = v->dquant,
.vstransform = v->vstransform,
.loopfilter = v->s.loop_filter,
.fastuvmc = v->fastuvmc,
.overlap = v->overlap,
.quantizer = v->quantizer_mode,
.extended_dmv = v->extended_dmv,
.range_mapy_flag = v->range_mapy_flag,
.range_mapy = v->range_mapy,
.range_mapuv_flag = v->range_mapuv_flag,
.range_mapuv = v->range_mapuv,
.rangeredfrm = v->rangeredfrm,
}
};
return 0;
}
| 3,469 |
FFmpeg | b12d21733975f9001eecb480fc28e5e4473b1327 | 0 | static int frame_thread_init(AVCodecContext *avctx)
{
int thread_count = avctx->thread_count;
AVCodec *codec = avctx->codec;
AVCodecContext *src = avctx;
FrameThreadContext *fctx;
int i, err = 0;
if (!thread_count) {
int nb_cpus = get_logical_cpus(avctx);
// use number of cores + 1 as thread count if there is motre than one
if (nb_cpus > 1)
thread_count = avctx->thread_count = nb_cpus + 1;
}
if (thread_count <= 1) {
avctx->active_thread_type = 0;
return 0;
}
avctx->thread_opaque = fctx = av_mallocz(sizeof(FrameThreadContext));
fctx->threads = av_mallocz(sizeof(PerThreadContext) * thread_count);
pthread_mutex_init(&fctx->buffer_mutex, NULL);
fctx->delaying = 1;
for (i = 0; i < thread_count; i++) {
AVCodecContext *copy = av_malloc(sizeof(AVCodecContext));
PerThreadContext *p = &fctx->threads[i];
pthread_mutex_init(&p->mutex, NULL);
pthread_mutex_init(&p->progress_mutex, NULL);
pthread_cond_init(&p->input_cond, NULL);
pthread_cond_init(&p->progress_cond, NULL);
pthread_cond_init(&p->output_cond, NULL);
p->parent = fctx;
p->avctx = copy;
if (!copy) {
err = AVERROR(ENOMEM);
goto error;
}
*copy = *src;
copy->thread_opaque = p;
copy->pkt = &p->avpkt;
if (!i) {
src = copy;
if (codec->init)
err = codec->init(copy);
update_context_from_thread(avctx, copy, 1);
} else {
copy->priv_data = av_malloc(codec->priv_data_size);
if (!copy->priv_data) {
err = AVERROR(ENOMEM);
goto error;
}
memcpy(copy->priv_data, src->priv_data, codec->priv_data_size);
copy->internal = av_malloc(sizeof(AVCodecInternal));
if (!copy->internal) {
err = AVERROR(ENOMEM);
goto error;
}
*(copy->internal) = *(src->internal);
copy->internal->is_copy = 1;
if (codec->init_thread_copy)
err = codec->init_thread_copy(copy);
}
if (err) goto error;
if (!pthread_create(&p->thread, NULL, frame_worker_thread, p))
p->thread_init = 1;
}
return 0;
error:
frame_thread_free(avctx, i+1);
return err;
}
| 3,470 |
qemu | c5a49c63fa26e8825ad101dfe86339ae4c216539 | 1 | static inline void gen_ins(DisasContext *s, TCGMemOp ot)
{
if (s->base.tb->cflags & CF_USE_ICOUNT) {
gen_io_start();
}
gen_string_movl_A0_EDI(s);
/* Note: we must do this dummy write first to be restartable in
case of page fault. */
tcg_gen_movi_tl(cpu_T0, 0);
gen_op_st_v(s, ot, cpu_T0, cpu_A0);
tcg_gen_trunc_tl_i32(cpu_tmp2_i32, cpu_regs[R_EDX]);
tcg_gen_andi_i32(cpu_tmp2_i32, cpu_tmp2_i32, 0xffff);
gen_helper_in_func(ot, cpu_T0, cpu_tmp2_i32);
gen_op_st_v(s, ot, cpu_T0, cpu_A0);
gen_op_movl_T0_Dshift(ot);
gen_op_add_reg_T0(s->aflag, R_EDI);
gen_bpt_io(s, cpu_tmp2_i32, ot);
if (s->base.tb->cflags & CF_USE_ICOUNT) {
gen_io_end();
}
}
| 3,473 |
qemu | a890643958f03aaa344290700093b280cb606c28 | 1 | static void qht_bucket_reset__locked(struct qht_bucket *head)
{
struct qht_bucket *b = head;
int i;
seqlock_write_begin(&head->sequence);
do {
for (i = 0; i < QHT_BUCKET_ENTRIES; i++) {
if (b->pointers[i] == NULL) {
goto done;
}
b->hashes[i] = 0;
atomic_set(&b->pointers[i], NULL);
}
b = b->next;
} while (b);
done:
seqlock_write_end(&head->sequence);
}
| 3,474 |
FFmpeg | 7bcd81299a83b28ee8266079646470dd3e02f2ef | 1 | static int read_seek(AVFormatContext *s, int stream_index,
int64_t ts, int flags)
{
WtvContext *wtv = s->priv_data;
AVIOContext *pb = wtv->pb;
AVStream *st = s->streams[0];
int64_t ts_relative;
int i;
if ((flags & AVSEEK_FLAG_FRAME) || (flags & AVSEEK_FLAG_BYTE))
return AVERROR(ENOSYS);
/* timestamp adjustment is required because wtv->pts values are absolute,
* whereas AVIndexEntry->timestamp values are relative to epoch. */
ts_relative = ts;
if (wtv->epoch != AV_NOPTS_VALUE)
ts_relative -= wtv->epoch;
i = ff_index_search_timestamp(wtv->index_entries, wtv->nb_index_entries, ts_relative, flags);
if (i < 0) {
if (wtv->last_valid_pts == AV_NOPTS_VALUE || ts < wtv->last_valid_pts)
avio_seek(pb, 0, SEEK_SET);
else if (st->duration != AV_NOPTS_VALUE && ts_relative > st->duration && wtv->nb_index_entries)
avio_seek(pb, wtv->index_entries[wtv->nb_index_entries - 1].pos, SEEK_SET);
if (parse_chunks(s, SEEK_TO_PTS, ts, 0) < 0)
return AVERROR(ERANGE);
return 0;
}
wtv->pts = wtv->index_entries[i].timestamp;
if (wtv->epoch != AV_NOPTS_VALUE)
wtv->pts += wtv->epoch;
wtv->last_valid_pts = wtv->pts;
avio_seek(pb, wtv->index_entries[i].pos, SEEK_SET);
return 0;
}
| 3,475 |
FFmpeg | b58cfa616c169c90166938608e7135cdab5820e0 | 0 | static void mov_parse_stsd_audio(MOVContext *c, AVIOContext *pb,
AVStream *st, MOVStreamContext *sc)
{
int bits_per_sample, flags;
uint16_t version = avio_rb16(pb);
AVDictionaryEntry *compatible_brands = av_dict_get(c->fc->metadata, "compatible_brands", NULL, AV_DICT_MATCH_CASE);
avio_rb16(pb); /* revision level */
avio_rb32(pb); /* vendor */
st->codec->channels = avio_rb16(pb); /* channel count */
st->codec->bits_per_coded_sample = avio_rb16(pb); /* sample size */
av_log(c->fc, AV_LOG_TRACE, "audio channels %d\n", st->codec->channels);
sc->audio_cid = avio_rb16(pb);
avio_rb16(pb); /* packet size = 0 */
st->codec->sample_rate = ((avio_rb32(pb) >> 16));
// Read QT version 1 fields. In version 0 these do not exist.
av_log(c->fc, AV_LOG_TRACE, "version =%d, isom =%d\n", version, c->isom);
if (!c->isom ||
(compatible_brands && strstr(compatible_brands->value, "qt "))) {
if (version == 1) {
sc->samples_per_frame = avio_rb32(pb);
avio_rb32(pb); /* bytes per packet */
sc->bytes_per_frame = avio_rb32(pb);
avio_rb32(pb); /* bytes per sample */
} else if (version == 2) {
avio_rb32(pb); /* sizeof struct only */
st->codec->sample_rate = av_int2double(avio_rb64(pb));
st->codec->channels = avio_rb32(pb);
avio_rb32(pb); /* always 0x7F000000 */
st->codec->bits_per_coded_sample = avio_rb32(pb);
flags = avio_rb32(pb); /* lpcm format specific flag */
sc->bytes_per_frame = avio_rb32(pb);
sc->samples_per_frame = avio_rb32(pb);
if (st->codec->codec_tag == MKTAG('l','p','c','m'))
st->codec->codec_id =
ff_mov_get_lpcm_codec_id(st->codec->bits_per_coded_sample,
flags);
}
if (version == 0 || (version == 1 && sc->audio_cid != -2)) {
/* can't correctly handle variable sized packet as audio unit */
switch (st->codec->codec_id) {
case AV_CODEC_ID_MP2:
case AV_CODEC_ID_MP3:
st->need_parsing = AVSTREAM_PARSE_FULL;
break;
}
}
}
if (sc->format == 0) {
if (st->codec->bits_per_coded_sample == 8)
st->codec->codec_id = mov_codec_id(st, MKTAG('r','a','w',' '));
else if (st->codec->bits_per_coded_sample == 16)
st->codec->codec_id = mov_codec_id(st, MKTAG('t','w','o','s'));
}
switch (st->codec->codec_id) {
case AV_CODEC_ID_PCM_S8:
case AV_CODEC_ID_PCM_U8:
if (st->codec->bits_per_coded_sample == 16)
st->codec->codec_id = AV_CODEC_ID_PCM_S16BE;
break;
case AV_CODEC_ID_PCM_S16LE:
case AV_CODEC_ID_PCM_S16BE:
if (st->codec->bits_per_coded_sample == 8)
st->codec->codec_id = AV_CODEC_ID_PCM_S8;
else if (st->codec->bits_per_coded_sample == 24)
st->codec->codec_id =
st->codec->codec_id == AV_CODEC_ID_PCM_S16BE ?
AV_CODEC_ID_PCM_S24BE : AV_CODEC_ID_PCM_S24LE;
else if (st->codec->bits_per_coded_sample == 32)
st->codec->codec_id =
st->codec->codec_id == AV_CODEC_ID_PCM_S16BE ?
AV_CODEC_ID_PCM_S32BE : AV_CODEC_ID_PCM_S32LE;
break;
/* set values for old format before stsd version 1 appeared */
case AV_CODEC_ID_MACE3:
sc->samples_per_frame = 6;
sc->bytes_per_frame = 2 * st->codec->channels;
break;
case AV_CODEC_ID_MACE6:
sc->samples_per_frame = 6;
sc->bytes_per_frame = 1 * st->codec->channels;
break;
case AV_CODEC_ID_ADPCM_IMA_QT:
sc->samples_per_frame = 64;
sc->bytes_per_frame = 34 * st->codec->channels;
break;
case AV_CODEC_ID_GSM:
sc->samples_per_frame = 160;
sc->bytes_per_frame = 33;
break;
default:
break;
}
bits_per_sample = av_get_bits_per_sample(st->codec->codec_id);
if (bits_per_sample) {
st->codec->bits_per_coded_sample = bits_per_sample;
sc->sample_size = (bits_per_sample >> 3) * st->codec->channels;
}
}
| 3,478 |
qemu | b20909195745c34a819aed14ae996b60ab0f591f | 1 | iscsi_aio_ioctl_cb(struct iscsi_context *iscsi, int status,
void *command_data, void *opaque)
{
IscsiAIOCB *acb = opaque;
if (acb->canceled) {
qemu_aio_release(acb);
return;
}
acb->status = 0;
if (status < 0) {
error_report("Failed to ioctl(SG_IO) to iSCSI lun. %s",
iscsi_get_error(iscsi));
acb->status = -EIO;
}
acb->ioh->driver_status = 0;
acb->ioh->host_status = 0;
acb->ioh->resid = 0;
#define SG_ERR_DRIVER_SENSE 0x08
if (status == SCSI_STATUS_CHECK_CONDITION && acb->task->datain.size >= 2) {
int ss;
acb->ioh->driver_status |= SG_ERR_DRIVER_SENSE;
acb->ioh->sb_len_wr = acb->task->datain.size - 2;
ss = (acb->ioh->mx_sb_len >= acb->ioh->sb_len_wr) ?
acb->ioh->mx_sb_len : acb->ioh->sb_len_wr;
memcpy(acb->ioh->sbp, &acb->task->datain.data[2], ss);
}
iscsi_schedule_bh(iscsi_readv_writev_bh_cb, acb);
}
| 3,479 |
FFmpeg | 973c3dba27d0b1a88c70f6661b6a90d2f2e50665 | 1 | static int mpeg_decode_slice(MpegEncContext *s, int mb_y,
const uint8_t **buf, int buf_size)
{
AVCodecContext *avctx = s->avctx;
const int lowres = s->avctx->lowres;
const int field_pic = s->picture_structure != PICT_FRAME;
int ret;
s->resync_mb_x =
s->resync_mb_y = -1;
av_assert0(mb_y < s->mb_height);
init_get_bits(&s->gb, *buf, buf_size * 8);
if (s->codec_id != AV_CODEC_ID_MPEG1VIDEO && s->mb_height > 2800/16)
skip_bits(&s->gb, 3);
ff_mpeg1_clean_buffers(s);
s->interlaced_dct = 0;
s->qscale = get_qscale(s);
if (s->qscale == 0) {
av_log(s->avctx, AV_LOG_ERROR, "qscale == 0\n");
return AVERROR_INVALIDDATA;
}
/* extra slice info */
if (skip_1stop_8data_bits(&s->gb) < 0)
return AVERROR_INVALIDDATA;
s->mb_x = 0;
if (mb_y == 0 && s->codec_tag == AV_RL32("SLIF")) {
skip_bits1(&s->gb);
} else {
while (get_bits_left(&s->gb) > 0) {
int code = get_vlc2(&s->gb, ff_mbincr_vlc.table,
MBINCR_VLC_BITS, 2);
if (code < 0) {
av_log(s->avctx, AV_LOG_ERROR, "first mb_incr damaged\n");
return AVERROR_INVALIDDATA;
}
if (code >= 33) {
if (code == 33)
s->mb_x += 33;
/* otherwise, stuffing, nothing to do */
} else {
s->mb_x += code;
break;
}
}
}
if (s->mb_x >= (unsigned) s->mb_width) {
av_log(s->avctx, AV_LOG_ERROR, "initial skip overflow\n");
return AVERROR_INVALIDDATA;
}
if (avctx->hwaccel && avctx->hwaccel->decode_slice) {
const uint8_t *buf_end, *buf_start = *buf - 4; /* include start_code */
int start_code = -1;
buf_end = avpriv_find_start_code(buf_start + 2, *buf + buf_size, &start_code);
if (buf_end < *buf + buf_size)
buf_end -= 4;
s->mb_y = mb_y;
if (avctx->hwaccel->decode_slice(avctx, buf_start, buf_end - buf_start) < 0)
return DECODE_SLICE_ERROR;
*buf = buf_end;
return DECODE_SLICE_OK;
}
s->resync_mb_x = s->mb_x;
s->resync_mb_y = s->mb_y = mb_y;
s->mb_skip_run = 0;
ff_init_block_index(s);
if (s->mb_y == 0 && s->mb_x == 0 && (s->first_field || s->picture_structure == PICT_FRAME)) {
if (s->avctx->debug & FF_DEBUG_PICT_INFO) {
av_log(s->avctx, AV_LOG_DEBUG,
"qp:%d fc:%2d%2d%2d%2d %s %s %s %s %s dc:%d pstruct:%d fdct:%d cmv:%d qtype:%d ivlc:%d rff:%d %s\n",
s->qscale,
s->mpeg_f_code[0][0], s->mpeg_f_code[0][1],
s->mpeg_f_code[1][0], s->mpeg_f_code[1][1],
s->pict_type == AV_PICTURE_TYPE_I ? "I" :
(s->pict_type == AV_PICTURE_TYPE_P ? "P" :
(s->pict_type == AV_PICTURE_TYPE_B ? "B" : "S")),
s->progressive_sequence ? "ps" : "",
s->progressive_frame ? "pf" : "",
s->alternate_scan ? "alt" : "",
s->top_field_first ? "top" : "",
s->intra_dc_precision, s->picture_structure,
s->frame_pred_frame_dct, s->concealment_motion_vectors,
s->q_scale_type, s->intra_vlc_format,
s->repeat_first_field, s->chroma_420_type ? "420" : "");
}
}
for (;;) {
// If 1, we memcpy blocks in xvmcvideo.
if ((CONFIG_MPEG1_XVMC_HWACCEL || CONFIG_MPEG2_XVMC_HWACCEL) && s->pack_pblocks)
ff_xvmc_init_block(s); // set s->block
if ((ret = mpeg_decode_mb(s, s->block)) < 0)
return ret;
// Note motion_val is normally NULL unless we want to extract the MVs.
if (s->current_picture.motion_val[0] && !s->encoding) {
const int wrap = s->b8_stride;
int xy = s->mb_x * 2 + s->mb_y * 2 * wrap;
int b8_xy = 4 * (s->mb_x + s->mb_y * s->mb_stride);
int motion_x, motion_y, dir, i;
for (i = 0; i < 2; i++) {
for (dir = 0; dir < 2; dir++) {
if (s->mb_intra ||
(dir == 1 && s->pict_type != AV_PICTURE_TYPE_B)) {
motion_x = motion_y = 0;
} else if (s->mv_type == MV_TYPE_16X16 ||
(s->mv_type == MV_TYPE_FIELD && field_pic)) {
motion_x = s->mv[dir][0][0];
motion_y = s->mv[dir][0][1];
} else { /* if ((s->mv_type == MV_TYPE_FIELD) || (s->mv_type == MV_TYPE_16X8)) */
motion_x = s->mv[dir][i][0];
motion_y = s->mv[dir][i][1];
}
s->current_picture.motion_val[dir][xy][0] = motion_x;
s->current_picture.motion_val[dir][xy][1] = motion_y;
s->current_picture.motion_val[dir][xy + 1][0] = motion_x;
s->current_picture.motion_val[dir][xy + 1][1] = motion_y;
s->current_picture.ref_index [dir][b8_xy] =
s->current_picture.ref_index [dir][b8_xy + 1] = s->field_select[dir][i];
av_assert2(s->field_select[dir][i] == 0 ||
s->field_select[dir][i] == 1);
}
xy += wrap;
b8_xy += 2;
}
}
s->dest[0] += 16 >> lowres;
s->dest[1] +=(16 >> lowres) >> s->chroma_x_shift;
s->dest[2] +=(16 >> lowres) >> s->chroma_x_shift;
ff_mpv_decode_mb(s, s->block);
if (++s->mb_x >= s->mb_width) {
const int mb_size = 16 >> s->avctx->lowres;
ff_mpeg_draw_horiz_band(s, mb_size * (s->mb_y >> field_pic), mb_size);
ff_mpv_report_decode_progress(s);
s->mb_x = 0;
s->mb_y += 1 << field_pic;
if (s->mb_y >= s->mb_height) {
int left = get_bits_left(&s->gb);
int is_d10 = s->chroma_format == 2 &&
s->pict_type == AV_PICTURE_TYPE_I &&
avctx->profile == 0 && avctx->level == 5 &&
s->intra_dc_precision == 2 &&
s->q_scale_type == 1 && s->alternate_scan == 0 &&
s->progressive_frame == 0
/* vbv_delay == 0xBBB || 0xE10 */;
if (left >= 32 && !is_d10) {
GetBitContext gb = s->gb;
align_get_bits(&gb);
if (show_bits(&gb, 24) == 0x060E2B) {
av_log(avctx, AV_LOG_DEBUG, "Invalid MXF data found in video stream\n");
is_d10 = 1;
}
}
if (left < 0 ||
(left && show_bits(&s->gb, FFMIN(left, 23)) && !is_d10) ||
((avctx->err_recognition & (AV_EF_BITSTREAM | AV_EF_AGGRESSIVE)) && left > 8)) {
av_log(avctx, AV_LOG_ERROR, "end mismatch left=%d %0X\n",
left, show_bits(&s->gb, FFMIN(left, 23)));
return AVERROR_INVALIDDATA;
} else
goto eos;
}
// There are some files out there which are missing the last slice
// in cases where the slice is completely outside the visible
// area, we detect this here instead of running into the end expecting
// more data
if (s->mb_y >= ((s->height + 15) >> 4) &&
!s->progressive_sequence &&
get_bits_left(&s->gb) <= 8 &&
get_bits_left(&s->gb) >= 0 &&
s->mb_skip_run == -1 &&
show_bits(&s->gb, 8) == 0)
goto eos;
ff_init_block_index(s);
}
/* skip mb handling */
if (s->mb_skip_run == -1) {
/* read increment again */
s->mb_skip_run = 0;
for (;;) {
int code = get_vlc2(&s->gb, ff_mbincr_vlc.table,
MBINCR_VLC_BITS, 2);
if (code < 0) {
av_log(s->avctx, AV_LOG_ERROR, "mb incr damaged\n");
return AVERROR_INVALIDDATA;
}
if (code >= 33) {
if (code == 33) {
s->mb_skip_run += 33;
} else if (code == 35) {
if (s->mb_skip_run != 0 || show_bits(&s->gb, 15) != 0) {
av_log(s->avctx, AV_LOG_ERROR, "slice mismatch\n");
return AVERROR_INVALIDDATA;
}
goto eos; /* end of slice */
}
/* otherwise, stuffing, nothing to do */
} else {
s->mb_skip_run += code;
break;
}
}
if (s->mb_skip_run) {
int i;
if (s->pict_type == AV_PICTURE_TYPE_I) {
av_log(s->avctx, AV_LOG_ERROR,
"skipped MB in I frame at %d %d\n", s->mb_x, s->mb_y);
return AVERROR_INVALIDDATA;
}
/* skip mb */
s->mb_intra = 0;
for (i = 0; i < 12; i++)
s->block_last_index[i] = -1;
if (s->picture_structure == PICT_FRAME)
s->mv_type = MV_TYPE_16X16;
else
s->mv_type = MV_TYPE_FIELD;
if (s->pict_type == AV_PICTURE_TYPE_P) {
/* if P type, zero motion vector is implied */
s->mv_dir = MV_DIR_FORWARD;
s->mv[0][0][0] = s->mv[0][0][1] = 0;
s->last_mv[0][0][0] = s->last_mv[0][0][1] = 0;
s->last_mv[0][1][0] = s->last_mv[0][1][1] = 0;
s->field_select[0][0] = (s->picture_structure - 1) & 1;
} else {
/* if B type, reuse previous vectors and directions */
s->mv[0][0][0] = s->last_mv[0][0][0];
s->mv[0][0][1] = s->last_mv[0][0][1];
s->mv[1][0][0] = s->last_mv[1][0][0];
s->mv[1][0][1] = s->last_mv[1][0][1];
}
}
}
}
eos: // end of slice
if (get_bits_left(&s->gb) < 0) {
av_log(s, AV_LOG_ERROR, "overread %d\n", -get_bits_left(&s->gb));
return AVERROR_INVALIDDATA;
}
*buf += (get_bits_count(&s->gb) - 1) / 8;
ff_dlog(s, "Slice start:%d %d end:%d %d\n", s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y);
return 0;
}
| 3,480 |
FFmpeg | 8364cb97193829dc3e14484c0aaadf59c0cafc8c | 1 | static int poll_filters(void)
{
AVFilterBufferRef *picref;
AVFrame *filtered_frame = NULL;
int i, ret, ret_all;
unsigned nb_success, nb_eof;
int64_t frame_pts;
while (1) {
/* Reap all buffers present in the buffer sinks */
for (i = 0; i < nb_output_streams; i++) {
OutputStream *ost = output_streams[i];
OutputFile *of = output_files[ost->file_index];
int ret = 0;
if (!ost->filter || ost->is_past_recording_time)
continue;
if (!ost->filtered_frame && !(ost->filtered_frame = avcodec_alloc_frame())) {
return AVERROR(ENOMEM);
} else
avcodec_get_frame_defaults(ost->filtered_frame);
filtered_frame = ost->filtered_frame;
while (1) {
AVRational ist_pts_tb = ost->filter->filter->inputs[0]->time_base;
if (ost->enc->type == AVMEDIA_TYPE_AUDIO &&
!(ost->enc->capabilities & CODEC_CAP_VARIABLE_FRAME_SIZE))
ret = av_buffersink_read_samples(ost->filter->filter, &picref,
ost->st->codec->frame_size);
else
#ifdef SINKA
ret = av_buffersink_read(ost->filter->filter, &picref);
#else
ret = av_buffersink_get_buffer_ref(ost->filter->filter, &picref,
AV_BUFFERSINK_FLAG_NO_REQUEST);
#endif
if (ret < 0) {
if (ret != AVERROR(EAGAIN) && ret != AVERROR_EOF) {
char buf[256];
av_strerror(ret, buf, sizeof(buf));
av_log(NULL, AV_LOG_WARNING,
"Error in av_buffersink_get_buffer_ref(): %s\n", buf);
}
break;
}
if (ost->enc->type == AVMEDIA_TYPE_VIDEO)
filtered_frame->pts = frame_pts = av_rescale_q(picref->pts, ist_pts_tb, AV_TIME_BASE_Q);
else if (picref->pts != AV_NOPTS_VALUE)
filtered_frame->pts = frame_pts = av_rescale_q(picref->pts,
ost->filter->filter->inputs[0]->time_base,
ost->st->codec->time_base) -
av_rescale_q(of->start_time,
AV_TIME_BASE_Q,
ost->st->codec->time_base);
//if (ost->source_index >= 0)
// *filtered_frame= *input_streams[ost->source_index]->decoded_frame; //for me_threshold
if (of->start_time && filtered_frame->pts < of->start_time) {
avfilter_unref_buffer(picref);
continue;
}
switch (ost->filter->filter->inputs[0]->type) {
case AVMEDIA_TYPE_VIDEO:
avfilter_fill_frame_from_video_buffer_ref(filtered_frame, picref);
filtered_frame->pts = frame_pts;
if (!ost->frame_aspect_ratio)
ost->st->codec->sample_aspect_ratio = picref->video->sample_aspect_ratio;
do_video_out(of->ctx, ost, filtered_frame,
same_quant ? ost->last_quality :
ost->st->codec->global_quality);
break;
case AVMEDIA_TYPE_AUDIO:
avfilter_copy_buf_props(filtered_frame, picref);
filtered_frame->pts = frame_pts;
do_audio_out(of->ctx, ost, filtered_frame);
break;
default:
// TODO support subtitle filters
av_assert0(0);
}
avfilter_unref_buffer(picref);
}
}
/* Request frames through all the graphs */
ret_all = nb_success = nb_eof = 0;
for (i = 0; i < nb_filtergraphs; i++) {
ret = avfilter_graph_request_oldest(filtergraphs[i]->graph);
if (!ret) {
nb_success++;
} else if (ret == AVERROR_EOF) {
nb_eof++;
} else if (ret != AVERROR(EAGAIN)) {
char buf[256];
av_strerror(ret, buf, sizeof(buf));
av_log(NULL, AV_LOG_WARNING,
"Error in request_frame(): %s\n", buf);
ret_all = ret;
}
}
if (!nb_success)
break;
/* Try again if anything succeeded */
}
return nb_eof == nb_filtergraphs ? AVERROR_EOF : ret_all;
} | 3,481 |
qemu | 449041d4db1f82f281fe097e832f07cd9ee1e864 | 1 | static int parse_hex32(DeviceState *dev, Property *prop, const char *str)
{
uint32_t *ptr = qdev_get_prop_ptr(dev, prop);
if (sscanf(str, "%" PRIx32, ptr) != 1)
return -EINVAL;
return 0;
}
| 3,482 |
qemu | 5ee5993001cf32addb86a92e2ae8cb090fbc1462 | 1 | void helper_retry(CPUSPARCState *env)
{
trap_state *tsptr = cpu_tsptr(env);
env->pc = tsptr->tpc;
env->npc = tsptr->tnpc;
cpu_put_ccr(env, tsptr->tstate >> 32);
env->asi = (tsptr->tstate >> 24) & 0xff;
cpu_change_pstate(env, (tsptr->tstate >> 8) & 0xf3f);
cpu_put_cwp64(env, tsptr->tstate & 0xff);
if (cpu_has_hypervisor(env)) {
uint32_t new_gl = (tsptr->tstate >> 40) & 7;
env->hpstate = env->htstate[env->tl];
cpu_gl_switch_gregs(env, new_gl);
env->gl = new_gl;
}
env->tl--;
trace_win_helper_retry(env->tl);
#if !defined(CONFIG_USER_ONLY)
if (cpu_interrupts_enabled(env)) {
cpu_check_irqs(env);
}
#endif
} | 3,483 |
FFmpeg | 6086731299e4d249ddc459e406b2ebb0cb71f6f4 | 1 | static int unpack_superblocks(Vp3DecodeContext *s, GetBitContext *gb)
{
int superblock_starts[3] = { 0, s->u_superblock_start, s->v_superblock_start };
int bit = 0;
int current_superblock = 0;
int current_run = 0;
int num_partial_superblocks = 0;
int i, j;
int current_fragment;
int plane;
if (s->keyframe) {
memset(s->superblock_coding, SB_FULLY_CODED, s->superblock_count);
} else {
/* unpack the list of partially-coded superblocks */
bit = get_bits1(gb);
while (current_superblock < s->superblock_count) {
current_run = get_vlc2(gb,
s->superblock_run_length_vlc.table, 6, 2) + 1;
if (current_run == 34)
current_run += get_bits(gb, 12);
if (current_superblock + current_run > s->superblock_count) {
av_log(s->avctx, AV_LOG_ERROR, "Invalid partially coded superblock run length\n");
return -1;
}
memset(s->superblock_coding + current_superblock, bit, current_run);
current_superblock += current_run;
if (bit)
num_partial_superblocks += current_run;
if (s->theora && current_run == MAXIMUM_LONG_BIT_RUN)
bit = get_bits1(gb);
else
bit ^= 1;
}
/* unpack the list of fully coded superblocks if any of the blocks were
* not marked as partially coded in the previous step */
if (num_partial_superblocks < s->superblock_count) {
int superblocks_decoded = 0;
current_superblock = 0;
bit = get_bits1(gb);
while (superblocks_decoded < s->superblock_count - num_partial_superblocks) {
current_run = get_vlc2(gb,
s->superblock_run_length_vlc.table, 6, 2) + 1;
if (current_run == 34)
current_run += get_bits(gb, 12);
for (j = 0; j < current_run; current_superblock++) {
if (current_superblock >= s->superblock_count) {
av_log(s->avctx, AV_LOG_ERROR, "Invalid fully coded superblock run length\n");
return -1;
}
/* skip any superblocks already marked as partially coded */
if (s->superblock_coding[current_superblock] == SB_NOT_CODED) {
s->superblock_coding[current_superblock] = 2*bit;
j++;
}
}
superblocks_decoded += current_run;
if (s->theora && current_run == MAXIMUM_LONG_BIT_RUN)
bit = get_bits1(gb);
else
bit ^= 1;
}
}
/* if there were partial blocks, initialize bitstream for
* unpacking fragment codings */
if (num_partial_superblocks) {
current_run = 0;
bit = get_bits1(gb);
/* toggle the bit because as soon as the first run length is
* fetched the bit will be toggled again */
bit ^= 1;
}
}
/* figure out which fragments are coded; iterate through each
* superblock (all planes) */
s->total_num_coded_frags = 0;
memset(s->macroblock_coding, MODE_COPY, s->macroblock_count);
for (plane = 0; plane < 3; plane++) {
int sb_start = superblock_starts[plane];
int sb_end = sb_start + (plane ? s->c_superblock_count : s->y_superblock_count);
int num_coded_frags = 0;
for (i = sb_start; i < sb_end; i++) {
/* iterate through all 16 fragments in a superblock */
for (j = 0; j < 16; j++) {
/* if the fragment is in bounds, check its coding status */
current_fragment = s->superblock_fragments[i * 16 + j];
if (current_fragment != -1) {
int coded = s->superblock_coding[i];
if (s->superblock_coding[i] == SB_PARTIALLY_CODED) {
/* fragment may or may not be coded; this is the case
* that cares about the fragment coding runs */
if (current_run-- == 0) {
bit ^= 1;
current_run = get_vlc2(gb,
s->fragment_run_length_vlc.table, 5, 2);
}
coded = bit;
}
if (coded) {
/* default mode; actual mode will be decoded in
* the next phase */
s->all_fragments[current_fragment].coding_method =
MODE_INTER_NO_MV;
s->coded_fragment_list[plane][num_coded_frags++] =
current_fragment;
} else {
/* not coded; copy this fragment from the prior frame */
s->all_fragments[current_fragment].coding_method =
MODE_COPY;
}
}
}
}
s->total_num_coded_frags += num_coded_frags;
for (i = 0; i < 64; i++)
s->num_coded_frags[plane][i] = num_coded_frags;
if (plane < 2)
s->coded_fragment_list[plane+1] = s->coded_fragment_list[plane] + num_coded_frags;
}
return 0;
}
| 3,485 |
FFmpeg | f95c81ce104554b6860d94724a681a1bac0c4fbd | 1 | static av_cold int mov_text_encode_init(AVCodecContext *avctx)
{
/*
* For now, we'll use a fixed default style. When we add styling
* support, this will be generated from the ASS style.
*/
static const uint8_t text_sample_entry[] = {
0x00, 0x00, 0x00, 0x00, // uint32_t displayFlags
0x01, // int8_t horizontal-justification
0xFF, // int8_t vertical-justification
0x00, 0x00, 0x00, 0x00, // uint8_t background-color-rgba[4]
// BoxRecord {
0x00, 0x00, // int16_t top
0x00, 0x00, // int16_t left
0x00, 0x00, // int16_t bottom
0x00, 0x00, // int16_t right
// };
// StyleRecord {
0x00, 0x00, // uint16_t startChar
0x00, 0x00, // uint16_t endChar
0x00, 0x01, // uint16_t font-ID
0x00, // uint8_t face-style-flags
0x12, // uint8_t font-size
0xFF, 0xFF, 0xFF, 0xFF, // uint8_t text-color-rgba[4]
// };
// FontTableBox {
0x00, 0x00, 0x00, 0x12, // uint32_t size
'f', 't', 'a', 'b', // uint8_t name[4]
0x00, 0x01, // uint16_t entry-count
// FontRecord {
0x00, 0x01, // uint16_t font-ID
0x05, // uint8_t font-name-length
'S', 'e', 'r', 'i', 'f',// uint8_t font[font-name-length]
// };
// };
};
MovTextContext *s = avctx->priv_data;
avctx->extradata_size = sizeof text_sample_entry;
avctx->extradata = av_mallocz(avctx->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE);
if (!avctx->extradata)
return AVERROR(ENOMEM);
av_bprint_init(&s->buffer, 0, AV_BPRINT_SIZE_UNLIMITED);
memcpy(avctx->extradata, text_sample_entry, avctx->extradata_size);
s->ass_ctx = ff_ass_split(avctx->subtitle_header);
return s->ass_ctx ? 0 : AVERROR_INVALIDDATA;
} | 3,486 |
qemu | a0d1cbdacff5df4ded16b753b38fdd9da6092968 | 1 | static ssize_t eth_rx(NetClientState *nc, const uint8_t *buf, size_t size)
{
struct xlx_ethlite *s = qemu_get_nic_opaque(nc);
unsigned int rxbase = s->rxbuf * (0x800 / 4);
/* DA filter. */
if (!(buf[0] & 0x80) && memcmp(&s->conf.macaddr.a[0], buf, 6))
return size;
if (s->regs[rxbase + R_RX_CTRL0] & CTRL_S) {
D(qemu_log("ethlite lost packet %x\n", s->regs[R_RX_CTRL0]));
D(qemu_log("%s %zd rxbase=%x\n", __func__, size, rxbase));
memcpy(&s->regs[rxbase + R_RX_BUF0], buf, size);
s->regs[rxbase + R_RX_CTRL0] |= CTRL_S;
if (s->regs[R_RX_CTRL0] & CTRL_I) {
eth_pulse_irq(s);
/* If c_rx_pingpong was set flip buffers. */
s->rxbuf ^= s->c_rx_pingpong;
return size;
| 3,487 |
qemu | faadf50e2962dd54175647a80bd6fc4319c91973 | 1 | static void init_proc_970MP (CPUPPCState *env)
{
gen_spr_ne_601(env);
gen_spr_7xx(env);
/* Time base */
gen_tbl(env);
/* Hardware implementation registers */
/* XXX : not implemented */
spr_register(env, SPR_HID0, "HID0",
SPR_NOACCESS, SPR_NOACCESS,
&spr_read_generic, &spr_write_clear,
0x60000000);
/* XXX : not implemented */
spr_register(env, SPR_HID1, "HID1",
SPR_NOACCESS, SPR_NOACCESS,
&spr_read_generic, &spr_write_generic,
0x00000000);
/* XXX : not implemented */
spr_register(env, SPR_750_HID2, "HID2",
SPR_NOACCESS, SPR_NOACCESS,
&spr_read_generic, &spr_write_generic,
0x00000000);
/* XXX : not implemented */
spr_register(env, SPR_970_HID5, "HID5",
SPR_NOACCESS, SPR_NOACCESS,
&spr_read_generic, &spr_write_generic,
POWERPC970_HID5_INIT);
/* Memory management */
/* XXX: not correct */
gen_low_BATs(env);
/* XXX : not implemented */
spr_register(env, SPR_MMUCFG, "MMUCFG",
SPR_NOACCESS, SPR_NOACCESS,
&spr_read_generic, SPR_NOACCESS,
0x00000000); /* TOFIX */
/* XXX : not implemented */
spr_register(env, SPR_MMUCSR0, "MMUCSR0",
SPR_NOACCESS, SPR_NOACCESS,
&spr_read_generic, &spr_write_generic,
0x00000000); /* TOFIX */
spr_register(env, SPR_HIOR, "SPR_HIOR",
SPR_NOACCESS, SPR_NOACCESS,
&spr_read_generic, &spr_write_generic,
0xFFF00000); /* XXX: This is a hack */
#if !defined(CONFIG_USER_ONLY)
env->excp_prefix = 0xFFF00000;
#endif
#if !defined(CONFIG_USER_ONLY)
env->slb_nr = 32;
#endif
init_excp_970(env);
env->dcache_line_size = 128;
env->icache_line_size = 128;
/* Allocate hardware IRQ controller */
ppc970_irq_init(env);
}
| 3,488 |
FFmpeg | 77a644e6fa4aaeb2c26cfaa0e8ec3b19829b8d88 | 1 | void ff_h264_direct_ref_list_init(const H264Context *const h, H264SliceContext *sl)
{
H264Ref *const ref1 = &sl->ref_list[1][0];
H264Picture *const cur = h->cur_pic_ptr;
int list, j, field;
int sidx = (h->picture_structure & 1) ^ 1;
int ref1sidx = (ref1->reference & 1) ^ 1;
for (list = 0; list < sl->list_count; list++) {
cur->ref_count[sidx][list] = sl->ref_count[list];
for (j = 0; j < sl->ref_count[list]; j++)
cur->ref_poc[sidx][list][j] = 4 * sl->ref_list[list][j].parent->frame_num +
(sl->ref_list[list][j].reference & 3);
}
if (h->picture_structure == PICT_FRAME) {
memcpy(cur->ref_count[1], cur->ref_count[0], sizeof(cur->ref_count[0]));
memcpy(cur->ref_poc[1], cur->ref_poc[0], sizeof(cur->ref_poc[0]));
}
cur->mbaff = FRAME_MBAFF(h);
sl->col_fieldoff = 0;
if (sl->list_count != 2 || !sl->ref_count[1])
return;
if (h->picture_structure == PICT_FRAME) {
int cur_poc = h->cur_pic_ptr->poc;
int *col_poc = sl->ref_list[1][0].parent->field_poc;
sl->col_parity = (FFABS(col_poc[0] - cur_poc) >=
FFABS(col_poc[1] - cur_poc));
ref1sidx =
sidx = sl->col_parity;
// FL -> FL & differ parity
} else if (!(h->picture_structure & sl->ref_list[1][0].reference) &&
!sl->ref_list[1][0].parent->mbaff) {
sl->col_fieldoff = 2 * sl->ref_list[1][0].reference - 3;
}
if (sl->slice_type_nos != AV_PICTURE_TYPE_B || sl->direct_spatial_mv_pred)
return;
for (list = 0; list < 2; list++) {
fill_colmap(h, sl, sl->map_col_to_list0, list, sidx, ref1sidx, 0);
if (FRAME_MBAFF(h))
for (field = 0; field < 2; field++)
fill_colmap(h, sl, sl->map_col_to_list0_field[field], list, field,
field, 1);
}
} | 3,489 |
qemu | ebb718a5c7240f6ffb308e0d0b67a92c3b63b91c | 1 | static coroutine_fn int qcow2_co_write_zeroes(BlockDriverState *bs,
int64_t sector_num, int nb_sectors, BdrvRequestFlags flags)
{
int ret;
BDRVQcow2State *s = bs->opaque;
int head = sector_num % s->cluster_sectors;
int tail = (sector_num + nb_sectors) % s->cluster_sectors;
trace_qcow2_write_zeroes_start_req(qemu_coroutine_self(), sector_num,
nb_sectors);
if (head != 0 || tail != 0) {
int64_t cl_start = sector_num - head;
assert(cl_start + s->cluster_sectors >= sector_num + nb_sectors);
sector_num = cl_start;
nb_sectors = s->cluster_sectors;
if (!is_zero_cluster(bs, sector_num)) {
return -ENOTSUP;
}
qemu_co_mutex_lock(&s->lock);
/* We can have new write after previous check */
if (!is_zero_cluster_top_locked(bs, sector_num)) {
qemu_co_mutex_unlock(&s->lock);
return -ENOTSUP;
}
} else {
qemu_co_mutex_lock(&s->lock);
}
trace_qcow2_write_zeroes(qemu_coroutine_self(), sector_num, nb_sectors);
/* Whatever is left can use real zero clusters */
ret = qcow2_zero_clusters(bs, sector_num << BDRV_SECTOR_BITS, nb_sectors);
qemu_co_mutex_unlock(&s->lock);
return ret;
}
| 3,490 |
FFmpeg | 5e3572893d7f17679c5e051c511bf42f3da77b00 | 1 | static int read_packet(AVFormatContext *s1, AVPacket *pkt)
{
VideoDemuxData *s = s1->priv_data;
char filename[1024];
int i;
int size[3]={0}, ret[3]={0};
AVIOContext *f[3];
AVCodecContext *codec= s1->streams[0]->codec;
if (!s->is_pipe) {
/* loop over input */
if (s->loop && s->img_number > s->img_last) {
s->img_number = s->img_first;
}
if (s->img_number > s->img_last)
return AVERROR_EOF;
if (av_get_frame_filename(filename, sizeof(filename),
s->path, s->img_number)<0 && s->img_number > 1)
return AVERROR(EIO);
for(i=0; i<3; i++){
if (avio_open2(&f[i], filename, AVIO_FLAG_READ,
&s1->interrupt_callback, NULL) < 0) {
if(i==1)
break;
av_log(s1, AV_LOG_ERROR, "Could not open file : %s\n",filename);
return AVERROR(EIO);
}
size[i]= avio_size(f[i]);
if(codec->codec_id != AV_CODEC_ID_RAWVIDEO)
break;
filename[ strlen(filename) - 1 ]= 'U' + i;
}
if(codec->codec_id == AV_CODEC_ID_RAWVIDEO && !codec->width)
infer_size(&codec->width, &codec->height, size[0]);
} else {
f[0] = s1->pb;
if (f[0]->eof_reached)
return AVERROR(EIO);
size[0]= 4096;
}
av_new_packet(pkt, size[0] + size[1] + size[2]);
pkt->stream_index = 0;
pkt->flags |= AV_PKT_FLAG_KEY;
pkt->size= 0;
for(i=0; i<3; i++){
if(size[i]){
ret[i]= avio_read(f[i], pkt->data + pkt->size, size[i]);
if (!s->is_pipe)
avio_close(f[i]);
if(ret[i]>0)
pkt->size += ret[i];
}
}
if (ret[0] <= 0 || ret[1]<0 || ret[2]<0) {
av_free_packet(pkt);
return AVERROR(EIO); /* signal EOF */
} else {
s->img_count++;
s->img_number++;
return 0;
}
}
| 3,491 |
FFmpeg | e53c9065ca08a9153ecc73a6a8940bcc6d667e58 | 0 | static void fill_float_array(AVLFG *lfg, float *a, int len)
{
int i;
double bmg[2], stddev = 10.0, mean = 0.0;
for (i = 0; i < len; i += 2) {
av_bmg_get(lfg, bmg);
a[i] = bmg[0] * stddev + mean;
a[i + 1] = bmg[1] * stddev + mean;
}
}
| 3,492 |
FFmpeg | 1d16a1cf99488f16492b1bb48e023f4da8377e07 | 0 | static void ff_h264_idct8_add_mmx(uint8_t *dst, int16_t *block, int stride)
{
int i;
DECLARE_ALIGNED(8, int16_t, b2)[64];
block[0] += 32;
for(i=0; i<2; i++){
DECLARE_ALIGNED(8, uint64_t, tmp);
h264_idct8_1d(block+4*i);
__asm__ volatile(
"movq %%mm7, %0 \n\t"
TRANSPOSE4( %%mm0, %%mm2, %%mm4, %%mm6, %%mm7 )
"movq %%mm0, 8(%1) \n\t"
"movq %%mm6, 24(%1) \n\t"
"movq %%mm7, 40(%1) \n\t"
"movq %%mm4, 56(%1) \n\t"
"movq %0, %%mm7 \n\t"
TRANSPOSE4( %%mm7, %%mm5, %%mm3, %%mm1, %%mm0 )
"movq %%mm7, (%1) \n\t"
"movq %%mm1, 16(%1) \n\t"
"movq %%mm0, 32(%1) \n\t"
"movq %%mm3, 48(%1) \n\t"
: "=m"(tmp)
: "r"(b2+32*i)
: "memory"
);
}
for(i=0; i<2; i++){
h264_idct8_1d(b2+4*i);
__asm__ volatile(
"psraw $6, %%mm7 \n\t"
"psraw $6, %%mm6 \n\t"
"psraw $6, %%mm5 \n\t"
"psraw $6, %%mm4 \n\t"
"psraw $6, %%mm3 \n\t"
"psraw $6, %%mm2 \n\t"
"psraw $6, %%mm1 \n\t"
"psraw $6, %%mm0 \n\t"
"movq %%mm7, (%0) \n\t"
"movq %%mm5, 16(%0) \n\t"
"movq %%mm3, 32(%0) \n\t"
"movq %%mm1, 48(%0) \n\t"
"movq %%mm0, 64(%0) \n\t"
"movq %%mm2, 80(%0) \n\t"
"movq %%mm4, 96(%0) \n\t"
"movq %%mm6, 112(%0) \n\t"
:: "r"(b2+4*i)
: "memory"
);
}
ff_add_pixels_clamped_mmx(b2, dst, stride);
}
| 3,493 |
qemu | 297a3646c2947ee64a6d42ca264039732c6218e0 | 1 | void visit_type_uint32(Visitor *v, uint32_t *obj, const char *name, Error **errp)
{
int64_t value;
if (!error_is_set(errp)) {
if (v->type_uint32) {
v->type_uint32(v, obj, name, errp);
} else {
value = *obj;
v->type_int(v, &value, name, errp);
if (value < 0 || value > UINT32_MAX) {
error_set(errp, QERR_INVALID_PARAMETER_VALUE, name ? name : "null",
"uint32_t");
return;
}
*obj = value;
}
}
}
| 3,495 |
FFmpeg | d7e9533aa06f4073a27812349b35ba5fede11ca1 | 1 | static int RENAME(dct_quantize)(MpegEncContext *s,
DCTELEM *block, int n,
int qscale)
{
int i, level, last_non_zero_p1, q;
const UINT16 *qmat;
static __align8 INT16 temp_block[64];
int minLevel, maxLevel;
if(s->avctx!=NULL && s->avctx->codec->id==CODEC_ID_MPEG4){
/* mpeg4 */
minLevel= -2048;
maxLevel= 2047;
}else if(s->out_format==FMT_MPEG1){
/* mpeg1 */
minLevel= -255;
maxLevel= 255;
}else if(s->out_format==FMT_MJPEG){
/* (m)jpeg */
minLevel= -1023;
maxLevel= 1023;
}else{
/* h263 / msmpeg4 */
minLevel= -128;
maxLevel= 127;
}
av_fdct (block);
if (s->mb_intra) {
int dummy;
if (n < 4)
q = s->y_dc_scale;
else
q = s->c_dc_scale;
/* note: block[0] is assumed to be positive */
#if 1
asm volatile (
"xorl %%edx, %%edx \n\t"
"mul %%ecx \n\t"
: "=d" (temp_block[0]), "=a"(dummy)
: "a" (block[0] + (q >> 1)), "c" (inverse[q])
);
#else
asm volatile (
"xorl %%edx, %%edx \n\t"
"divw %%cx \n\t"
"movzwl %%ax, %%eax \n\t"
: "=a" (temp_block[0])
: "a" (block[0] + (q >> 1)), "c" (q)
: "%edx"
);
#endif
// temp_block[0] = (block[0] + (q >> 1)) / q;
i = 1;
last_non_zero_p1 = 1;
if (s->out_format == FMT_H263) {
qmat = s->q_non_intra_matrix16;
} else {
qmat = s->q_intra_matrix16;
}
for(i=1;i<4;i++) {
level = block[i] * qmat[i];
level = level / (1 << (QMAT_SHIFT_MMX - 3));
/* XXX: currently, this code is not optimal. the range should be:
mpeg1: -255..255
mpeg2: -2048..2047
h263: -128..127
mpeg4: -2048..2047
*/
if (level > maxLevel)
level = maxLevel;
else if (level < minLevel)
level = minLevel;
temp_block[i] = level;
if(level)
if(last_non_zero_p1 < inv_zigzag_direct16[i]) last_non_zero_p1= inv_zigzag_direct16[i];
block[i]=0;
}
} else {
i = 0;
last_non_zero_p1 = 0;
qmat = s->q_non_intra_matrix16;
}
asm volatile( /* XXX: small rounding bug, but it shouldnt matter */
"movd %3, %%mm3 \n\t"
SPREADW(%%mm3)
"movd %4, %%mm4 \n\t"
SPREADW(%%mm4)
#ifndef HAVE_MMX2
"movd %5, %%mm5 \n\t"
SPREADW(%%mm5)
#endif
"pxor %%mm7, %%mm7 \n\t"
"movd %%eax, %%mm2 \n\t"
SPREADW(%%mm2)
"movl %6, %%eax \n\t"
".balign 16 \n\t"
"1: \n\t"
"movq (%1, %%eax), %%mm0 \n\t"
"movq (%2, %%eax), %%mm1 \n\t"
"movq %%mm0, %%mm6 \n\t"
"psraw $15, %%mm6 \n\t"
"pmulhw %%mm0, %%mm1 \n\t"
"psubsw %%mm6, %%mm1 \n\t"
#ifdef HAVE_MMX2
"pminsw %%mm3, %%mm1 \n\t"
"pmaxsw %%mm4, %%mm1 \n\t"
#else
"paddsw %%mm3, %%mm1 \n\t"
"psubusw %%mm4, %%mm1 \n\t"
"paddsw %%mm5, %%mm1 \n\t"
#endif
"movq %%mm1, (%8, %%eax) \n\t"
"pcmpeqw %%mm7, %%mm1 \n\t"
"movq (%7, %%eax), %%mm0 \n\t"
"movq %%mm7, (%1, %%eax) \n\t"
"pandn %%mm0, %%mm1 \n\t"
PMAXW(%%mm1, %%mm2)
"addl $8, %%eax \n\t"
" js 1b \n\t"
"movq %%mm2, %%mm0 \n\t"
"psrlq $32, %%mm2 \n\t"
PMAXW(%%mm0, %%mm2)
"movq %%mm2, %%mm0 \n\t"
"psrlq $16, %%mm2 \n\t"
PMAXW(%%mm0, %%mm2)
"movd %%mm2, %%eax \n\t"
"movzbl %%al, %%eax \n\t"
: "+a" (last_non_zero_p1)
: "r" (block+64), "r" (qmat+64),
#ifdef HAVE_MMX2
"m" (maxLevel), "m" (minLevel), "m" (minLevel /* dummy */), "g" (2*i - 128),
#else
"m" (0x7FFF - maxLevel), "m" (0x7FFF -maxLevel + minLevel), "m" (minLevel), "g" (2*i - 128),
#endif
"r" (inv_zigzag_direct16+64), "r" (temp_block+64)
);
// last_non_zero_p1=64;
/* permute for IDCT */
asm volatile(
"movl %0, %%eax \n\t"
"pushl %%ebp \n\t"
"movl %%esp, " MANGLE(esp_temp) "\n\t"
"1: \n\t"
"movzbl (%1, %%eax), %%ebx \n\t"
"movzbl 1(%1, %%eax), %%ebp \n\t"
"movw (%2, %%ebx, 2), %%cx \n\t"
"movw (%2, %%ebp, 2), %%sp \n\t"
"movzbl " MANGLE(permutation) "(%%ebx), %%ebx\n\t"
"movzbl " MANGLE(permutation) "(%%ebp), %%ebp\n\t"
"movw %%cx, (%3, %%ebx, 2) \n\t"
"movw %%sp, (%3, %%ebp, 2) \n\t"
"addl $2, %%eax \n\t"
" js 1b \n\t"
"movl " MANGLE(esp_temp) ", %%esp\n\t"
"popl %%ebp \n\t"
:
: "g" (-last_non_zero_p1), "d" (zigzag_direct_noperm+last_non_zero_p1), "S" (temp_block), "D" (block)
: "%eax", "%ebx", "%ecx"
);
/*
for(i=0; i<last_non_zero_p1; i++)
{
int j= zigzag_direct_noperm[i];
block[block_permute_op(j)]= temp_block[j];
}
*/
//block_permute(block);
return last_non_zero_p1 - 1;
}
| 3,496 |
FFmpeg | b51e7554e74cbf007a1cab83c7bed3ad9fa2793a | 1 | static int mxf_write_packet(AVFormatContext *s, AVPacket *pkt)
{
MXFContext *mxf = s->priv_data;
AVIOContext *pb = s->pb;
AVStream *st = s->streams[pkt->stream_index];
MXFStreamContext *sc = st->priv_data;
MXFIndexEntry ie = {0};
int err;
if (!mxf->edit_unit_byte_count && !(mxf->edit_units_count % EDIT_UNITS_PER_BODY)) {
if ((err = av_reallocp_array(&mxf->index_entries, mxf->edit_units_count
+ EDIT_UNITS_PER_BODY, sizeof(*mxf->index_entries))) < 0) {
mxf->edit_units_count = 0;
av_log(s, AV_LOG_ERROR, "could not allocate index entries\n");
return err;
if (st->codec->codec_id == AV_CODEC_ID_MPEG2VIDEO) {
if (!mxf_parse_mpeg2_frame(s, st, pkt, &ie)) {
av_log(s, AV_LOG_ERROR, "could not get mpeg2 profile and level\n");
return -1;
} else if (st->codec->codec_id == AV_CODEC_ID_DNXHD) {
if (!mxf_parse_dnxhd_frame(s, st, pkt)) {
av_log(s, AV_LOG_ERROR, "could not get dnxhd profile\n");
return -1;
} else if (st->codec->codec_id == AV_CODEC_ID_DVVIDEO) {
if (!mxf_parse_dv_frame(s, st, pkt)) {
av_log(s, AV_LOG_ERROR, "could not get dv profile\n");
return -1;
} else if (st->codec->codec_id == AV_CODEC_ID_H264) {
if (!mxf_parse_h264_frame(s, st, pkt, &ie)) {
av_log(s, AV_LOG_ERROR, "could not get h264 profile\n");
return -1;
if (s->oformat == &ff_mxf_opatom_muxer)
return mxf_write_opatom_packet(s, pkt, &ie);
if (!mxf->header_written) {
if (mxf->edit_unit_byte_count) {
if ((err = mxf_write_partition(s, 1, 2, header_open_partition_key, 1)) < 0)
return err;
mxf_write_klv_fill(s);
mxf_write_index_table_segment(s);
} else {
if ((err = mxf_write_partition(s, 0, 0, header_open_partition_key, 1)) < 0)
return err;
mxf->header_written = 1;
if (st->index == 0) {
if (!mxf->edit_unit_byte_count &&
(!mxf->edit_units_count || mxf->edit_units_count > EDIT_UNITS_PER_BODY) &&
!(ie.flags & 0x33)) { // I frame, Gop start
mxf_write_klv_fill(s);
if ((err = mxf_write_partition(s, 1, 2, body_partition_key, 0)) < 0)
return err;
mxf_write_klv_fill(s);
mxf_write_index_table_segment(s);
mxf_write_klv_fill(s);
mxf_write_system_item(s);
if (!mxf->edit_unit_byte_count) {
mxf->index_entries[mxf->edit_units_count].offset = mxf->body_offset;
mxf->index_entries[mxf->edit_units_count].flags = ie.flags;
mxf->index_entries[mxf->edit_units_count].temporal_ref = ie.temporal_ref;
mxf->body_offset += KAG_SIZE; // size of system element
mxf->edit_units_count++;
} else if (!mxf->edit_unit_byte_count && st->index == 1) {
mxf->index_entries[mxf->edit_units_count-1].slice_offset =
mxf->body_offset - mxf->index_entries[mxf->edit_units_count-1].offset;
mxf_write_klv_fill(s);
avio_write(pb, sc->track_essence_element_key, 16); // write key
if (s->oformat == &ff_mxf_d10_muxer) {
if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO)
mxf_write_d10_video_packet(s, st, pkt);
else
mxf_write_d10_audio_packet(s, st, pkt);
} else {
klv_encode_ber4_length(pb, pkt->size); // write length
avio_write(pb, pkt->data, pkt->size);
mxf->body_offset += 16+4+pkt->size + klv_fill_size(16+4+pkt->size);
avio_flush(pb);
return 0;
| 3,497 |
qemu | 868d585aced5457218b3443398d08594d9c3ba6d | 1 | static void set_up_watchdog (m48t59_t *NVRAM, uint8_t value)
{
uint64_t interval; /* in 1/16 seconds */
if (NVRAM->wd_timer != NULL) {
qemu_del_timer(NVRAM->wd_timer);
NVRAM->wd_timer = NULL;
}
NVRAM->buffer[0x1FF0] &= ~0x80;
if (value != 0) {
interval = (1 << (2 * (value & 0x03))) * ((value >> 2) & 0x1F);
qemu_mod_timer(NVRAM->wd_timer, ((uint64_t)time(NULL) * 1000) +
((interval * 1000) >> 4));
}
}
| 3,498 |
FFmpeg | 01ecb7172b684f1c4b3e748f95c5a9a494ca36ec | 1 | static float get_band_cost_SQUAD_mips(struct AACEncContext *s,
PutBitContext *pb, const float *in,
const float *scaled, int size, int scale_idx,
int cb, const float lambda, const float uplim,
int *bits)
{
const float Q34 = ff_aac_pow34sf_tab[POW_SF2_ZERO - scale_idx + SCALE_ONE_POS - SCALE_DIV_512];
const float IQ = ff_aac_pow2sf_tab [POW_SF2_ZERO + scale_idx - SCALE_ONE_POS + SCALE_DIV_512];
int i;
float cost = 0;
int qc1, qc2, qc3, qc4;
int curbits = 0;
uint8_t *p_bits = (uint8_t *)ff_aac_spectral_bits[cb-1];
float *p_codes = (float *)ff_aac_codebook_vectors[cb-1];
for (i = 0; i < size; i += 4) {
const float *vec;
int curidx;
int *in_int = (int *)&in[i];
float *in_pos = (float *)&in[i];
float di0, di1, di2, di3;
int t0, t1, t2, t3, t4, t5, t6, t7;
qc1 = scaled[i ] * Q34 + ROUND_STANDARD;
qc2 = scaled[i+1] * Q34 + ROUND_STANDARD;
qc3 = scaled[i+2] * Q34 + ROUND_STANDARD;
qc4 = scaled[i+3] * Q34 + ROUND_STANDARD;
__asm__ volatile (
".set push \n\t"
".set noreorder \n\t"
"slt %[qc1], $zero, %[qc1] \n\t"
"slt %[qc2], $zero, %[qc2] \n\t"
"slt %[qc3], $zero, %[qc3] \n\t"
"slt %[qc4], $zero, %[qc4] \n\t"
"lw %[t0], 0(%[in_int]) \n\t"
"lw %[t1], 4(%[in_int]) \n\t"
"lw %[t2], 8(%[in_int]) \n\t"
"lw %[t3], 12(%[in_int]) \n\t"
"srl %[t0], %[t0], 31 \n\t"
"srl %[t1], %[t1], 31 \n\t"
"srl %[t2], %[t2], 31 \n\t"
"srl %[t3], %[t3], 31 \n\t"
"subu %[t4], $zero, %[qc1] \n\t"
"subu %[t5], $zero, %[qc2] \n\t"
"subu %[t6], $zero, %[qc3] \n\t"
"subu %[t7], $zero, %[qc4] \n\t"
"movn %[qc1], %[t4], %[t0] \n\t"
"movn %[qc2], %[t5], %[t1] \n\t"
"movn %[qc3], %[t6], %[t2] \n\t"
"movn %[qc4], %[t7], %[t3] \n\t"
".set pop \n\t"
: [qc1]"+r"(qc1), [qc2]"+r"(qc2),
[qc3]"+r"(qc3), [qc4]"+r"(qc4),
[t0]"=&r"(t0), [t1]"=&r"(t1), [t2]"=&r"(t2), [t3]"=&r"(t3),
[t4]"=&r"(t4), [t5]"=&r"(t5), [t6]"=&r"(t6), [t7]"=&r"(t7)
: [in_int]"r"(in_int)
: "memory"
);
curidx = qc1;
curidx *= 3;
curidx += qc2;
curidx *= 3;
curidx += qc3;
curidx *= 3;
curidx += qc4;
curidx += 40;
curbits += p_bits[curidx];
vec = &p_codes[curidx*4];
__asm__ volatile (
".set push \n\t"
".set noreorder \n\t"
"lwc1 $f0, 0(%[in_pos]) \n\t"
"lwc1 $f1, 0(%[vec]) \n\t"
"lwc1 $f2, 4(%[in_pos]) \n\t"
"lwc1 $f3, 4(%[vec]) \n\t"
"lwc1 $f4, 8(%[in_pos]) \n\t"
"lwc1 $f5, 8(%[vec]) \n\t"
"lwc1 $f6, 12(%[in_pos]) \n\t"
"lwc1 $f7, 12(%[vec]) \n\t"
"nmsub.s %[di0], $f0, $f1, %[IQ] \n\t"
"nmsub.s %[di1], $f2, $f3, %[IQ] \n\t"
"nmsub.s %[di2], $f4, $f5, %[IQ] \n\t"
"nmsub.s %[di3], $f6, $f7, %[IQ] \n\t"
".set pop \n\t"
: [di0]"=&f"(di0), [di1]"=&f"(di1),
[di2]"=&f"(di2), [di3]"=&f"(di3)
: [in_pos]"r"(in_pos), [vec]"r"(vec),
[IQ]"f"(IQ)
: "$f0", "$f1", "$f2", "$f3",
"$f4", "$f5", "$f6", "$f7",
"memory"
);
cost += di0 * di0 + di1 * di1
+ di2 * di2 + di3 * di3;
}
if (bits)
*bits = curbits;
return cost * lambda + curbits;
}
| 3,500 |
qemu | ad0ebb91cd8b5fdc4a583b03645677771f420a46 | 1 | static target_ulong h_register_logical_lan(CPUPPCState *env,
sPAPREnvironment *spapr,
target_ulong opcode,
target_ulong *args)
{
target_ulong reg = args[0];
target_ulong buf_list = args[1];
target_ulong rec_queue = args[2];
target_ulong filter_list = args[3];
VIOsPAPRDevice *sdev = spapr_vio_find_by_reg(spapr->vio_bus, reg);
VIOsPAPRVLANDevice *dev = (VIOsPAPRVLANDevice *)sdev;
vlan_bd_t filter_list_bd;
if (!dev) {
return H_PARAMETER;
}
if (dev->isopen) {
hcall_dprintf("H_REGISTER_LOGICAL_LAN called twice without "
"H_FREE_LOGICAL_LAN\n");
return H_RESOURCE;
}
if (check_bd(dev, VLAN_VALID_BD(buf_list, SPAPR_VIO_TCE_PAGE_SIZE),
SPAPR_VIO_TCE_PAGE_SIZE) < 0) {
hcall_dprintf("Bad buf_list 0x" TARGET_FMT_lx "\n", buf_list);
return H_PARAMETER;
}
filter_list_bd = VLAN_VALID_BD(filter_list, SPAPR_VIO_TCE_PAGE_SIZE);
if (check_bd(dev, filter_list_bd, SPAPR_VIO_TCE_PAGE_SIZE) < 0) {
hcall_dprintf("Bad filter_list 0x" TARGET_FMT_lx "\n", filter_list);
return H_PARAMETER;
}
if (!(rec_queue & VLAN_BD_VALID)
|| (check_bd(dev, rec_queue, VLAN_RQ_ALIGNMENT) < 0)) {
hcall_dprintf("Bad receive queue\n");
return H_PARAMETER;
}
dev->buf_list = buf_list;
sdev->signal_state = 0;
rec_queue &= ~VLAN_BD_TOGGLE;
/* Initialize the buffer list */
stq_tce(sdev, buf_list, rec_queue);
stq_tce(sdev, buf_list + 8, filter_list_bd);
spapr_tce_dma_zero(sdev, buf_list + VLAN_RX_BDS_OFF,
SPAPR_VIO_TCE_PAGE_SIZE - VLAN_RX_BDS_OFF);
dev->add_buf_ptr = VLAN_RX_BDS_OFF - 8;
dev->use_buf_ptr = VLAN_RX_BDS_OFF - 8;
dev->rx_bufs = 0;
dev->rxq_ptr = 0;
/* Initialize the receive queue */
spapr_tce_dma_zero(sdev, VLAN_BD_ADDR(rec_queue), VLAN_BD_LEN(rec_queue));
dev->isopen = 1;
return H_SUCCESS;
}
| 3,501 |
FFmpeg | 771c86c13d7133035e53f7aeb14407ae5dca6453 | 1 | av_cold void ff_psy_preprocess_end(struct FFPsyPreprocessContext *ctx)
{
int i;
ff_iir_filter_free_coeffs(ctx->fcoeffs);
if (ctx->fstate)
for (i = 0; i < ctx->avctx->channels; i++)
ff_iir_filter_free_state(ctx->fstate[i]);
av_freep(&ctx->fstate);
} | 3,503 |
qemu | 15c7733bb231090e5ebd6d10060dccdb98bb4941 | 1 | static int bdrv_open_common(BlockDriverState *bs, const char *filename,
int flags, BlockDriver *drv)
{
int ret, open_flags;
assert(drv != NULL);
bs->file = NULL;
bs->total_sectors = 0;
bs->is_temporary = 0;
bs->encrypted = 0;
bs->valid_key = 0;
bs->open_flags = flags;
/* buffer_alignment defaulted to 512, drivers can change this value */
bs->buffer_alignment = 512;
pstrcpy(bs->filename, sizeof(bs->filename), filename);
if (use_bdrv_whitelist && !bdrv_is_whitelisted(drv)) {
return -ENOTSUP;
}
bs->drv = drv;
bs->opaque = qemu_mallocz(drv->instance_size);
/*
* Yes, BDRV_O_NOCACHE aka O_DIRECT means we have to present a
* write cache to the guest. We do need the fdatasync to flush
* out transactions for block allocations, and we maybe have a
* volatile write cache in our backing device to deal with.
*/
if (flags & (BDRV_O_CACHE_WB|BDRV_O_NOCACHE))
bs->enable_write_cache = 1;
/*
* Clear flags that are internal to the block layer before opening the
* image.
*/
open_flags = flags & ~(BDRV_O_SNAPSHOT | BDRV_O_NO_BACKING);
/*
* Snapshots should be writeable.
*/
if (bs->is_temporary) {
open_flags |= BDRV_O_RDWR;
}
/* Open the image, either directly or using a protocol */
if (drv->bdrv_file_open) {
ret = drv->bdrv_file_open(bs, filename, open_flags);
} else {
ret = bdrv_file_open(&bs->file, filename, open_flags);
if (ret >= 0) {
ret = drv->bdrv_open(bs, open_flags);
}
}
if (ret < 0) {
goto free_and_fail;
}
bs->keep_read_only = bs->read_only = !(open_flags & BDRV_O_RDWR);
ret = refresh_total_sectors(bs, bs->total_sectors);
if (ret < 0) {
goto free_and_fail;
}
#ifndef _WIN32
if (bs->is_temporary) {
unlink(filename);
}
#endif
return 0;
free_and_fail:
if (bs->file) {
bdrv_delete(bs->file);
bs->file = NULL;
}
qemu_free(bs->opaque);
bs->opaque = NULL;
bs->drv = NULL;
return ret;
}
| 3,504 |
FFmpeg | 28f9ab7029bd1a02f659995919f899f84ee7361b | 0 | void ff_vp3_idct_put_altivec(uint8_t *dst, int stride, DCTELEM block[64])
{
vec_u8 t;
IDCT_START
// pixels are signed; so add 128*16 in addition to the normal 8
vec_s16 v2048 = vec_sl(vec_splat_s16(1), vec_splat_u16(11));
eight = vec_add(eight, v2048);
IDCT_1D(NOP, NOP)
TRANSPOSE8(b0, b1, b2, b3, b4, b5, b6, b7);
IDCT_1D(ADD8, SHIFT4)
#define PUT(a)\
t = vec_packsu(a, a);\
vec_ste((vec_u32)t, 0, (unsigned int *)dst);\
vec_ste((vec_u32)t, 4, (unsigned int *)dst);
PUT(b0) dst += stride;
PUT(b1) dst += stride;
PUT(b2) dst += stride;
PUT(b3) dst += stride;
PUT(b4) dst += stride;
PUT(b5) dst += stride;
PUT(b6) dst += stride;
PUT(b7)
}
| 3,505 |
FFmpeg | db592f3b03a21d5bd5237021c00af3ce0431fc60 | 0 | static void lowpass16(WaveformContext *s, AVFrame *in, AVFrame *out,
int component, int intensity, int offset, int column)
{
const int plane = s->desc->comp[component].plane;
const int mirror = s->mirror;
const int is_chroma = (component == 1 || component == 2);
const int shift_w = (is_chroma ? s->desc->log2_chroma_w : 0);
const int shift_h = (is_chroma ? s->desc->log2_chroma_h : 0);
const int src_linesize = in->linesize[plane] / 2;
const int dst_linesize = out->linesize[plane] / 2;
const int dst_signed_linesize = dst_linesize * (mirror == 1 ? -1 : 1);
const int limit = s->size - 1;
const int max = limit - intensity;
const int src_h = FF_CEIL_RSHIFT(in->height, shift_h);
const int src_w = FF_CEIL_RSHIFT(in->width, shift_w);
const uint16_t *src_data = (const uint16_t *)in->data[plane];
uint16_t *dst_data = (uint16_t *)out->data[plane] + (column ? (offset >> shift_h) * dst_linesize : offset >> shift_w);
uint16_t * const dst_bottom_line = dst_data + dst_linesize * ((s->size >> shift_h) - 1);
uint16_t * const dst_line = (mirror ? dst_bottom_line : dst_data);
const uint16_t *p;
int y;
if (!column && mirror)
dst_data += s->size >> shift_w;
for (y = 0; y < src_h; y++) {
const uint16_t *src_data_end = src_data + src_w;
uint16_t *dst = dst_line;
for (p = src_data; p < src_data_end; p++) {
uint16_t *target;
int v = FFMIN(*p, limit);
if (column) {
target = dst++ + dst_signed_linesize * (v >> shift_h);
} else {
if (mirror)
target = dst_data - (v >> shift_w) - 1;
else
target = dst_data + (v >> shift_w);
}
update16(target, max, intensity, limit);
}
src_data += src_linesize;
dst_data += dst_linesize;
}
envelope16(s, out, plane, plane);
}
| 3,506 |
qemu | 3b6eda2f57a5b7ed047077b6272c2b5a9e3531ca | 0 | static int qemu_dup_flags(int fd, int flags)
{
int ret;
int serrno;
int dup_flags;
int setfl_flags;
#ifdef F_DUPFD_CLOEXEC
ret = fcntl(fd, F_DUPFD_CLOEXEC, 0);
#else
ret = dup(fd);
if (ret != -1) {
qemu_set_cloexec(ret);
}
#endif
if (ret == -1) {
goto fail;
}
dup_flags = fcntl(ret, F_GETFL);
if (dup_flags == -1) {
goto fail;
}
if ((flags & O_SYNC) != (dup_flags & O_SYNC)) {
errno = EINVAL;
goto fail;
}
/* Set/unset flags that we can with fcntl */
setfl_flags = O_APPEND | O_ASYNC | O_NONBLOCK;
#ifdef O_NOATIME
setfl_flags |= O_NOATIME;
#endif
#ifdef O_DIRECT
setfl_flags |= O_DIRECT;
#endif
dup_flags &= ~setfl_flags;
dup_flags |= (flags & setfl_flags);
if (fcntl(ret, F_SETFL, dup_flags) == -1) {
goto fail;
}
/* Truncate the file in the cases that open() would truncate it */
if (flags & O_TRUNC ||
((flags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL))) {
if (ftruncate(ret, 0) == -1) {
goto fail;
}
}
return ret;
fail:
serrno = errno;
if (ret != -1) {
close(ret);
}
errno = serrno;
return -1;
}
| 3,507 |
qemu | 9a29e18f7dfd5a0e80d1c60fc856ebba18ddb738 | 0 | void bdrv_query_image_info(BlockDriverState *bs,
ImageInfo **p_info,
Error **errp)
{
int64_t size;
const char *backing_filename;
BlockDriverInfo bdi;
int ret;
Error *err = NULL;
ImageInfo *info;
size = bdrv_getlength(bs);
if (size < 0) {
error_setg_errno(errp, -size, "Can't get size of device '%s'",
bdrv_get_device_name(bs));
return;
}
info = g_new0(ImageInfo, 1);
info->filename = g_strdup(bs->filename);
info->format = g_strdup(bdrv_get_format_name(bs));
info->virtual_size = size;
info->actual_size = bdrv_get_allocated_file_size(bs);
info->has_actual_size = info->actual_size >= 0;
if (bdrv_is_encrypted(bs)) {
info->encrypted = true;
info->has_encrypted = true;
}
if (bdrv_get_info(bs, &bdi) >= 0) {
if (bdi.cluster_size != 0) {
info->cluster_size = bdi.cluster_size;
info->has_cluster_size = true;
}
info->dirty_flag = bdi.is_dirty;
info->has_dirty_flag = true;
}
info->format_specific = bdrv_get_specific_info(bs);
info->has_format_specific = info->format_specific != NULL;
backing_filename = bs->backing_file;
if (backing_filename[0] != '\0') {
char *backing_filename2 = g_malloc0(1024);
info->backing_filename = g_strdup(backing_filename);
info->has_backing_filename = true;
bdrv_get_full_backing_filename(bs, backing_filename2, 1024, &err);
if (err) {
error_propagate(errp, err);
qapi_free_ImageInfo(info);
g_free(backing_filename2);
return;
}
if (strcmp(backing_filename, backing_filename2) != 0) {
info->full_backing_filename =
g_strdup(backing_filename2);
info->has_full_backing_filename = true;
}
if (bs->backing_format[0]) {
info->backing_filename_format = g_strdup(bs->backing_format);
info->has_backing_filename_format = true;
}
g_free(backing_filename2);
}
ret = bdrv_query_snapshot_info_list(bs, &info->snapshots, &err);
switch (ret) {
case 0:
if (info->snapshots) {
info->has_snapshots = true;
}
break;
/* recoverable error */
case -ENOMEDIUM:
case -ENOTSUP:
error_free(err);
break;
default:
error_propagate(errp, err);
qapi_free_ImageInfo(info);
return;
}
*p_info = info;
}
| 3,508 |
qemu | 5fb6c7a8b26eab1a22207d24b4784bd2b39ab54b | 0 | static int vnc_set_x509_credential(VncDisplay *vs,
const char *certdir,
const char *filename,
char **cred,
int ignoreMissing)
{
struct stat sb;
if (*cred) {
qemu_free(*cred);
*cred = NULL;
}
*cred = qemu_malloc(strlen(certdir) + strlen(filename) + 2);
strcpy(*cred, certdir);
strcat(*cred, "/");
strcat(*cred, filename);
VNC_DEBUG("Check %s\n", *cred);
if (stat(*cred, &sb) < 0) {
qemu_free(*cred);
*cred = NULL;
if (ignoreMissing && errno == ENOENT)
return 0;
return -1;
}
return 0;
}
| 3,509 |
qemu | a8170e5e97ad17ca169c64ba87ae2f53850dab4c | 0 | void stw_le_phys(target_phys_addr_t addr, uint32_t val)
{
stw_phys_internal(addr, val, DEVICE_LITTLE_ENDIAN);
}
| 3,510 |
qemu | 6acbe4c6f18e7de00481ff30574262b58526de45 | 0 | const char *qdev_fw_name(DeviceState *dev)
{
DeviceClass *dc = DEVICE_GET_CLASS(dev);
if (dc->fw_name) {
return dc->fw_name;
} else if (dc->alias) {
return dc->alias;
}
return object_get_typename(OBJECT(dev));
}
| 3,511 |
qemu | de9e9d9f17a36ff76c1a02a5348835e5e0a081b0 | 0 | static inline void gen_op_eval_fblg(TCGv dst, TCGv src,
unsigned int fcc_offset)
{
gen_mov_reg_FCC0(dst, src, fcc_offset);
gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
tcg_gen_xor_tl(dst, dst, cpu_tmp0);
}
| 3,512 |
qemu | b854bc196f5c4b4e3299c0b0ee63cf828ece9e77 | 0 | uint32_t omap_badwidth_read32(void *opaque, target_phys_addr_t addr)
{
OMAP_32B_REG(addr);
return 0;
}
| 3,514 |
qemu | bd269ebc82fbaa5fe7ce5bc7c1770ac8acecd884 | 0 | SocketAddressLegacy *socket_parse(const char *str, Error **errp)
{
SocketAddressLegacy *addr;
addr = g_new0(SocketAddressLegacy, 1);
if (strstart(str, "unix:", NULL)) {
if (str[5] == '\0') {
error_setg(errp, "invalid Unix socket address");
goto fail;
} else {
addr->type = SOCKET_ADDRESS_LEGACY_KIND_UNIX;
addr->u.q_unix.data = g_new(UnixSocketAddress, 1);
addr->u.q_unix.data->path = g_strdup(str + 5);
}
} else if (strstart(str, "fd:", NULL)) {
if (str[3] == '\0') {
error_setg(errp, "invalid file descriptor address");
goto fail;
} else {
addr->type = SOCKET_ADDRESS_LEGACY_KIND_FD;
addr->u.fd.data = g_new(String, 1);
addr->u.fd.data->str = g_strdup(str + 3);
}
} else if (strstart(str, "vsock:", NULL)) {
addr->type = SOCKET_ADDRESS_LEGACY_KIND_VSOCK;
addr->u.vsock.data = g_new(VsockSocketAddress, 1);
if (vsock_parse(addr->u.vsock.data, str + strlen("vsock:"), errp)) {
goto fail;
}
} else {
addr->type = SOCKET_ADDRESS_LEGACY_KIND_INET;
addr->u.inet.data = g_new(InetSocketAddress, 1);
if (inet_parse(addr->u.inet.data, str, errp)) {
goto fail;
}
}
return addr;
fail:
qapi_free_SocketAddressLegacy(addr);
return NULL;
}
| 3,515 |
qemu | ba14414174b72fa231997243a9650feaa520d054 | 0 | static void do_info_cpus(Monitor *mon, QObject **ret_data)
{
CPUState *env;
QList *cpu_list;
cpu_list = qlist_new();
/* just to set the default cpu if not already done */
mon_get_cpu();
for(env = first_cpu; env != NULL; env = env->next_cpu) {
QDict *cpu;
QObject *obj;
cpu_synchronize_state(env);
obj = qobject_from_jsonf("{ 'CPU': %d, 'current': %i, 'halted': %i }",
env->cpu_index, env == mon->mon_cpu,
env->halted);
assert(obj != NULL);
cpu = qobject_to_qdict(obj);
#if defined(TARGET_I386)
qdict_put(cpu, "pc", qint_from_int(env->eip + env->segs[R_CS].base));
#elif defined(TARGET_PPC)
qdict_put(cpu, "nip", qint_from_int(env->nip));
#elif defined(TARGET_SPARC)
qdict_put(cpu, "pc", qint_from_int(env->pc));
qdict_put(cpu, "npc", qint_from_int(env->npc));
#elif defined(TARGET_MIPS)
qdict_put(cpu, "PC", qint_from_int(env->active_tc.PC));
#endif
qlist_append(cpu_list, cpu);
}
*ret_data = QOBJECT(cpu_list);
}
| 3,516 |
qemu | ad196a9d0c14f681f010bb4b979030ec125ba976 | 0 | void slirp_init(int restricted, const char *special_ip)
{
// debug_init("/tmp/slirp.log", DEBUG_DEFAULT);
#ifdef _WIN32
{
WSADATA Data;
WSAStartup(MAKEWORD(2,0), &Data);
atexit(slirp_cleanup);
}
#endif
link_up = 1;
slirp_restrict = restricted;
if_init();
ip_init();
/* Initialise mbufs *after* setting the MTU */
m_init();
/* set default addresses */
inet_aton("127.0.0.1", &loopback_addr);
if (get_dns_addr(&dns_addr) < 0) {
dns_addr = loopback_addr;
fprintf (stderr, "Warning: No DNS servers found\n");
}
if (special_ip)
slirp_special_ip = special_ip;
inet_aton(slirp_special_ip, &special_addr);
alias_addr.s_addr = special_addr.s_addr | htonl(CTL_ALIAS);
getouraddr();
register_savevm("slirp", 0, 1, slirp_state_save, slirp_state_load, NULL);
}
| 3,518 |
qemu | bd269ebc82fbaa5fe7ce5bc7c1770ac8acecd884 | 0 | static void test_io_channel(bool async,
SocketAddressLegacy *listen_addr,
SocketAddressLegacy *connect_addr,
bool passFD)
{
QIOChannel *src, *dst;
QIOChannelTest *test;
if (async) {
test_io_channel_setup_async(listen_addr, connect_addr, &src, &dst);
g_assert(!passFD ||
qio_channel_has_feature(src, QIO_CHANNEL_FEATURE_FD_PASS));
g_assert(!passFD ||
qio_channel_has_feature(dst, QIO_CHANNEL_FEATURE_FD_PASS));
g_assert(qio_channel_has_feature(src, QIO_CHANNEL_FEATURE_SHUTDOWN));
g_assert(qio_channel_has_feature(dst, QIO_CHANNEL_FEATURE_SHUTDOWN));
test = qio_channel_test_new();
qio_channel_test_run_threads(test, true, src, dst);
qio_channel_test_validate(test);
object_unref(OBJECT(src));
object_unref(OBJECT(dst));
test_io_channel_setup_async(listen_addr, connect_addr, &src, &dst);
g_assert(!passFD ||
qio_channel_has_feature(src, QIO_CHANNEL_FEATURE_FD_PASS));
g_assert(!passFD ||
qio_channel_has_feature(dst, QIO_CHANNEL_FEATURE_FD_PASS));
g_assert(qio_channel_has_feature(src, QIO_CHANNEL_FEATURE_SHUTDOWN));
g_assert(qio_channel_has_feature(dst, QIO_CHANNEL_FEATURE_SHUTDOWN));
test = qio_channel_test_new();
qio_channel_test_run_threads(test, false, src, dst);
qio_channel_test_validate(test);
object_unref(OBJECT(src));
object_unref(OBJECT(dst));
} else {
test_io_channel_setup_sync(listen_addr, connect_addr, &src, &dst);
g_assert(!passFD ||
qio_channel_has_feature(src, QIO_CHANNEL_FEATURE_FD_PASS));
g_assert(!passFD ||
qio_channel_has_feature(dst, QIO_CHANNEL_FEATURE_FD_PASS));
g_assert(qio_channel_has_feature(src, QIO_CHANNEL_FEATURE_SHUTDOWN));
g_assert(qio_channel_has_feature(dst, QIO_CHANNEL_FEATURE_SHUTDOWN));
test = qio_channel_test_new();
qio_channel_test_run_threads(test, true, src, dst);
qio_channel_test_validate(test);
object_unref(OBJECT(src));
object_unref(OBJECT(dst));
test_io_channel_setup_sync(listen_addr, connect_addr, &src, &dst);
g_assert(!passFD ||
qio_channel_has_feature(src, QIO_CHANNEL_FEATURE_FD_PASS));
g_assert(!passFD ||
qio_channel_has_feature(dst, QIO_CHANNEL_FEATURE_FD_PASS));
g_assert(qio_channel_has_feature(src, QIO_CHANNEL_FEATURE_SHUTDOWN));
g_assert(qio_channel_has_feature(dst, QIO_CHANNEL_FEATURE_SHUTDOWN));
test = qio_channel_test_new();
qio_channel_test_run_threads(test, false, src, dst);
qio_channel_test_validate(test);
object_unref(OBJECT(src));
object_unref(OBJECT(dst));
}
}
| 3,519 |
qemu | 364031f17932814484657e5551ba12957d993d7e | 0 | static int v9fs_synth_name_to_path(FsContext *ctx, V9fsPath *dir_path,
const char *name, V9fsPath *target)
{
V9fsSynthNode *node;
V9fsSynthNode *dir_node;
/* "." and ".." are not allowed */
if (!strcmp(name, ".") || !strcmp(name, "..")) {
errno = EINVAL;
return -1;
}
if (!dir_path) {
dir_node = &v9fs_synth_root;
} else {
dir_node = *(V9fsSynthNode **)dir_path->data;
}
if (!strcmp(name, "/")) {
node = dir_node;
goto out;
}
/* search for the name in the childern */
rcu_read_lock();
QLIST_FOREACH(node, &dir_node->child, sibling) {
if (!strcmp(node->name, name)) {
break;
}
}
rcu_read_unlock();
if (!node) {
errno = ENOENT;
return -1;
}
out:
/* Copy the node pointer to fid */
target->data = g_malloc(sizeof(void *));
memcpy(target->data, &node, sizeof(void *));
target->size = sizeof(void *);
return 0;
}
| 3,520 |
qemu | 621ff94d5074d88253a5818c6b9c4db718fbfc65 | 0 | static void virtio_ccw_9p_realize(VirtioCcwDevice *ccw_dev, Error **errp)
{
V9fsCCWState *dev = VIRTIO_9P_CCW(ccw_dev);
DeviceState *vdev = DEVICE(&dev->vdev);
Error *err = NULL;
qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus));
object_property_set_bool(OBJECT(vdev), true, "realized", &err);
if (err) {
error_propagate(errp, err);
}
}
| 3,522 |
qemu | 758e8e38eb582e3dc87fd55a1d234c25108a7b7f | 0 | static V9fsFidState *lookup_fid(V9fsState *s, int32_t fid)
{
V9fsFidState *f;
for (f = s->fid_list; f; f = f->next) {
if (f->fid == fid) {
v9fs_do_setuid(s, f->uid);
return f;
}
}
return NULL;
}
| 3,523 |
qemu | a89f364ae8740dfc31b321eed9ee454e996dc3c1 | 0 | static int hda_audio_post_load(void *opaque, int version)
{
HDAAudioState *a = opaque;
HDAAudioStream *st;
int i;
dprint(a, 1, "%s\n", __FUNCTION__);
if (version == 1) {
/* assume running_compat[] is for output streams */
for (i = 0; i < ARRAY_SIZE(a->running_compat); i++)
a->running_real[16 + i] = a->running_compat[i];
}
for (i = 0; i < ARRAY_SIZE(a->st); i++) {
st = a->st + i;
if (st->node == NULL)
continue;
hda_codec_parse_fmt(st->format, &st->as);
hda_audio_setup(st);
hda_audio_set_amp(st);
hda_audio_set_running(st, a->running_real[st->output * 16 + st->stream]);
}
return 0;
}
| 3,524 |
FFmpeg | 6fcd4f3c7255014eeb883385d32abc7442426314 | 0 | static av_cold int dfa_decode_init(AVCodecContext *avctx)
{
DfaContext *s = avctx->priv_data;
int ret;
avctx->pix_fmt = PIX_FMT_PAL8;
if ((ret = av_image_check_size(avctx->width, avctx->height, 0, avctx)) < 0)
return ret;
s->frame_buf = av_mallocz(avctx->width * avctx->height + AV_LZO_OUTPUT_PADDING);
if (!s->frame_buf)
return AVERROR(ENOMEM);
return 0;
}
| 3,525 |
FFmpeg | 9e494ab77cdf519eb5de8056c00469c78bf8a7e8 | 0 | static int mpeg_field_start(MpegEncContext *s){
AVCodecContext *avctx= s->avctx;
Mpeg1Context *s1 = (Mpeg1Context*)s;
/* start frame decoding */
if(s->first_field || s->picture_structure==PICT_FRAME){
if(MPV_frame_start(s, avctx) < 0)
return -1;
ff_er_frame_start(s);
/* first check if we must repeat the frame */
s->current_picture_ptr->repeat_pict = 0;
if (s->repeat_first_field) {
if (s->progressive_sequence) {
if (s->top_field_first)
s->current_picture_ptr->repeat_pict = 4;
else
s->current_picture_ptr->repeat_pict = 2;
} else if (s->progressive_frame) {
s->current_picture_ptr->repeat_pict = 1;
}
}
*s->current_picture_ptr->pan_scan= s1->pan_scan;
}else{ //second field
int i;
if(!s->current_picture_ptr){
av_log(s->avctx, AV_LOG_ERROR, "first field missing\n");
return -1;
}
for(i=0; i<4; i++){
s->current_picture.data[i] = s->current_picture_ptr->data[i];
if(s->picture_structure == PICT_BOTTOM_FIELD){
s->current_picture.data[i] += s->current_picture_ptr->linesize[i];
}
}
}
#if CONFIG_MPEG_XVMC_DECODER
// MPV_frame_start will call this function too,
// but we need to call it on every field
if(s->avctx->xvmc_acceleration)
ff_xvmc_field_start(s,avctx);
#endif
return 0;
}
| 3,527 |
qemu | a8f2e5c8fffbaf7fbd4f0efc8efbeebade78008f | 1 | static void virtio_scsi_handle_cmd(VirtIODevice *vdev, VirtQueue *vq)
{
/* use non-QOM casts in the data path */
VirtIOSCSI *s = (VirtIOSCSI *)vdev;
VirtIOSCSIReq *req, *next;
QTAILQ_HEAD(, VirtIOSCSIReq) reqs = QTAILQ_HEAD_INITIALIZER(reqs);
if (s->ctx && !s->dataplane_started) {
virtio_scsi_dataplane_start(s);
return;
}
while ((req = virtio_scsi_pop_req(s, vq))) {
if (virtio_scsi_handle_cmd_req_prepare(s, req)) {
QTAILQ_INSERT_TAIL(&reqs, req, next);
}
}
QTAILQ_FOREACH_SAFE(req, &reqs, next, next) {
virtio_scsi_handle_cmd_req_submit(s, req);
}
}
| 3,528 |
FFmpeg | c3ab0004ae4dffc32494ae84dd15cfaa909a7884 | 1 | static inline void RENAME(bgr24ToUV)(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1, const uint8_t *src2, int width, uint32_t *unused)
{
#if COMPILE_TEMPLATE_MMX
RENAME(bgr24ToUV_mmx)(dstU, dstV, src1, width, PIX_FMT_BGR24);
#else
int i;
for (i=0; i<width; i++) {
int b= src1[3*i + 0];
int g= src1[3*i + 1];
int r= src1[3*i + 2];
dstU[i]= (RU*r + GU*g + BU*b + (257<<(RGB2YUV_SHIFT-1)))>>RGB2YUV_SHIFT;
dstV[i]= (RV*r + GV*g + BV*b + (257<<(RGB2YUV_SHIFT-1)))>>RGB2YUV_SHIFT;
}
#endif /* COMPILE_TEMPLATE_MMX */
assert(src1 == src2);
}
| 3,529 |
qemu | 4ae3c0e27fff7e41fd75fc63a35703bc64785863 | 1 | static QEMUFile *open_test_file(bool write)
{
int fd = dup(temp_fd);
QIOChannel *ioc;
lseek(fd, 0, SEEK_SET);
if (write) {
g_assert_cmpint(ftruncate(fd, 0), ==, 0);
}
ioc = QIO_CHANNEL(qio_channel_file_new_fd(fd));
if (write) {
return qemu_fopen_channel_output(ioc);
} else {
return qemu_fopen_channel_input(ioc);
}
}
| 3,531 |
FFmpeg | f44d50a94c120135faeba6b4a1e5551b4397810f | 1 | static void hScale16_c(SwsContext *c, int16_t *_dst, int dstW, const uint8_t *_src,
const int16_t *filter,
const int16_t *filterPos, int filterSize)
{
int i;
int32_t *dst = (int32_t *) _dst;
const uint16_t *src = (const uint16_t *) _src;
int bits = av_pix_fmt_descriptors[c->srcFormat].comp[0].depth_minus1;
int sh = (bits <= 7) ? 11 : (bits - 4);
for (i = 0; i < dstW; i++) {
int j;
int srcPos = filterPos[i];
unsigned int val = 0;
for (j = 0; j < filterSize; j++) {
val += src[srcPos + j] * filter[filterSize * i + j];
}
// filter=14 bit, input=16 bit, output=30 bit, >> 11 makes 19 bit
dst[i] = FFMIN(val >> sh, (1 << 19) - 1);
}
}
| 3,532 |
qemu | cc64b1a1940dc2e041c5b06b003d9acf64c22372 | 1 | static uint64_t kvmppc_read_int_cpu_dt(const char *propname)
{
char buf[PATH_MAX];
union {
uint32_t v32;
uint64_t v64;
} u;
FILE *f;
int len;
if (kvmppc_find_cpu_dt(buf, sizeof(buf))) {
return -1;
}
strncat(buf, "/", sizeof(buf) - strlen(buf));
strncat(buf, propname, sizeof(buf) - strlen(buf));
f = fopen(buf, "rb");
if (!f) {
return -1;
}
len = fread(&u, 1, sizeof(u), f);
fclose(f);
switch (len) {
case 4:
/* property is a 32-bit quantity */
return be32_to_cpu(u.v32);
case 8:
return be64_to_cpu(u.v64);
}
return 0;
}
| 3,533 |
qemu | 187337f8b0ec0813dd3876d1efe37d415fb81c2e | 1 | void icp_pit_init(uint32_t base, qemu_irq *pic, int irq)
{
int iomemtype;
icp_pit_state *s;
s = (icp_pit_state *)qemu_mallocz(sizeof(icp_pit_state));
s->base = base;
/* Timer 0 runs at the system clock speed (40MHz). */
s->timer[0] = arm_timer_init(40000000, pic[irq]);
/* The other two timers run at 1MHz. */
s->timer[1] = arm_timer_init(1000000, pic[irq + 1]);
s->timer[2] = arm_timer_init(1000000, pic[irq + 2]);
iomemtype = cpu_register_io_memory(0, icp_pit_readfn,
icp_pit_writefn, s);
cpu_register_physical_memory(base, 0x00000fff, iomemtype);
/* ??? Save/restore. */
}
| 3,534 |
FFmpeg | dd44d9e316c17f473eff9f4a5a94ad0d7adb157e | 1 | static int adts_write_header(AVFormatContext *s)
{
ADTSContext *adts = s->priv_data;
AVCodecContext *avc = s->streams[0]->codec;
if(avc->extradata_size > 0)
decode_extradata(adts, avc->extradata, avc->extradata_size);
return 0;
}
| 3,535 |
qemu | dd793a74882477ca38d49e191110c17dfee51dcc | 1 | start_xmit(E1000State *s)
{
PCIDevice *d = PCI_DEVICE(s);
dma_addr_t base;
struct e1000_tx_desc desc;
uint32_t tdh_start = s->mac_reg[TDH], cause = E1000_ICS_TXQE;
if (!(s->mac_reg[TCTL] & E1000_TCTL_EN)) {
DBGOUT(TX, "tx disabled\n");
return;
}
while (s->mac_reg[TDH] != s->mac_reg[TDT]) {
base = tx_desc_base(s) +
sizeof(struct e1000_tx_desc) * s->mac_reg[TDH];
pci_dma_read(d, base, &desc, sizeof(desc));
DBGOUT(TX, "index %d: %p : %x %x\n", s->mac_reg[TDH],
(void *)(intptr_t)desc.buffer_addr, desc.lower.data,
desc.upper.data);
process_tx_desc(s, &desc);
cause |= txdesc_writeback(s, base, &desc);
if (++s->mac_reg[TDH] * sizeof(desc) >= s->mac_reg[TDLEN])
s->mac_reg[TDH] = 0;
/*
* the following could happen only if guest sw assigns
* bogus values to TDT/TDLEN.
* there's nothing too intelligent we could do about this.
*/
if (s->mac_reg[TDH] == tdh_start) {
DBGOUT(TXERR, "TDH wraparound @%x, TDT %x, TDLEN %x\n",
tdh_start, s->mac_reg[TDT], s->mac_reg[TDLEN]);
break;
}
}
set_ics(s, 0, cause);
}
| 3,536 |
FFmpeg | f8323744a0783d5937232a95cd1cc98f6b70a810 | 1 | static void vector_fmul_window_mips(float *dst, const float *src0,
const float *src1, const float *win, int len)
{
float * dst_j, *win_j, *src0_i, *src1_j, *dst_i, *win_i;
float temp, temp1, temp2, temp3;
float s0, s01, s1, s11;
float wi, wi1, wi2, wi3;
float wj, wj1, wj2, wj3;
const float * lp_end = win + len;
win_i = (float *)win;
win_j = (float *)(win + 2 * len -1);
src1_j = (float *)(src1 + len - 1);
src0_i = (float *)src0;
dst_i = (float *)dst;
dst_j = (float *)(dst + 2 * len -1);
/* loop unrolled 4 times */
__asm__ volatile (
"1:"
"lwc1 %[s1], 0(%[src1_j]) \n\t"
"lwc1 %[wi], 0(%[win_i]) \n\t"
"lwc1 %[wj], 0(%[win_j]) \n\t"
"lwc1 %[s11], -4(%[src1_j]) \n\t"
"lwc1 %[wi1], 4(%[win_i]) \n\t"
"lwc1 %[wj1], -4(%[win_j]) \n\t"
"lwc1 %[s0], 0(%[src0_i]) \n\t"
"lwc1 %[s01], 4(%[src0_i]) \n\t"
"mul.s %[temp], %[s1], %[wi] \n\t"
"mul.s %[temp1], %[s1], %[wj] \n\t"
"mul.s %[temp2], %[s11], %[wi1] \n\t"
"mul.s %[temp3], %[s11], %[wj1] \n\t"
"lwc1 %[s1], -8(%[src1_j]) \n\t"
"lwc1 %[wi2], 8(%[win_i]) \n\t"
"lwc1 %[wj2], -8(%[win_j]) \n\t"
"lwc1 %[s11], -12(%[src1_j]) \n\t"
"msub.s %[temp], %[temp], %[s0], %[wj] \n\t"
"madd.s %[temp1], %[temp1], %[s0], %[wi] \n\t"
"msub.s %[temp2], %[temp2], %[s01], %[wj1] \n\t"
"madd.s %[temp3], %[temp3], %[s01], %[wi1] \n\t"
"lwc1 %[wi3], 12(%[win_i]) \n\t"
"lwc1 %[wj3], -12(%[win_j]) \n\t"
"lwc1 %[s0], 8(%[src0_i]) \n\t"
"lwc1 %[s01], 12(%[src0_i]) \n\t"
"addiu %[src1_j],-16 \n\t"
"addiu %[win_i], 16 \n\t"
"addiu %[win_j], -16 \n\t"
"addiu %[src0_i], 16 \n\t"
"swc1 %[temp], 0(%[dst_i]) \n\t" /* dst[i] = s0*wj - s1*wi; */
"swc1 %[temp1], 0(%[dst_j]) \n\t" /* dst[j] = s0*wi + s1*wj; */
"swc1 %[temp2], 4(%[dst_i]) \n\t" /* dst[i+1] = s01*wj1 - s11*wi1; */
"swc1 %[temp3], -4(%[dst_j]) \n\t" /* dst[j-1] = s01*wi1 + s11*wj1; */
"mul.s %[temp], %[s1], %[wi2] \n\t"
"mul.s %[temp1], %[s1], %[wj2] \n\t"
"mul.s %[temp2], %[s11], %[wi3] \n\t"
"mul.s %[temp3], %[s11], %[wj3] \n\t"
"msub.s %[temp], %[temp], %[s0], %[wj2] \n\t"
"madd.s %[temp1], %[temp1], %[s0], %[wi2] \n\t"
"msub.s %[temp2], %[temp2], %[s01], %[wj3] \n\t"
"madd.s %[temp3], %[temp3], %[s01], %[wi3] \n\t"
"swc1 %[temp], 8(%[dst_i]) \n\t" /* dst[i+2] = s0*wj2 - s1*wi2; */
"swc1 %[temp1], -8(%[dst_j]) \n\t" /* dst[j-2] = s0*wi2 + s1*wj2; */
"swc1 %[temp2], 12(%[dst_i]) \n\t" /* dst[i+2] = s01*wj3 - s11*wi3; */
"swc1 %[temp3], -12(%[dst_j]) \n\t" /* dst[j-3] = s01*wi3 + s11*wj3; */
"addiu %[dst_i], 16 \n\t"
"addiu %[dst_j], -16 \n\t"
"bne %[win_i], %[lp_end], 1b \n\t"
: [temp]"=&f"(temp), [temp1]"=&f"(temp1), [temp2]"=&f"(temp2),
[temp3]"=&f"(temp3), [src0_i]"+r"(src0_i), [win_i]"+r"(win_i),
[src1_j]"+r"(src1_j), [win_j]"+r"(win_j), [dst_i]"+r"(dst_i),
[dst_j]"+r"(dst_j), [s0] "=&f"(s0), [s01]"=&f"(s01), [s1] "=&f"(s1),
[s11]"=&f"(s11), [wi] "=&f"(wi), [wj] "=&f"(wj), [wi2]"=&f"(wi2),
[wj2]"=&f"(wj2), [wi3]"=&f"(wi3), [wj3]"=&f"(wj3), [wi1]"=&f"(wi1),
[wj1]"=&f"(wj1)
: [lp_end]"r"(lp_end)
: "memory"
);
}
| 3,537 |
qemu | c92458538f501eda585b4b774c50644aed391a8a | 1 | PCIBus *typhoon_init(ram_addr_t ram_size, ISABus **isa_bus,
qemu_irq *p_rtc_irq,
AlphaCPU *cpus[4], pci_map_irq_fn sys_map_irq)
{
const uint64_t MB = 1024 * 1024;
const uint64_t GB = 1024 * MB;
MemoryRegion *addr_space = get_system_memory();
MemoryRegion *addr_space_io = get_system_io();
DeviceState *dev;
TyphoonState *s;
PCIHostState *phb;
PCIBus *b;
int i;
dev = qdev_create(NULL, TYPE_TYPHOON_PCI_HOST_BRIDGE);
qdev_init_nofail(dev);
s = TYPHOON_PCI_HOST_BRIDGE(dev);
phb = PCI_HOST_BRIDGE(dev);
/* Remember the CPUs so that we can deliver interrupts to them. */
for (i = 0; i < 4; i++) {
AlphaCPU *cpu = cpus[i];
s->cchip.cpu[i] = cpu;
if (cpu != NULL) {
CPUAlphaState *env = &cpu->env;
env->alarm_timer = qemu_new_timer_ns(rtc_clock,
typhoon_alarm_timer,
(void *)((uintptr_t)s + i));
}
}
*p_rtc_irq = *qemu_allocate_irqs(typhoon_set_timer_irq, s, 1);
/* Main memory region, 0x00.0000.0000. Real hardware supports 32GB,
but the address space hole reserved at this point is 8TB. */
memory_region_init_ram(&s->ram_region, "ram", ram_size);
vmstate_register_ram_global(&s->ram_region);
memory_region_add_subregion(addr_space, 0, &s->ram_region);
/* TIGbus, 0x801.0000.0000, 1GB. */
/* ??? The TIGbus is used for delivering interrupts, and access to
the flash ROM. I'm not sure that we need to implement it at all. */
/* Pchip0 CSRs, 0x801.8000.0000, 256MB. */
memory_region_init_io(&s->pchip.region, &pchip_ops, s, "pchip0", 256*MB);
memory_region_add_subregion(addr_space, 0x80180000000ULL,
&s->pchip.region);
/* Cchip CSRs, 0x801.A000.0000, 256MB. */
memory_region_init_io(&s->cchip.region, &cchip_ops, s, "cchip0", 256*MB);
memory_region_add_subregion(addr_space, 0x801a0000000ULL,
&s->cchip.region);
/* Dchip CSRs, 0x801.B000.0000, 256MB. */
memory_region_init_io(&s->dchip_region, &dchip_ops, s, "dchip0", 256*MB);
memory_region_add_subregion(addr_space, 0x801b0000000ULL,
&s->dchip_region);
/* Pchip0 PCI memory, 0x800.0000.0000, 4GB. */
memory_region_init(&s->pchip.reg_mem, "pci0-mem", 4*GB);
memory_region_add_subregion(addr_space, 0x80000000000ULL,
&s->pchip.reg_mem);
/* Pchip0 PCI I/O, 0x801.FC00.0000, 32MB. */
/* ??? Ideally we drop the "system" i/o space on the floor and give the
PCI subsystem the full address space reserved by the chipset.
We can't do that until the MEM and IO paths in memory.c are unified. */
memory_region_init_io(&s->pchip.reg_io, &alpha_pci_bw_io_ops, NULL,
"pci0-io", 32*MB);
memory_region_add_subregion(addr_space, 0x801fc000000ULL,
&s->pchip.reg_io);
b = pci_register_bus(dev, "pci",
typhoon_set_irq, sys_map_irq, s,
&s->pchip.reg_mem, addr_space_io, 0, 64);
phb->bus = b;
/* Pchip0 PCI special/interrupt acknowledge, 0x801.F800.0000, 64MB. */
memory_region_init_io(&s->pchip.reg_iack, &alpha_pci_iack_ops, b,
"pci0-iack", 64*MB);
memory_region_add_subregion(addr_space, 0x801f8000000ULL,
&s->pchip.reg_iack);
/* Pchip0 PCI configuration, 0x801.FE00.0000, 16MB. */
memory_region_init_io(&s->pchip.reg_conf, &alpha_pci_conf1_ops, b,
"pci0-conf", 16*MB);
memory_region_add_subregion(addr_space, 0x801fe000000ULL,
&s->pchip.reg_conf);
/* For the record, these are the mappings for the second PCI bus.
We can get away with not implementing them because we indicate
via the Cchip.CSC<PIP> bit that Pchip1 is not present. */
/* Pchip1 PCI memory, 0x802.0000.0000, 4GB. */
/* Pchip1 CSRs, 0x802.8000.0000, 256MB. */
/* Pchip1 PCI special/interrupt acknowledge, 0x802.F800.0000, 64MB. */
/* Pchip1 PCI I/O, 0x802.FC00.0000, 32MB. */
/* Pchip1 PCI configuration, 0x802.FE00.0000, 16MB. */
/* Init the ISA bus. */
/* ??? Technically there should be a cy82c693ub pci-isa bridge. */
{
qemu_irq isa_pci_irq, *isa_irqs;
*isa_bus = isa_bus_new(NULL, addr_space_io);
isa_pci_irq = *qemu_allocate_irqs(typhoon_set_isa_irq, s, 1);
isa_irqs = i8259_init(*isa_bus, isa_pci_irq);
isa_bus_irqs(*isa_bus, isa_irqs);
}
return b;
}
| 3,538 |
FFmpeg | 7e2eb4bacd70541702bd086ab2a39cb7653d314e | 1 | static int decode_update_thread_context(AVCodecContext *dst, const AVCodecContext *src){
H264Context *h= dst->priv_data, *h1= src->priv_data;
MpegEncContext * const s = &h->s, * const s1 = &h1->s;
int inited = s->context_initialized, err;
int i;
if(dst == src || !s1->context_initialized) return 0;
err = ff_mpeg_update_thread_context(dst, src);
if(err) return err;
//FIXME handle width/height changing
if(!inited){
for(i = 0; i < MAX_SPS_COUNT; i++)
av_freep(h->sps_buffers + i);
for(i = 0; i < MAX_PPS_COUNT; i++)
av_freep(h->pps_buffers + i);
memcpy(&h->s + 1, &h1->s + 1, sizeof(H264Context) - sizeof(MpegEncContext)); //copy all fields after MpegEnc
memset(h->sps_buffers, 0, sizeof(h->sps_buffers));
memset(h->pps_buffers, 0, sizeof(h->pps_buffers));
ff_h264_alloc_tables(h);
context_init(h);
for(i=0; i<2; i++){
h->rbsp_buffer[i] = NULL;
h->rbsp_buffer_size[i] = 0;
}
h->thread_context[0] = h;
// frame_start may not be called for the next thread (if it's decoding a bottom field)
// so this has to be allocated here
h->s.obmc_scratchpad = av_malloc(16*2*s->linesize + 8*2*s->uvlinesize);
s->dsp.clear_blocks(h->mb);
}
//extradata/NAL handling
h->is_avc = h1->is_avc;
//SPS/PPS
copy_parameter_set((void**)h->sps_buffers, (void**)h1->sps_buffers, MAX_SPS_COUNT, sizeof(SPS));
h->sps = h1->sps;
copy_parameter_set((void**)h->pps_buffers, (void**)h1->pps_buffers, MAX_PPS_COUNT, sizeof(PPS));
h->pps = h1->pps;
//Dequantization matrices
//FIXME these are big - can they be only copied when PPS changes?
copy_fields(h, h1, dequant4_buffer, dequant4_coeff);
for(i=0; i<6; i++)
h->dequant4_coeff[i] = h->dequant4_buffer[0] + (h1->dequant4_coeff[i] - h1->dequant4_buffer[0]);
for(i=0; i<2; i++)
h->dequant8_coeff[i] = h->dequant8_buffer[0] + (h1->dequant8_coeff[i] - h1->dequant8_buffer[0]);
h->dequant_coeff_pps = h1->dequant_coeff_pps;
//POC timing
copy_fields(h, h1, poc_lsb, redundant_pic_count);
//reference lists
copy_fields(h, h1, ref_count, intra_gb);
copy_fields(h, h1, short_ref, cabac_init_idc);
copy_picture_range(h->short_ref, h1->short_ref, 32, s, s1);
copy_picture_range(h->long_ref, h1->long_ref, 32, s, s1);
copy_picture_range(h->delayed_pic, h1->delayed_pic, MAX_DELAYED_PIC_COUNT+2, s, s1);
h->last_slice_type = h1->last_slice_type;
if(!s->current_picture_ptr) return 0;
if(!s->dropable) {
ff_h264_execute_ref_pic_marking(h, h->mmco, h->mmco_index);
h->prev_poc_msb = h->poc_msb;
h->prev_poc_lsb = h->poc_lsb;
}
h->prev_frame_num_offset= h->frame_num_offset;
h->prev_frame_num = h->frame_num;
h->outputed_poc = h->next_outputed_poc;
return 0;
}
| 3,539 |
FFmpeg | fd58678b86023ea98665f06756bf03f91e56be54 | 1 | static int device_open(AVFormatContext *ctx)
{
struct v4l2_capability cap;
int fd;
#if CONFIG_LIBV4L2
int fd_libv4l;
#endif
int res, err;
int flags = O_RDWR;
if (ctx->flags & AVFMT_FLAG_NONBLOCK) {
flags |= O_NONBLOCK;
}
fd = v4l2_open(ctx->filename, flags, 0);
if (fd < 0) {
err = errno;
av_log(ctx, AV_LOG_ERROR, "Cannot open video device %s : %s\n",
ctx->filename, strerror(err));
return AVERROR(err);
}
#if CONFIG_LIBV4L2
fd_libv4l = v4l2_fd_open(fd, 0);
if (fd < 0) {
err = AVERROR(errno);
av_log(ctx, AV_LOG_ERROR, "Cannot open video device with libv4l neither %s : %s\n",
ctx->filename, strerror(errno));
return err;
}
fd = fd_libv4l;
#endif
res = v4l2_ioctl(fd, VIDIOC_QUERYCAP, &cap);
if (res < 0) {
err = errno;
av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_QUERYCAP): %s\n",
strerror(err));
goto fail;
}
av_log(ctx, AV_LOG_VERBOSE, "[%d]Capabilities: %x\n",
fd, cap.capabilities);
if (!(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE)) {
av_log(ctx, AV_LOG_ERROR, "Not a video capture device.\n");
err = ENODEV;
goto fail;
}
if (!(cap.capabilities & V4L2_CAP_STREAMING)) {
av_log(ctx, AV_LOG_ERROR,
"The device does not support the streaming I/O method.\n");
err = ENOSYS;
goto fail;
}
return fd;
fail:
v4l2_close(fd);
return AVERROR(err);
}
| 3,541 |
qemu | 6b4495401bdf442457b713b7e3994b465c55af35 | 1 | int pcie_cap_init(PCIDevice *dev, uint8_t offset, uint8_t type, uint8_t port)
{
/* PCIe cap v2 init */
int pos;
uint8_t *exp_cap;
assert(pci_is_express(dev));
pos = pci_add_capability(dev, PCI_CAP_ID_EXP, offset, PCI_EXP_VER2_SIZEOF);
if (pos < 0) {
return pos;
}
dev->exp.exp_cap = pos;
exp_cap = dev->config + pos;
/* Filling values common with v1 */
pcie_cap_v1_fill(exp_cap, port, type, PCI_EXP_FLAGS_VER2);
/* Filling v2 specific values */
pci_set_long(exp_cap + PCI_EXP_DEVCAP2,
PCI_EXP_DEVCAP2_EFF | PCI_EXP_DEVCAP2_EETLPP);
pci_set_word(dev->wmask + pos + PCI_EXP_DEVCTL2, PCI_EXP_DEVCTL2_EETLPPB);
return pos;
}
| 3,542 |
FFmpeg | 436f866f92a9483717e376866783346bf8a00e58 | 1 | void ff_svq3_add_idct_c(uint8_t *dst, DCTELEM *block, int stride, int qp,
int dc)
{
const int qmul = svq3_dequant_coeff[qp];
int i;
uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
if (dc) {
dc = 13*13*((dc == 1) ? 1538*block[0] : ((qmul*(block[0] >> 3)) / 2));
block[0] = 0;
}
for (i = 0; i < 4; i++) {
const int z0 = 13*(block[0 + 4*i] + block[2 + 4*i]);
const int z1 = 13*(block[0 + 4*i] - block[2 + 4*i]);
const int z2 = 7* block[1 + 4*i] - 17*block[3 + 4*i];
const int z3 = 17* block[1 + 4*i] + 7*block[3 + 4*i];
block[0 + 4*i] = z0 + z3;
block[1 + 4*i] = z1 + z2;
block[2 + 4*i] = z1 - z2;
block[3 + 4*i] = z0 - z3;
}
for (i = 0; i < 4; i++) {
const int z0 = 13*(block[i + 4*0] + block[i + 4*2]);
const int z1 = 13*(block[i + 4*0] - block[i + 4*2]);
const int z2 = 7* block[i + 4*1] - 17*block[i + 4*3];
const int z3 = 17* block[i + 4*1] + 7*block[i + 4*3];
const int rr = (dc + 0x80000);
dst[i + stride*0] = cm[ dst[i + stride*0] + (((z0 + z3)*qmul + rr) >> 20) ];
dst[i + stride*1] = cm[ dst[i + stride*1] + (((z1 + z2)*qmul + rr) >> 20) ];
dst[i + stride*2] = cm[ dst[i + stride*2] + (((z1 - z2)*qmul + rr) >> 20) ];
dst[i + stride*3] = cm[ dst[i + stride*3] + (((z0 - z3)*qmul + rr) >> 20) ];
}
}
| 3,543 |
qemu | 8e84865e54cb66fd7b57bb18c312ad3d56b6e276 | 1 | void process_incoming_migration(QEMUFile *f)
{
if (qemu_loadvm_state(f) < 0) {
fprintf(stderr, "load of migration failed\n");
exit(0);
}
qemu_announce_self();
DPRINTF("successfully loaded vm state\n");
if (autostart)
vm_start();
} | 3,544 |
FFmpeg | 0ecca7a49f8e254c12a3a1de048d738bfbb614c6 | 1 | void *av_realloc(void *ptr, unsigned int size)
{
#ifdef MEMALIGN_HACK
//FIXME this isnt aligned correctly though it probably isnt needed
int diff;
if(!ptr) return av_malloc(size);
diff= ((char*)ptr)[-1];
return realloc(ptr - diff, size + diff) + diff;
#else
return realloc(ptr, size);
#endif
} | 3,545 |
qemu | faadf50e2962dd54175647a80bd6fc4319c91973 | 1 | static void init_excp_620 (CPUPPCState *env)
{
#if !defined(CONFIG_USER_ONLY)
env->excp_vectors[POWERPC_EXCP_RESET] = 0x00000100;
env->excp_vectors[POWERPC_EXCP_MCHECK] = 0x00000200;
env->excp_vectors[POWERPC_EXCP_DSI] = 0x00000300;
env->excp_vectors[POWERPC_EXCP_ISI] = 0x00000400;
env->excp_vectors[POWERPC_EXCP_EXTERNAL] = 0x00000500;
env->excp_vectors[POWERPC_EXCP_ALIGN] = 0x00000600;
env->excp_vectors[POWERPC_EXCP_PROGRAM] = 0x00000700;
env->excp_vectors[POWERPC_EXCP_FPU] = 0x00000800;
env->excp_vectors[POWERPC_EXCP_DECR] = 0x00000900;
env->excp_vectors[POWERPC_EXCP_SYSCALL] = 0x00000C00;
env->excp_vectors[POWERPC_EXCP_TRACE] = 0x00000D00;
env->excp_vectors[POWERPC_EXCP_FPA] = 0x00000E00;
env->excp_vectors[POWERPC_EXCP_PERFM] = 0x00000F00;
env->excp_vectors[POWERPC_EXCP_IABR] = 0x00001300;
env->excp_vectors[POWERPC_EXCP_SMI] = 0x00001400;
/* Hardware reset vector */
env->hreset_vector = 0x0000000000000100ULL; /* ? */
#endif
}
| 3,547 |
Subsets and Splits