background preloader

Bit Twiddling Hacks

Bit Twiddling Hacks
By Sean Eron Anderson seander@cs.stanford.edu Individually, the code snippets here are in the public domain (unless otherwise noted) — feel free to use them however you please. The aggregate collection and descriptions are © 1997-2005 Sean Eron Anderson. The code and descriptions are distributed in the hope that they will be useful, but WITHOUT ANY WARRANTY and without even the implied warranty of merchantability or fitness for a particular purpose. As of May 5, 2005, all the code has been tested thoroughly. Contents About the operation counting methodology When totaling the number of operations for algorithms here, any C operator is counted as one operation. Compute the sign of an integer The last expression above evaluates to sign = v >> 31 for 32-bit integers. Alternatively, if you prefer the result be either -1 or +1, then use: sign = +1 | (v >> (sizeof(int) * CHAR_BIT - 1)); // if v < 0 then -1, else +1 On the other hand, if you prefer the result be either -1, 0, or +1, then use: Related:  programming

HAKMEM -- CONTENTS -- DRAFT, NOT YET PROOFED contents index [Retyped and formatted in 'html' ('Web browser format) by Henry Baker, April, 1995. The goal of this 'html' document is to make HAKMEM available to the widest possible audience -- including those without bitmapped graphics browsers. Therefore, equations have been formatted to be readable even on ASCII browsers such as 'lynx'. Click here to get original AI Memo 239 in 400 dots/inch, 1 bit/pixel, Group 4 facsimile TIFF format (a single 5 megabyte gzip compressed tar file, AIM-239.tiff.tar.gz).] Work reported herein was conducted at the Artificial Intelligence Laboratory, a Massachusetts Institute of Technology research program supported in part by the Advanced Research Projects Agency of the Department of Defense and monitored by the Office of Naval Research under Contract Number N00014-70-A-0362-0002. Reproduction of this document, in whole or in part, is permitted for any purpose of the United States Government. People referred to are from the A. Once at the A. in France:

Research - Can Polling Location Influence STANFORD GRADUATE SCHOOL OF BUSINESS—What would you say influenced your voting decisions in the most recent local or national election? Political preferences? A candidate's stance on a particular issue? The repercussions of a proposition on your economic well-being? But Stanford Graduate School of Business researchers, doctoral graduates Jonah Berger and Marc Meredith, and S. It's hard to imagine that something as innocuous as polling location (e.g., school, church, or fire station) might actually influence voting behavior, but the Stanford researchers have discovered just that. Why might something like polling location influence voting behavior? Using data from Arizona's 2000 general election, Berger, Meredith, a visiting lecturer at MIT, and Wheeler discovered that people who voted in schools were more likely to support raising the state sales tax to fund education. This effect persisted even when the researchers controlled for—or removed the possibility of—other factors such as:

3D Programming - Weekly : Bounding Boxes Bounding Box Types This article gives an overview of oriented bounding boxes, including source code. An oriented box is allowed to rotate freely, unlike a axis-aligned bounding box, which always remains aligned to the x,y, and z axes. Data Structure To store the box, we need to store a centerpoint, a rotation, and how far the box extends from the centerpoint in the x,y,z directions. Functions This class contains the following functions: IsPointInBox: Tests if a point is in the box. Code Download bbox.h( 2KB ), bbox.cpp ( 5KB ) : An oriented bounding box class. External Link A while after I had first written a bounding box class, I found this article which inspired some code changes.

untitled Author Spotlight About Intel® 64 and IA-32 Architectures Software Developer Manuals These manuals describe the architecture and programming environment of the Intel® 64 and IA-32 processors. Links Online manuals Intel Software Developer's Manual Offerings More Detail Intel® 64 and IA-32 Architectures Software Developer's Manual, Volume 3D: System Programming Guide, Part 4 By Intel Corporation Paperback: $9.91 Prints in 3-5 business days Revision 71. More Detail Intel® 64 and IA-32 Architectures Software Developer's Manual, Volume 3C: System Programming Guide, Part 3 By Intel Corporation Paperback: $11.95 More Detail Intel® 64 and IA-32 Architectures Software Developer's Manual, Volume 2D: Instruction Set Reference By Intel Corporation Paperback: $9.55 Revision 71. More Detail Intel® 64 and IA-32 Architectures Software Developer's Manual, Volume 2C: Instruction Set Reference V-Z By Intel Corporation Paperback: $21.07 Revision 71. More Detail Paperback: $23.35 Revision 71. More Detail Paperback: $16.75

Code Charts Specials Controls: C0, C1 Layout Controls Invisible Operators Specials Tags Variation Selectors Variation Selectors Supplement Private Use Private Use Area Supplementary Private Use Area-A Supplementary Private Use Area-B Surrogates High Surrogates Low Surrogates Noncharacters in Charts Noncharacters in blocks Range in Arabic Presentation Forms-A Range in Specials Noncharacters at end of ... BMP, Plane 1, Plane 2, Plane 3, Plane 4, Plane 5, Plane 6, Plane 7, Plane 8, Plane 9, Plane 10, Plane 11, Plane 12, Plane 13, Plane 14, Plane 15, Plane 16 CS 229: Machine Learning (Course handouts) Lecture notes 1 (ps) (pdf) Supervised Learning, Discriminative Algorithms Lecture notes 2 (ps) (pdf) Generative Algorithms Lecture notes 3 (ps) (pdf) Support Vector Machines Lecture notes 4 (ps) (pdf) Learning Theory Lecture notes 5 (ps) (pdf) Regularization and Model Selection Lecture notes 6 (ps) (pdf) Online Learning and the Perceptron Algorithm. (optional reading) Lecture notes 7a (ps) (pdf) Unsupervised Learning, k-means clustering. Lecture notes 7b (ps) (pdf) Mixture of Gaussians Lecture notes 8 (ps) (pdf) The EM Algorithm Lecture notes 9 (ps) (pdf) Factor Analysis Lecture notes 10 (ps) (pdf) Principal Components Analysis Lecture notes 11 (ps) (pdf) Independent Components Analysis Lecture notes 12 (ps) (pdf) Reinforcement Learning and Control Supplemental notes 1 (pdf) Binary classification with +/-1 labels. Supplemental notes 2 (pdf) Boosting algorithms and weak learning.

My own little DirectX FAQ untitled These manuals describe the architecture and programming environment of the Intel® 64 and IA-32 architectures. Combined Volume Set of Intel® 64 and IA-32 Architectures Software Developer’s ManualsFour-Volume Set of Intel® 64 and IA-32 Architectures Software Developer’s ManualsTen-Volume Set of Intel® 64 and IA-32 Architectures Software Developer's ManualsIntel® architecture instruction set extensions programming referenceSoftware Optimization Reference ManualUncore Performance Monitoring Reference ManualsRelated Specifications, Application Notes, and White Papers Electronic versions of these documents allow you to quickly get to the information you need and print only the pages you want. The Intel® 64 and IA-32 architectures software developer's manuals are now available for download via one combined volume, a four volume set or a ten volume set. All content is identical in each set; see details below. At present, downloadable PDFs of all volumes are at version 071.

Wakaba and Kareha Wakaba and Kareha are my attempts at implementing from scratch image and message boards of a type popular in Japan (used on sites such as Futaba Channel and 2channel). This kind of board software is built around anonymous posting and no requirements for registration, to make the boards more suited for casual uses, and more fun overall. They are written in Perl, and are designed to be more efficient and cleanly written than the original scripts that are available, while preserving the same kind of functionality. Both scripts are in use at iichan, an English-language site built along the same lines as the Japanese Futaba Channel, and also 4-ch, an English-language discussion BBS. Wakaba Wakaba is an image board script very strictly modelled after the Futaba and Futallaby scripts. Kareha Kareha is a message board script. There is also a somewhat incomplete documentation wiki, which contains a bit of information about the scripts.

CS 349: Data Mining, Search, and the World Tuesdays and Thursdays 4:15 - 5:30 in Bldg 370, Room 370 on the Main Quad Instructors: Sergey Brin and Lawrence Page Tues and Thurs 5:30 - 7:00 or by appointment. sergey@cs.stanford.edu and page@cs.stanford.edu Course Assistant: Diane Tang Gates 416: Mon - Wed 11:15 - 12:15 or by appointment. dtang@cs.stanford.edu Description Over the past two years there has been a close collaboration between the Data Mining Group (MIDAS) and the Digital Libraries Group at Stanford in the area of Web research. The topics of this class are data mining and information retrieval in the context of the World Wide Web. Prerequisites A strong knowledge of C. Very Tentative Syllabus Introduction: 1 Data Mining: 5 Publications of IBM's QUEST project 10/1 Market Basket (slides) R. Mailing List

CDWFS: Optimizing for SSE: A Case Study Deprecated: Function eregi() is deprecated in /home/postgoodism/cortstratton.org/private/cortsite.php on line 19 Originally appeared in Hugi Issue #25 Table of Contents Introduction In this article I'll be describing the process of optimizing a piece of code to make use of Intel's SSE instruction set. We'll apply these techniques to a problem that often arises in computer graphics: you want to multiply a 3D vector by a 4x4 matrix. Naïve C++ So, hopefully you agree that it's important to have a fast software matrix-vector multiplier. MatrixMultiply1 (100 cycles/vec) A brief note on cycle timings: the timings I give for each function were achieved when running the sample code on my 500 MHz Pentium 3. So sure, the function works - but if all you're looking for is code that WORKS, you wouldn't be reading Hugi, would you? Basic SSE Why does Chris's version run so fast? SIMD lends itself amazingly well to matrix operations. MatrixMultiply3 (43 cycles/vec) Batch Processing Better still! Prefetching

Related: