freevec.org

  • about
  • benchmarks
Home

Search

Primary links

  • About
    • History of libfreevec
  • Benchmarks
    • libfreevec

Please donate to libfreevec to ensure its continuing development! Donations are done via Paypal.





AltiVec runtime detection in Linux

markos — Thu, 10/04/2008 - 14:01

After a little search I did on Google to find how to detect AltiVec runtime in Linux (I used keywords such as runtime altivec detection and similar), I found that there is no single nice article anywhere that describes something so simple. Thankfully, I got a few good answers from benh and dwmw2 in #mklinux/FreeNode, and I decided to put these down in a cleaned up form.

So here is a little function (also as an attachment) that is tested to work (and will also be in some form part of libfreevec and will also be used for AltiVec detection in SIMDx86 as well). Resubmitted with permission from David Woodhouse.
NOTE: According to David, any methods that use SIGILL handlers (executing AltiVec code and catching the signal when AltiVec is not supported) should be avoided, as they lead to problems such as this one. Use this method instead.

#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <linux/auxvec.h>
#include <asm/cputable.h>
 
int have_altivec() {
    static int available = -1;
    int new_avail = 0;
    char fname[64];
    unsigned long buf[64];
    ssize_t count;
    pid_t pid;
    int fd, i;
 
    if (available != -1)
            return available;
 
    pid = getpid();
    snprintf(fname, sizeof(fname)-1, "/proc/%d/auxv", pid);
 
    fd = open(fname, O_RDONLY);
    if (fd < 0)
            goto out;
 more:
    count = read(fd, buf, sizeof(buf));
    if (count < 0)
            goto out_close;
 
    for (i=0; i < (count / sizeof(unsigned long)); i += 2) {
            if (buf[i] == AT_HWCAP) {
            new_avail = !!(buf[i+1] & PPC_FEATURE_HAS_ALTIVEC);
                    goto out_close;
            } else if (buf[i] == AT_NULL) {
                    goto out_close;
            }
    }
 
    if (count == sizeof(buf))
            goto more;
 out_close:
    close(fd);
 out:
    available = new_avail;
    return available;
}
 
int main() {
        int altivec_support = have_altivec();
        printf("Altivec support: %d\n", altivec_support);
        return(0);
}

SIMD

  • AltiVec
AttachmentSize
altivec_detect.c1.04 KB
  • Login or register to post comments

/proc/self ?

mwsealey — Thu, 01/01/2009 - 02:17

Why would you need to getpid(), wouldn't /proc/self work just as well and require less code and less playing around?

  • Login or register to post comments

SIMD

  • Algorithms (31)
    • Algebra (9)
      • Matrix operations (8)
    • Bit operations (0)
    • Codecs (0)
      • Audio (0)
      • Video (0)
    • Comparison (0)
      • image comparison (0)
      • Levenshtein (0)
    • Compression (0)
      • Bzip2 (0)
      • Gzip (0)
      • LZMA (0)
      • LZW (0)
      • Squashfs (0)
      • Zlib (0)
    • Encryption (0)
      • AES (0)
      • DES (0)
      • RSA (0)
      • Salsa (0)
      • SSL (0)
    • Hashing (1)
      • CRC (0)
      • TCP/IP checksum (0)
      • UMAC (0)
    • Memory operations (15)
    • Multiprecision (0)
    • Searching (5)
      • String searching (5)
    • Sorting (0)
  • Software (32)
    • Benchmarking (2)
    • Libraries (30)
      • Eigen2 (0)
      • libfreevec (22)
      • simdX86 (8)
  • Architecture (32)
    • AltiVec (32)
    • ARM NEON (0)
    • CELL SPU (0)
    • SSE (0)
    • VIS (0)

User login

  • Create new account
  • Request new password
  • about
  • benchmarks

Copyright (c)2008 by CODEX.
Powered by Drupal. Using theme Deco.
All Google charts have been created by the CSV Chart and Chart API Drupal modules.