Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
俺はビッグエンディアンでテストがしたいんだ!
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
kenjihanada
February 22, 2019
Technology
3k
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
俺はビッグエンディアンでテストがしたいんだ!
by kawashin73
kenjihanada
February 22, 2019
More Decks by kenjihanada
See All by kenjihanada
Akatsuki Summer Internship 2019 インターン成果発表
kenjihanada
0
2.3k
ゼロから始めるGo Modules
kenjihanada
0
2.9k
MMOの作り方
kenjihanada
0
2.9k
今風トゥーンシェーディング
kenjihanada
0
3.2k
お父さんが教えるプログラミング教育
kenjihanada
0
2.8k
Other Decks in Technology
See All in Technology
自宅LLMの話
jacopen
1
600
FinOps × AIエージェントで実現する コストインシデントの自動調査
oasis1994liveforever
0
150
【NRUG vol.18】なぜ多くのオブザーバビリティ導入は失敗するのか
nrug_member
0
170
GitHub Copilot 最新アップデート – 「一歩先」の実践活用術
moulongzhang
4
1.2k
Bucharest Tech Week 2026 - Reinventing testing practices in the AI era
edeandrea
PRO
1
160
あなたの知らないPDFのアクセシビリティ
lycorptech_jp
PRO
0
200
脆弱性対応、どこで線を引くか
rymiyamoto
1
400
ACE-Step-1.5で見る 音楽生成AIのしくみと“破綻だけ直す”Retake機能の開発【zennfes spring 2026 登壇資料】
personabb
1
500
データサイエンスを価値につなげるプロジェクト設計 〜 DS一年目が現場で得た気づき 〜
ysd113
1
260
AIエージェントが名古屋の猛暑からあなたを守る
happysamurai294
0
130
やさしいA2A入門
minorun365
PRO
12
1.9k
小さく始める AI 活用推進 ― 日経電子版 Web チームの事例/nikkei-tech-talk47
nikkei_engineer_recruiting
0
270
Featured
See All Featured
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
230
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
55k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
35k
Building a Scalable Design System with Sketch
lauravandoore
463
34k
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
590
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.3k
The Mindset for Success: Future Career Progression
greggifford
PRO
0
360
Reality Check: Gamification 10 Years Later
codingconduct
0
2.2k
How GitHub (no longer) Works
holman
316
150k
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
11k
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
62
54k
Building an army of robots
kneath
306
46k
Transcript
俺はビッグエンディアンでテス トがしたいんだ! @kawasin73
言語の壁をぶっ壊す
自己紹介 かわしん @kawasin73 東京大学工学部システム創成学科 3年生 (2年半休学してました) DMM.com のCTO室で、Go言語でデータベースを作るインターン この1年半くらいGo。それまでは、Rails、iOS、Android、Webフロントなど 趣味は特にない(強いて挙げれば蟻の飼育)
ビットベクトルライブラリを作ってテストした Go 言語で マシンエンディアンに関わらず 指定されたエンディアンで動く ビットベクトルライブラリを作ってテストを行った https://github.com/kawasin73/bitset ビットベクトル:[]bool の省メモリ版データ構造
エンディアンとは
エンディアンはバイトの並び順(バイトオーダーとも) 例えば uint64 は 8 バイトの数値。その中身がどのように配置されているか ビッグエンディアン 0x0123456789abcdef → 0x01
| 0x23 | 0x45 | 0x67 | 0x89 | 0xab | 0xcd | 0xef リトルエンディアン → 0xef | 0xcd | 0xab | 0x89 | 0x67 | 0x45 | 0x23 | 0x01 エンディアンとは
エンディアンはどう決まるのか エンディアンは CPU によって違う。 amd64 (Intel) など → リトルエンディアン arm
など → ビッグエンディアン CPU によっては切り替えることもできる
エンディアンはいつ気にするのか? バイナリで外部とのやりとり(ファイル読み書き、ネットワーク通信)する時 エンディアンが違うと正しい値を読み取れない。 ビッグエンディアンの uint64(1) → リトルエンディアンのuint64(72057594037927936) 普通は、ネットワークライブラリがエンディアン処理をしているので、気にする必要はな い。
Go でのエンディアン "encoding/binary" パッケージが用意されている binary.BigEndian.PutUint64(bytes, v) binary.LittleEndian.Uint64(bytes) Go ではエンディアンは露出しない。uint64 のビットの順番は環境に寄らず同じ
課題 ファイルへの読み書きを頻繁に行う時 毎回エンディアン処理を行うのはオーバーヘッドになる。
言語の壁をぶっ壊す
unsafe.Pointer だ!!
unsafe.Pointer マシンエンディアンで直接扱うために、unsafe.Pointer を使って []byte から []uint64 に 強制キャストをしている。
壊したので unsafe.Pointer によって壊したので、どのエンディアンの環境でも正しく動くかをテストす る必要がある。
俺はビッグエンディアンでテス トがしたいんだ! @kawasin73 本編
Travis CI で自動テスト Travis CI の CPU アーキテクチャは amd64 (リトルエンディアン)のみ
Travis CI でビッグエンディアンでテストする手法を探す → QEMU でビッグエンディアンの CPU をエミュレートする
qemu で go test Linux で Go の実行環境をインストールできるのは以下のCPUアーキテクチャ amd64, 386,
arm, arm64, s390x, ppc64le この中で、ビッグエンディアンなのは s390x https://golang.org/doc/install#requirements ※ arm はリトルエンディアン、armbe がビッグエンディアン
qemu-ppc64-static で go test 無慈悲なエラー
なんでや
go test はできない 原因は不明。Go が悪いのか qemu が悪いのか。 qemu が特定の CPU
命令に対応していない? 行き詰まった。
救世主
おい、テストを コンパイルできるらしいぞ
コンパイルできると可能性が広がる ビッグエンディアンに対応している ppc64, mips, mips64, s390x ppc64 だとうまくいった
結論
None
よっしゃ https://travis-ci.com/kawasin73/bitset/jobs/172066523
参考資料 ブログ記事 https://kawasin73.hatenablog.com/entry/2018/12/01/172708 対応した github issue https://github.com/kawasin73/bitset/issues/5