Skip to Content
Binary Hacks Rebooted ―低レイヤの世界を探検するテクニック89選
book

Binary Hacks Rebooted ―低レイヤの世界を探検するテクニック89選

by 河田 旺, 小池 悠生, 渡邉 慶一, 佐伯 学哉, 荒田 実樹, 鈴木 創, 中村 孝史, 竹腰 開, 光成 滋生, hikalium, 浜地 慎一郎
August 2024
Intermediate to advanced
660 pages
9h 58m
Japanese
O'Reilly Japan, Inc.
Content preview from Binary Hacks Rebooted ―低レイヤの世界を探検するテクニック89選

8章言語処理系HackHack #79–86

通常、コンパイラの教科書では構文解析やレジスタ割り付けといったオーソドックスなテーマが扱われています。それらのテーマも非常に重要なのですが、現実世界のコンパイラ・インタプリタ周辺には、有名ではなくても特定の状況下で役に立つテクニックが多数存在します。本章ではそれらのテクニックをまとめて紹介します。言語処理系周辺でHackをしたくなったときに本章の内容が役に立つでしょう。

[level-medium] HACK #79 NaNを活用して64ビット値にタグ付きの値を格納する

本Hackでは、64ビット値に倍精度浮動小数点数やポインタ等の値をタグ付きで格納するテクニックを紹介します。

動的型付き言語での値の表現

動的型付き言語の典型的な実装では、任意の種類の値を区別・表現できるように、種類を表すタグと実際の内容を組み合わせて値を表現しています。C言語の構造体として書けば次のようになります。

struct Value {
  uint8_t tag;
  union {
    Object *obj; // 固定長で表現できないデータや可変なオブジェクトを表現するためにポインタを使う
    double f64;
    int32_t i32;
  };
};

この定義では、x86-32では1個の値を表現するのに12バイト、典型的な64ビット環境では16バイト必要になります†1。ですが、Value型は至るところに現れるため、メモリ上で表現する際は1バイトでも節約したいです。もっと少ないバイト数で任意の値を表現することはできないでしょうか? ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

LLMのプロンプトエンジニアリング ―GitHub Copilotを生んだ開発者が教える生成AIアプリケーション開発

LLMのプロンプトエンジニアリング ―GitHub Copilotを生んだ開発者が教える生成AIアプリケーション開発

John Berryman, Albert Ziegler, 服部 佑樹, 佐藤 直生
実用 Git 第3版

実用 Git 第3版

Prem Kumar Ponuthorai, Jon Loeliger, 萬谷 暢崇, 長尾 高弘
入門 Python 3 第2版

入門 Python 3 第2版

Bill Lubanovic, 鈴木 駿, 長尾 高弘
実践 Keycloak ―OpenID Connect、OAuth 2.0を利用したモダンアプリケーションのセキュリティー保護

実践 Keycloak ―OpenID Connect、OAuth 2.0を利用したモダンアプリケーションのセキュリティー保護

Stian Thorgersen, Pedro Igor Silva, 和田 広之, 田村 広平, 乗松 隆志, 田畑 義之

Publisher Resources

ISBN: 9784814400850Publisher Website