lkml.org 
[lkml]   [2006]   [Jan]   [20]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    Date
    From
    Subjectset_bit() is broken on i386?
    /* 
    * setbit.c -- test the Linux set_bit() function
    *
    * Compare the output of this program with and without the
    * -finline-functions option to GCC.
    *
    * If they are not the same, set_bit is broken.
    *
    * Result on i386 with gcc 3.3.2 (Fedora Core 2):
    *
    * [me@d2 t]$ gcc -O2 -o setbit.ex setbit.c ; ./setbit.ex
    * 00010001
    * [me@d2 t]$ gcc -O2 -o setbit.ex -finline-functions setbit.c ; ./setbit.ex
    * 00000001
    */
    #define _GNU_SOURCE
    #include <stdio.h>
    #include <stdlib.h>

    #define inline __attribute__((always_inline))

    /*
    * From 2.6.15/include/asm-i386/bitops.h -- needs a memory clobber?
    */
    #define ADDR (*(volatile long *) addr)
    static inline void set_bit(int nr, volatile unsigned long * addr)
    {
    __asm__ __volatile__( "lock ; "
    "btsl %1,%0"
    :"=m" (ADDR)
    :"Ir" (nr));
    }

    unsigned long b[2];

    int main(int argc, char * const argv[])
    {
    b[1] = 0x1;
    set_bit(12 * sizeof(unsigned long), b);
    printf("%08x\n", b[1]);
    return 0;
    }
    --
    Chuck
    Currently reading: _Sun Of Suns_ by Karl Schroeder
    -
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    More majordomo info at http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at http://www.tux.org/lkml/

    \
     
     \ /
      Last update: 2006-01-21 01:58    [W:0.018 / U:64.304 seconds]
    ©2003-2016 Jasper Spaans. hosted at Digital OceanAdvertise on this site