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
俺はビッグエンディアンでテストがしたいんだ!
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.8k
今風トゥーンシェーディング
kenjihanada
0
3.1k
お父さんが教えるプログラミング教育
kenjihanada
0
2.8k
Other Decks in Technology
See All in Technology
コードや知識を組み込む / Incorporate Code and Knowledge
ks91
PRO
0
170
20260428_Product Management Summit_tadokoroyoshiro
tadokoro_yoshiro
10
13k
AgentCore×VPCでの設計パターンn選と勘所
har1101
3
300
Oracle AI Database@AWS:サービス概要のご紹介
oracle4engineer
PRO
4
2.4k
Agents CLI と Gemini Enterprise Agent Platform で マルチエージェント開発が楽しくなる!
kaz1437
0
130
EBS暗号化に失敗してEC2が動かなくなった話
hamaguchimmm
2
210
Keeping Ruby Running on Cygwin
fd0
0
170
「誰一人取り残されない」 AIエージェント時代のプロダクト設計思想 Product Management Summit 2026
mizushimac
1
1.4k
Route 53 Global Resolver で高額課金発生!
otanikohei2023
0
120
Practical TypeProf: Lessons from Analyzing Optcarrot
mame
0
910
Do Vibe Coding ao LLM em Produção para Busca Agêntica - TDC 2026 - Summit IA - São Paulo
jpbonson
3
150
[最強DB講義]推薦システム | 基礎編
recsyslab
PRO
1
180
Featured
See All Featured
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
110
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
Technical Leadership for Architectural Decision Making
baasie
3
330
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
54k
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
62
53k
Building Adaptive Systems
keathley
44
3k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.7k
Faster Mobile Websites
deanohume
310
31k
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
270
Crafting Experiences
bethany
1
120
The AI Search Optimization Roadmap by Aleyda Solis
aleyda
1
5.6k
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