Skip to contentSkip to conversation

Bug in helper_pcmpestrm and helper_pcmpistrm

Qemu-devel Frank Mehnert 2 participants 2 messages Sep 29, 2011

lore
Share & tools
lore
#0 lore raw

Hi,

the two functions helper_pcmpestrm() and helper_pcmpistrm() in target-i386/ops_sse.h contain obviously typos. I think that at all 4 marked places should increment the index 'i', not decrement it during the loop:

void glue(helper_pcmpestrm, SUFFIX) (Reg *d, Reg *s, uint32_t ctrl)

{
    int i;
    unsigned int res = pcmpxstrx(d, s, ctrl,
                    pcmp_elen(R_EDX, ctrl),
                    pcmp_elen(R_EAX, ctrl));

    if ((ctrl >> 6) & 1) {
        if (ctrl & 1)
            for (i = 0; i <= 8; i--, res >>= 1)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                d->W(i) = (res & 1) ? ~0 : 0;
        else
            for (i = 0; i <= 16; i--, res >>= 1)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                d->B(i) = (res & 1) ? ~0 : 0;
    } else {
        d->Q(1) = 0;
        d->Q(0) = res;
    }
}

void glue(helper_pcmpistrm, SUFFIX) (Reg *d, Reg *s, uint32_t ctrl)

{
    int i;
    unsigned int res = pcmpxstrx(d, s, ctrl,
                    pcmp_ilen(s, ctrl),
                    pcmp_ilen(d, ctrl));

    if ((ctrl >> 6) & 1) {
        if (ctrl & 1)
            for (i = 0; i <= 8; i--, res >>= 1)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                d->W(i) = (res & 1) ? ~0 : 0;
        else
            for (i = 0; i <= 16; i--, res >>= 1)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                d->B(i) = (res & 1) ? ~0 : 0;
    } else {
        d->Q(1) = 0;
        d->Q(0) = res;
    }
}

Kind regards,

Frank

Signature · 11 lines
Dr.-Ing. Frank Mehnert
Senior Manager Software Development Desktop Virtualization, VirtualBox
ORACLE Deutschland B.V. & Co. KG | Werkstr. 24 | 71384 Weinstadt, Germany

Hauptverwaltung: Riesstr. 25, D-80992 München
Registergericht: Amtsgericht München, HRA 95603

Komplementärin: ORACLE Deutschland Verwaltung B.V.
Hertogswetering 163/167, 3543 AS Utrecht, Niederlande
Handelsregister der Handelskammer Midden-Niederlande, Nr. 30143697
Geschäftsführer: Jürgen Kunz, Marcel van de Molen, Alexander van der Ven
#1 lore raw
Quoted 15 lines · Frank Mehnert

Hi,

the two functions helper_pcmpestrm() and helper_pcmpistrm() in target-i386/ops_sse.h contain obviously typos. I think that at all 4 marked places should increment the index 'i', not decrement it during the loop:

void glue(helper_pcmpestrm, SUFFIX) (Reg *d, Reg *s, uint32_t ctrl) {
   int i;
   unsigned int res = pcmpxstrx(d, s, ctrl, pcmp_elen(R_EDX, ctrl), pcmp_elen(R_EAX, ctrl));

Quoted 5 lines

   if ((ctrl >> 6) & 1) {
       if (ctrl & 1)
           for (i = 0; i <= 8; i--, res >>= 1)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
               d->W(i) = (res & 1) ? ~0 : 0;

I think this line will also fill the entire memory with 0xff and 0x00.

Please make a patch, http://wiki.qemu.org/Contribute/SubmitAPatch
should tell how (seems to be down ATM).

Quoted 50 lines

       else
           for (i = 0; i <= 16; i--, res >>= 1)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
               d->B(i) = (res & 1) ? ~0 : 0;
   } else {
       d->Q(1) = 0;
       d->Q(0) = res;
   }
}

void glue(helper_pcmpistrm, SUFFIX) (Reg *d, Reg *s, uint32_t ctrl) {
   int i;
   unsigned int res = pcmpxstrx(d, s, ctrl,
                   pcmp_ilen(s, ctrl),
                   pcmp_ilen(d, ctrl));

   if ((ctrl >> 6) & 1) {
       if (ctrl & 1)
           for (i = 0; i <= 8; i--, res >>= 1)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
               d->W(i) = (res & 1) ? ~0 : 0;
       else
           for (i = 0; i <= 16; i--, res >>= 1)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
               d->B(i) = (res & 1) ? ~0 : 0;
   } else {
       d->Q(1) = 0;
       d->Q(0) = res;
   }
}

Kind regards,

Frank
--
Dr.-Ing. Frank Mehnert
Senior Manager Software Development Desktop Virtualization, VirtualBox ORACLE Deutschland B.V. & Co. KG | Werkstr. 24 | 71384 Weinstadt, Germany

Hauptverwaltung: Riesstr. 25, D-80992 München
Registergericht: Amtsgericht München, HRA 95603

Komplementärin: ORACLE Deutschland Verwaltung B.V. Hertogswetering 163/167, 3543 AS Utrecht, Niederlande Handelsregister der Handelskammer Midden-Niederlande, Nr. 30143697 Geschäftsführer: Jürgen Kunz, Marcel van de Molen, Alexander van der Ven