剪切蒐集文章 2 關於iphone指令集

iPhone指令集 

本文所講的內容都是圍繞iPhone的指令集(想了解ARM指令集的同學請點擊這裏),現在先說說不同型號的iPhone都使用的是什麼指令集: 

ARMv8/ARM64 = iPhone 5s, iPad Air, Retina iPad MiniARMv7s = iPhone 5, iPhone 5c, iPad 4ARMv7= iPhone 3GS, iPhone 4, iPhone 4S, iPod 3G/4G/5G, iPad, iPad 2, iPad 3, iPad MiniARMv6= iPhone, iPhone 3G, iPod 1G/2G 

設置你想支持的指令集 

Xcode中關於生成二進制包指令集相關的設置項有以下三個: 
Architectures 
官方文檔說明: 
Space-separated list of identifiers. Specifies the architectures (ABIs, processor models) to which the binary is targeted. When this build setting specifies more than one architecture, the generated binary may contain object code for each of the specified architectures. 

改變以選項指定了工程將被編譯成支持哪些指令集,支持指令集是通過編譯生成對應的二進制數據包實現的,如果支持的指令集數目有多個,就會編譯出包含多個指令集代碼的數據包,造成最終編譯的包很大。 

Valid Architectures 
官方文檔說明: 
Space-separated list of identifiers. Specifies the architectures for which the binary may be built. During the build, this list is intersected with the value of ARCHS build setting; the resulting list specifies the architectures the binary can run on. If the resulting architecture list is empty, the target generates no binary. 

該編譯項指定可能支持的指令集,該列表和Architectures列表的交集,將是Xcode最終生成二進制包所支持的指令集。 

比如,你的Valid Architectures設置的支持arm指令集版本有:armv7/armv7s/arm64,對應的Architectures設置的支持arm指令集版本有:armv7s,這時Xcode只會生成一個armv7s指令集的二進制包。 
Build Active Architecture Only 

官方文檔說明: 


Boolean value. Specifies whether the product includes only object code for the native architecture. 

該編譯項用於設置是否只編譯當前使用的設備對應的arm指令集。 

當該選項設置成YES時,你連上一個armv7指令集的設備,就算你的Valid Architectures和Architectures都設置成armv7/armv7s/arm64,還是依然只會生成一個armv7指令集的二進制包。 

當然該選項起作用的前提是你的Xcode必須成功連接了調試設備。如果你沒有任何活躍設備,即Xcode沒有成功連接調試設備,就算該設置項設置成YES依然還會編譯Valid Architectures和Architectures指定的二進制包。 

通常情況下,該編譯選項在Debug模式都設成YES,Release模式都設成NO。 
說明 

    指令集都是可以向下兼容的 

比如,你的設備是armv7s指令集,那麼它也可以兼容運行比armv7s版本低的指令集:armv7、armv6 

    xcode對armv6指令集的支持 

Xcode4.5起不再支持armv6,Xcode4.5的release notes中明確指出: 


ChangesGeneral: iOSThis version of Xcode does not generate armv6 binaries. 12282156The minimum deployment target is iOS 4.3. 12282166 

如何選擇支持的指令集 

如果你的軟件對安裝包大小非常敏感,你可以減少安裝包中的指令集數據包,而且這能達到立竿見影的效果。 

我們的項目之前支持的指令集是armv7/armv7s,後來改成只支持armv7後,比原來小了10MB左右。目前AppStore上的一些知名應用,比如百度地圖、騰訊地圖通過反彙編工具查看後,也都只支持armv7指令集。 

根據向下兼容原則,armv7指令集的應用是可以正常在支持armv7s/arm64指令集的機器上運行的。 

不過對於armv7s/arm64指令集設備來說,使用運行armv7應用是會有一定的性能損失,不過這種損失有多大缺乏權威統計數據,個人認爲是不會影響用戶體驗的。 
參考文檔 



目前ios的指令集有以下幾種: 

1,armv6,支持的機器iPhone,iPhone2,iPhone3G及對應的iTouch 

2,armv7,支持的機器iPhone4,iPhone4S 

3,armv7s,支持的機器iPhone5,iPhone5C 

4,arm64,支持的機器:iPhone5S 

機器對指令集的支持是向下兼容的,因此armv7的指令集是可以運行在iphone5S的,只是效率沒那麼高而已~ 

======================== 

Architecture : 指你想支持的指令集。 

Valid architectures : 指即將編譯的指令集。 

Build Active Architecture Only : 只是否只編譯當前適用的指令集。 

======== 

現在是2014年初,其實4和4S的用戶還是蠻多的,而iphone3之類的機器幾乎沒有了,所以我們的指令集最低必須基於armv7. 

因此,Architecture的值選擇:armv7 armv7s arm64(選arm64時需要最低支持5.1.1,這塊不太明白) 

1,如果想自己的app在各個機器都能夠最高效率的運行,則需要將Build Active Architecture Only改爲NO,Valid architectures選擇對應的指令集:armv7 armv7s arm64。這個會爲各個指令集編譯對應的代碼,因此最後的 ipa體積基本翻了3倍。(如果不在乎app大小的話,應該這樣做) 

2,如果想讓app體積保持最小,則現階段應該選擇Valid architectures爲armv7,這樣Build Active Architecture Only選YES或NO就無所謂了。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章