Hacker's Delight

{{Italic title}}

{{Short description|Software algorithm book}}

{{Use dmy dates|date=May 2019|cs1-dates=y}}

{{Use list-defined references|date=January 2022}}

{{Infobox book

| name = Hacker's Delight

| image = Hacker's Delight.jpg

| caption = Hacker's Delight First edition (2002)

| alt = Hacker's Delight

| author = Henry S. Warren, Jr.

| title_orig =

| working_title =

| translator =

| illustrator =

| cover_artist =

| country = United States

| language = English

| series =

| release_number =

| subject =

| genre =

| publisher = Addison-Wesley Professional

| pub_date = 2002

| pages = 306 (first edition), 494 (second edition)

| awards =

| isbn = 0201914654

| isbn_note = (Second edition {{ISBNT|0321842685}})

| oclc =

| congress = QA76.6.W375

| preceded_by =

| followed_by =

| wikisource =

}}

Hacker's Delight is a software algorithm book by Henry S. Warren, Jr. first published in 2002. It presents fast bit-level and low-level arithmetic algorithms for common tasks such as counting bits or improving speed of division by using multiplication.

Background

The author, an IBM researcher working on systems ranging from the IBM 704 to the PowerPC, collected what he called "programming tricks" over the course of his career. These tricks concern efficient low-level manipulation of bit strings and numbers. According to the book's foreword by Guy L. Steele, the target audience includes compiler writers and people writing high-performance code.

Summary

Programming examples are written in C and assembler for a RISC architecture similar, but not identical to PowerPC. Algorithms are given as formulas for any number of bits, the examples usually for 32 bits.

Apart from the introduction, chapters are independent of each other, each focusing on a particular subject. Many algorithms in the book depend on two's complement integer numbers.

The subject matter of the second edition of the book includes algorithms for

  • Basic algorithms for manipulating individual bits, formulas for identities, inequalities, overflow detection for arithmetic operations and shifts
  • Rounding up and down to a multiple of a known power of two, the next power of two and for detecting whether an operation crossed a power-of-two boundary
  • Checking bounds
  • Counting total, leading and trailing zeros
  • Searching for bit strings
  • Permutations of bits and bytes in a word
  • Software algorithms for multiplication
  • Integer division
  • Efficient integer division and calculating of the remainder when the divisor is known
  • Integer square and cube roots
  • Unusual number systems, including base −2
  • Transfer of values between floating-point and integer
  • Cyclic redundancy checks, error-correcting codes and Gray codes
  • Hilbert curves, including a discussion of applications

Style

The style is that of an informal mathematical textbook. Formulas are used extensively. Mathematical proofs are given for some non-obvious algorithms, but are not the focus of the book.

Reception

Overall reception has been generally positive.

Publication history

The book was published by Addison-Wesley Professional. The first edition was released in 2002 and the second in 2013.

Japanese language edition of this book was published by SIBaccess Co. Ltd., in 2004.

See also

References

{{Reflist|refs=

{{Cite book |title=Hacker's Delight |author-first=Henry S. Jr. |author-last=Warren |date=2002 |edition=1 |publisher=Addison Wesley |isbn=978-0-201-91465-8}}

{{Cite book |title=Hacker's Delight |author-first=Henry S. Jr. |author-last=Warren |date=2013 |edition=2 |publisher=Addison Wesley - Pearson Education, Inc. |isbn=978-0-321-84268-8 |url=https://books.google.com/books?id=VicPJYM0I5QC}}

{{cite journal |title=Book Review: Engineer's Bookshelf - Hacker's Delight by Henry S. Warren, Jr. |author-first=Clive "Max" |author-last=Maxfield |journal=EE Times |date=2012-04-05 |url=http://www.eetimes.com/author.asp?doc_id=1286016 |access-date=2017-04-02 |url-status=live |archive-url=https://web.archive.org/web/20170402223009/http://www.eetimes.com/author.asp?doc_id=1286016 |archive-date=2017-04-02}}

{{cite journal |author-last=Baxter |author-first=Michael |title=Hacker's Delight |department=Reviews |journal=Linux Journal |date=2003-04-01 |url=https://www.linuxjournal.com/article/6478 |access-date=2021-08-28 |url-status=live |archive-url=https://web.archive.org/web/20200927143203/https://www.linuxjournal.com/article/6478 |archive-date=2020-09-27}}

}}

Further reading

  • {{cite book |title=HAKMEM |title-link=HAKMEM |chapter=Artificial Intelligence Memo No. 239 |author-first1=Michael |author-last1=Beeler |author-first2=Ralph William |author-last2=Gosper |author-link2=Bill Gosper |author-first3=Richard C. |author-last3=Schroeppel |author-link3=Richard C. Schroeppel |orig-date=1972-02-29 |publisher=Artificial Intelligence Laboratory, Massachusetts Institute of Technology (MIT) |location=Cambridge, Massachusetts, USA |edition=retyped & converted |date=April 1995 |editor-first=Henry Givens Jr. |editor-last=Baker |editor-link=Henry Baker (computer scientist) |chapter-url=http://home.pipeline.com/~hbaker1/hakmem/hakmem.html |access-date=2016-01-02 |url-status=live |archive-url=https://web.archive.org/web/20191008012414/http://home.pipeline.com/~hbaker1/hakmem/hakmem.html |archive-date=2019-10-08}}
  • {{cite web |title=Arithmetic Tutorials |author-first=Douglas W. |author-last=Jones |author-link=Douglas W. Jones |publisher=The University of Iowa, Department of Computer Science |orig-date=1999 |date=2014-09-10 |location=Iowa City, Iowa, USA |url=http://homepage.cs.uiowa.edu/~jones/bcd/ |access-date=2016-01-03 |url-status=live |archive-url=https://web.archive.org/web/20190710110710/https://homepage.cs.uiowa.edu/~jones/bcd/ |archive-date=2019-07-10}}
  • {{cite web |author-first=Mike F. |author-last=Cowlishaw |author-link=Mike F. Cowlishaw |title=General Decimal Arithmetic |orig-date=1981, 2008 |date=2015 |url=http://speleotrove.com/decimal/ |access-date=2016-01-02 |url-status=live |archive-url=https://web.archive.org/web/20191102142229/http://speleotrove.com/decimal/ |archive-date=2019-11-02}}
  • {{cite book |title=Making Code Work Better - How to minimize the size of 80x86 code and sometimes make it faster |chapter=Chapter 11 - More tricks in C and Assembler code |author-first=Tony |author-last=Ingenoso |date=1999-02-03 |orig-date=1998 |type=e-book |url=http://www.bobeager.uk/tonyingenoso/chap11.htm |access-date=2019-11-18 |url-status=live |archive-url=https://web.archive.org/web/20191118001449/http://www.bobeager.uk/tonyingenoso/chap11.htm |archive-date=2019-11-18}}
  • {{cite web |title=Bit Twiddling Hacks |editor-first=Sean Eron |editor-last=Anderson |display-authors=etal |date=2009-11-26 |orig-date=1997 |publisher=Stanford University |url=https://graphics.stanford.edu/~seander/bithacks.html |access-date=2020-06-01 |url-status=live |archive-url=https://web.archive.org/web/20200601123740/https://graphics.stanford.edu/~seander/bithacks.html |archive-date=2020-06-01}}