布斯乘法算法

布斯乘法算法(英語:Booth's multiplication algorithm)是计算机中一种利用数的2的补码形式来计算乘法的算法。该算法由安德鲁·唐纳德·布思于1950年发明,当时他在伦敦大学柏贝克学院晶体学研究。布斯曾使用过一种台式计算器,由于用这种计算器来做移位计算比加法快,他发明了该算法来加快计算速度。布斯算法在计算机体系结构学科中备受关注。

算法描述

对于N位乘数Y,布斯算法检查其2的补码形式的最后一位和一个隐含的低位,命名为y-1,初始值为0。对于yi, i = 0, 1, ..., N - 1,考察yiyi - 1。当这两位相同时,存放积的累加器P的值保持不变。当yi = 0且yi - 1 = 1时,被乘数乘以2i加到P中。当yi = 1且yi - 1 = 0时,从P中减去被乘数乘以2i的值。算法结束后,P中的数即为乘法结果。

该算法对被乘数和积这两个数的表达方式并没有作规定。一般地,和乘数一样,可以采用2的补码方式表达。也可以采用其他计数形式,只要支持加减法就行。这个算法从乘数的最低位执行到最高位,从i = 0开始,接下来和2i的乘法被累加器P的算术右移所取代。较低位可以被移出,加减法可以只在P的前N位上进行。[1]

典型实现

布斯算法的实现,可以通过重复地在P上加两个预设值A S 其中的一个,然后对P实施算术右移。设mr分别为被乘数和乘数,再令xy分别为mr中的数字位数。

  1. 确定AS的值,以及P的初始值。这三个数字的长度都应等于(x + y + 1):
    1. 对于A,以m的值填充前x位(最靠左的位),用零填满剩下的(y + 1)位;
    2. 对于S,以( - m)的值填充前x位,用零填满剩下的(y + 1)位;
    3. 对于P:用0填满最左的x位,将r的值附加在尾部;最右一位用零占位(辅助位,当i=0时i-1=-1,指的就是这个辅助位);
  2. 考察P的最右两位:
    1. 如果等于01,求出P + A的值,忽略上溢;
    2. 如果等于10,求出P + S的值,忽略上溢;
    3. 如果等于00,不做任何运算,在下一步中直接采用P的值;
    4. 如果等于11,不做任何运算,在下一步中直接采用P的值。
  3. 对第2步中得到的值进行算术右移一位,并将结果赋给P
  4. 重复第2步和第3步,一共做y次;
  5. 舍掉P的最右一位,得到的即为mr的积。

换另一种说法:把前x位用一个单独的数R0表示,中间y位用另一个数表示R1表示,辅助位用Z表示 在这里,要通过重复的把R0加上或者减去m来得到结果。具体如下: 初始值R0=0,R1=r.Z=0,此时来考查yi和yi-1这两位,在这里就是r的最后一位和Z的值。这里要说下为什么每次看的都是这两位了。在下边每次运算后都会把R0,R1,Z中的值右移一次,RO的最后一位移入R1的高位,R1的最后一位移入Z。这里要注意的是在右移R0时,如果他的最高位是1,则移位后最高位用1填充,如果最高位是0,移位后最高位用0填充。接下来要按r的最后一位和Z的值来判断怎么加减了:

    1. 如果为01,则R0+m,进位忽略。然后R0,R1,Z右移一位,再下一步判断,直到把R1的每一位都判断过后为结束
    2. 如果为10,则R0-m,借位忽略(只要x位的R0的值)。然后R0,R1,Z右移一位,再下一步判断,直到把R1的每一位都判断过后为结束
    3. 如果为00或是11,则R0的值保持不变。然后R0,R1,Z右移一位,再下一步判断,直到把R1的每一位都判断过后为结束

最后是结果,结果就是R0并上R1的值。比如R0=3,R1=25,结果就是325.

算法原理

考虑一个由若干个0包围着若干个1的正的二进制乘数,比如00111110,积可以表达为:

其中,M代表被乘数。变形为下式可以使运算次数可以减为两次:

事实上,任何二进制数中连续的1可以被分解为两个二进制数之差:

因此,我们可以用更简单的运算来替换原数中连续为1的数字的乘法,通过加上乘数,对部分积进行移位运算,最后再将之从乘数中减去。它利用了我们在针对为零的位做乘法时,不需要做其他运算,只需移位这一特点,这很像我们在做和99的乘法时利用99 = 100 − 1这一性质。这种模式可以扩展应用于任何一串数字中连续为1的部分(包括只有一个1的情况)。那么,

布斯算法遵从这种模式,它在遇到一串数字中的第一组从0到1的变化时(即遇到01时)执行加法,在遇到这一串连续1的尾部时(即遇到10时)执行减法。这在乘数为负时同样有效。当乘数中的连续1比较多时(形成比较长的1串时),布斯算法较一般的乘法算法执行的加减法运算少。

参考来源

  1. ^ Chi-hau Chen. Signal processing handbook. CRC Press. 1988: 234. ISBN 9780824779566. 

延伸阅读

  1. Andrew D. Booth. A signed binary multiplication technique. The Quarterly Journal of Mechanics and Applied Mathematics, Volume IV, Pt. 2 [1]页面存档备份,存于互联网档案馆
  2. Collin, Andrew. Andrew Booth's Computers at Birkbeck College页面存档备份,存于互联网档案馆). Resurrection, Issue 5, Spring 1993. London: Computer Conservation Society.
  3. Patterson, David and John Hennessy. Computer Organization and Design: The Hardware/Software Interface, Second Edition. ISBN 1-55860-428-6. San Francisco, California: Morgan Kaufmann Publishers. 1998.
  4. Stallings, William. Computer Organization and Architecture: Designing for performance, Fifth Edition. ISBN 0-13-081294-3. New Jersey: Prentice-Hall, Inc.. 2000.

外部链接

Read other articles:

Grandiflora rose cultivar Rosa 'Wild Blue Yonder'Rosa 'Wild Blue Yonder'GenusRosa hybridCultivar groupGrandifloraCultivarWEKisosblipMarketing names'Wild Blue Yonder', 'Blue Eden'BreederCarruthOriginUnited States, 2004 Rosa 'Wild Blue Yonder', (aka WEKisosblip), is a grandiflora rose cultivar, bred by Tom Carruth in 2004, and introduced into the United States by Weeks Rose Growers in 2006. The rose was named an All-America Rose Selections winner in 2006.[1] Description 'Wild Blue Yonde...

 

Japanese Spaceport This article includes a list of references, related reading, or external links, but its sources remain unclear because it lacks inline citations. Please help improve this article by introducing more precise citations. (September 2013) (Learn how and when to remove this template message) Uchinouraclass=notpageimage| Location of the Uchinoura Space Center Map all coordinates using OpenStreetMap Download coordinates as: KML GPX (all coordinates) GPX (primary coordinates) GPX (...

 

Yuliya MenshovaLahirYuliya Vladimirovna Menshova28 Juli 1969 (umur 54)Moscow, RSFSR, USSRKebangsaanRusiaPekerjaanAktris produserSuami/istriIgor GordinAnak2PenghargaanTEFI - 1999 Yuliya Vladimirovna Menshova (bahasa Rusia: Ю́лия Влади́мировна Меньшо́ва; lahir 28 Juli 1969) adalah seorang aktris, juga pembawa acara asal Rusia.[1] Dia adalah pemenang penghargaan televisi nasional Rusia TEFI dalam Talk-show (1999).[2] Referensi ^ Все вып�...

Main article: 1944 United States presidential election 1944 United States presidential election in Arizona ← 1940 November 7, 1944[1] 1948 → All 4 Arizona votes to the Electoral College   Nominee Franklin D. Roosevelt Thomas E. Dewey Party Democratic Republican Home state New York New York Running mate Harry S. Truman John W. Bricker Electoral vote 4 0 Popular vote 80,926 56,287 Percentage 58.80% 40.90% County Results Roosevelt ...

 

1991 World Sportscar Championship Previous 1990 Next 1992 The 1991 FIA Sportscar World Championship season was the 39th season of FIA World Sportscar Championship motor racing. It featured the 1991 FIA Sportscar World Championship, which was contested over an eight race series from 14 April to 28 October 28, 1991. The series was open to Group C Sportscars, with Category 1 cars complying with new 1991 Group C rules and Category 2 cars running under the pre 1991 regulations. Teo Fabi won the D...

 

American breed of domestic chicken Plymouth RockHens, barred plumageConservation statusrecoveringOther namesRockBarred RockCountry of originUnited StatesStandardAmerican Poultry AssociationUsedual-purpose breedTraitsWeightMale: Standard: minimum 3.4 kg (7.5 lb)[1]: 241 Bantam: maximum 1.4 kg (3 lb)[1]: 242 Female: Standard: minimum 2.9 kg (6.5 lb)[1]: 241 Bantam: maximum 1.1 kg (2.5 ...

Aquia FormationStratigraphic range: Late Paleocene~59.0–55.5 Ma PreꞒ Ꞓ O S D C P T J K Pg N ↓ Boulder of Aquia Formation along Chester River. Contains casts of large mollusks. (c. 1917)TypeGeological formationUnit ofPamunkey GroupSub-unitsPaspotansa & Piscataway MembersUnderliesNanjemoy FormationOverliesBrightseat FormationThicknessup to 100 feet (30 m)LithologyPrimarySandstoneLocationLocationHopewell, VirginiaCoordinates38°18′N 77°18′W / 38.3°...

 

Á

Latin letter A with acute accentThis article needs additional citations for verification. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed.Find sources: Á – news · newspapers · books · scholar · JSTOR (February 2024) (Learn how and when to remove this template message)Latin letter A with acute Á, á (a-acute) is a letter of the Chinese (Pinyin), Blackfoot, Czech, Dutch, Faroese...

 

This article includes inline citations, but they are not properly formatted. Please improve this article by correcting them. Parenthetical referencing has been deprecated; convert to shortened footnotes. (February 2023) (Learn how and when to remove this template message) Part of a series onPhilosophy  Philosophy portal Contents Outline Lists Glossary History Categories Disambiguation Philosophies By period Ancient Ancient Egyptian Ancient Greek Medieval Renaissance Modern Contempora...

2016 mystery debut novel by Jane Harper For the 2020 film derived from this novel, see The Dry (film). The Dry AuthorJane HarperCountryAustraliaLanguageEnglishSeriesAaron FalkGenreCrimePublisherMacmillan PublishersPublication dateMay 31, 2016Pages336ISBN1-250-10560-9Followed byForce of Nature  The Dry is the 2016 debut novel by Australian author Jane Harper.[1][2] The book has won numerous international awards[3][4][5] and has sold more than o...

 

此條目翻譯品質不佳。翻譯者可能不熟悉中文或原文語言,也可能使用了機器翻譯。請協助翻譯本條目或重新編寫,并注意避免翻译腔的问题。明顯拙劣的翻譯請改掛{{d|G13}}提交刪除。  「希拉克」重定向至此。關於法国洛泽尔省的同名市镇,請見「希拉克 (洛泽尔省)」。 雅克·勒内·希拉克Jacques René Chirac 第22任法國總統安道爾大公任期1995年5月17日—2007年5月16日...

 

If I Lose MyselfSingel oleh OneRepublicdari album NativeDirilis8 Januari 2013Direkam2012Durasi4:01LabelMosleyInterscopePenciptaRyan TedderBrent KutzleZach FilkinsBenjamin LevinProduserRyan TedderBenny BlancoBrent KutzleKronologi singel OneRepublic Feel Again (2012) If I Lose Myself (2013) Counting Stars (2013) If I Lose Myself adalah lagu yang direkam oleh band pop rock asal Amerika Serikat OneRepublic untuk album studio ketiga mereka, Native (2013). Lagu ini dirilis sebagai singel resmi pert...

Questa voce o sezione sull'argomento radio non cita le fonti necessarie o quelle presenti sono insufficienti. Puoi migliorare questa voce aggiungendo citazioni da fonti attendibili secondo le linee guida sull'uso delle fonti. Segui i suggerimenti del progetto di riferimento. Radio PopolarePaeseItalia Data di lancio1976 Share di ascolti166.000 (anno 2016[1]) EditoreErrepi Nomi precedentiRadio Popolare MottoLibera e indipendente Sito webwww.radiopopolare.it/ DiffusioneTerrestr...

 

Bandar Udara Internasional Bacha KhanIATA: PEWICAO: OPPS PEWLokasi bandar udara di PakistanInformasiJenisPublikPengelolaOtoritas Penerbangan Sipil PaistanMelayaniPeshawarLokasiProvinsi Khyber Pakhtunkhwa, PakistanKetinggian dpl353 mdplKoordinat33°59′38″N 71°30′53″E / 33.99389°N 71.51472°E / 33.99389; 71.51472Landasan pacu Arah Panjang Permukaan kaki m 17/35 9,000 2,743 Aspal StatistikPenumpang1,035,259[1]Kargo9,338 ton[1] Bandar Ud...

 

Equestrian at the Olympics Team eventingat the Games of the VIII OlympiadVenueStade Olympique Yves-du-ManoirDates21–26 JulyCompetitors40 from 10 nationsMedalists Antonius Colenbrander, Gerard de Kruijff, Charles Pahud de Mortanges, Adolph van der Voort van Zijp Netherlands Gustaf Hagelin, Claës König, Carl Gustaf Lewenhaupt, Torsten Sylvan Sweden Alessandro Alvisi, Emanuele Beraudo di Pralormo, Tommaso Lequio di Assaba, Alberto Lombardi Italy← 19201928&...

American court case alleging demonic possession Devil made me do it caseCourtConnecticut Superior CourtDecidedNovember 25, 1981VerdictFound guilty of first degree manslaughter charge and sentenced to 10 to 20 years prison, serving 5 for good behavior.[1]DefendantArne Cheyenne JohnsonCitationhttps://archives.law.virginia.edu/dengrove/writeup/arne-cheyenne-johnson The trial of Arne Cheyenne Johnson, also known as the devil made me do it case, is the first known court case in the United ...

 

16th season of the Premier League Football league seasonPremier LeagueManchester United celebrating their 10th Premier League title following their win at WiganSeason2007–08Dates11 August 2007 – 11 May 2008ChampionsManchester United10th Premier League title17th English titleRelegatedReading Birmingham CityDerby CountyChampions LeagueManchester UnitedChelseaArsenalLiverpoolUEFA CupPortsmouthEvertonTottenham HotspurManchester City (through UEFA Respect Fair Play ranking)Intertoto CupAston ...

 

German miniaturist, pastelist and court painter Johanna Juliana Friederike BacciarelliBorn21 May 1733Dresden, Electorate of SaxonyDied1809, 1811 or 1812Warsaw, Duchy of WarsawNationalityGermanKnown forPainting Johanna Juliana Friederike Bacciarelli, née Richter (21 May 1733 – 1809 or later), was a German miniaturist, pastelist and court painter to the Polish kings. Early life and education Stanisław August Poniatowski, circle of Bacciarelli Johanna was born on 21 May,[1][...

Este artigo não cita fontes confiáveis. Ajude a inserir referências. Conteúdo não verificável pode ser removido.—Encontre fontes: ABW  • CAPES  • Google (N • L • A) (Junho de 2022) SÉCULOS: Século XIII — Século XIV — Século XV DÉCADAS: 1280 • 1290 • 1300 • 1310 • 1320 • 1330 • 1340 • 1350 • 1360 • 1370 • 1380 ANOS: 1334 • 1335 • 1336 • 1337 • 1338 • 1339 • 1340 • 13...

 

Hungarian rabbi, botanist, and politician (1854–1944) This article needs additional citations for verification. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed.Find sources: Immanuel Löw – news · newspapers · books · scholar · JSTOR (February 2021) (Learn how and when to remove this message) Immanuel Löw Immanuel Löw (January 20, 1854 in Szeged – July 19, 1944 in Budapest...