Commit 88711eab authored by George Hotz's avatar George Hotz

this saves like 200M instructions

parent 288c7b42
...@@ -11,9 +11,6 @@ ...@@ -11,9 +11,6 @@
package main package main
import ( import (
"bytes"
"compress/zlib"
"encoding/base64"
"fmt" "fmt"
"log" "log"
"os" "os"
...@@ -30,7 +27,7 @@ func main() { ...@@ -30,7 +27,7 @@ func main() {
// Compress the serialized byte points. // Compress the serialized byte points.
serialized := btcec.S256().SerializedBytePoints() serialized := btcec.S256().SerializedBytePoints()
var compressed bytes.Buffer /*var compressed bytes.Buffer
w := zlib.NewWriter(&compressed) w := zlib.NewWriter(&compressed)
if _, err := w.Write(serialized); err != nil { if _, err := w.Write(serialized); err != nil {
fmt.Println(err) fmt.Println(err)
...@@ -40,7 +37,7 @@ func main() { ...@@ -40,7 +37,7 @@ func main() {
// Encode the compressed byte points with base64. // Encode the compressed byte points with base64.
encoded := make([]byte, base64.StdEncoding.EncodedLen(compressed.Len())) encoded := make([]byte, base64.StdEncoding.EncodedLen(compressed.Len()))
base64.StdEncoding.Encode(encoded, compressed.Bytes()) base64.StdEncoding.Encode(encoded, compressed.Bytes())*/
fmt.Fprintln(fi, "// Copyright (c) 2015 The btcsuite developers") fmt.Fprintln(fi, "// Copyright (c) 2015 The btcsuite developers")
fmt.Fprintln(fi, "// Use of this source code is governed by an ISC") fmt.Fprintln(fi, "// Use of this source code is governed by an ISC")
...@@ -51,7 +48,7 @@ func main() { ...@@ -51,7 +48,7 @@ func main() {
fmt.Fprintln(fi, "// Auto-generated file (see genprecomps.go)") fmt.Fprintln(fi, "// Auto-generated file (see genprecomps.go)")
fmt.Fprintln(fi, "// DO NOT EDIT") fmt.Fprintln(fi, "// DO NOT EDIT")
fmt.Fprintln(fi) fmt.Fprintln(fi)
fmt.Fprintf(fi, "var secp256k1BytePoints = %q\n", string(encoded)) fmt.Fprintf(fi, "var secp256k1BytePoints = %q\n", string(serialized))
a1, b1, a2, b2 := btcec.S256().EndomorphismVectors() a1, b1, a2, b2 := btcec.S256().EndomorphismVectors()
fmt.Println("The following values are the computed linearly " + fmt.Println("The following values are the computed linearly " +
......
...@@ -5,11 +5,7 @@ ...@@ -5,11 +5,7 @@
package btcec package btcec
import ( import (
"compress/zlib"
"encoding/base64"
"encoding/binary" "encoding/binary"
"io/ioutil"
"strings"
) )
//go:generate go run -tags gensecp256k1 genprecomps.go //go:generate go run -tags gensecp256k1 genprecomps.go
...@@ -29,7 +25,7 @@ func loadS256BytePoints() error { ...@@ -29,7 +25,7 @@ func loadS256BytePoints() error {
// Decompress the pre-computed table used to accelerate scalar base // Decompress the pre-computed table used to accelerate scalar base
// multiplication. // multiplication.
decoder := base64.NewDecoder(base64.StdEncoding, strings.NewReader(bp)) /*decoder := base64.NewDecoder(base64.StdEncoding, strings.NewReader(bp))
r, err := zlib.NewReader(decoder) r, err := zlib.NewReader(decoder)
if err != nil { if err != nil {
return err return err
...@@ -37,7 +33,8 @@ func loadS256BytePoints() error { ...@@ -37,7 +33,8 @@ func loadS256BytePoints() error {
serialized, err := ioutil.ReadAll(r) serialized, err := ioutil.ReadAll(r)
if err != nil { if err != nil {
return err return err
} }*/
serialized := []byte(bp)
// Deserialize the precomputed byte points and set the curve to them. // Deserialize the precomputed byte points and set the curve to them.
offset := 0 offset := 0
......
This diff is collapsed.
...@@ -44,6 +44,7 @@ instrumenting_all = False ...@@ -44,6 +44,7 @@ instrumenting_all = False
instructions_seen = set() instructions_seen = set()
profiler = defaultdict(int) profiler = defaultdict(int)
phit = 0 phit = 0
PROFILE = os.getenv("PROFILE", False)
def hook_code_simple(uc, address, size, user_data): def hook_code_simple(uc, address, size, user_data):
global icount, bcount, phit global icount, bcount, phit
#assert size == 4 #assert size == 4
...@@ -57,12 +58,13 @@ def hook_code_simple(uc, address, size, user_data): ...@@ -57,12 +58,13 @@ def hook_code_simple(uc, address, size, user_data):
#instructions_seen.add(dat.mnemonic) #instructions_seen.add(dat.mnemonic)
#print(sorted(list(instructions_seen))) #print(sorted(list(instructions_seen)))
symbol = r[address] if address in r else "UNKNOWN" symbol = r[address] if address in r else "UNKNOWN"
profiler[symbol] += 1
phit += 1
print("%10d(%2d): %8x %-80s %s" % (icount, newicount, address, symbol, dat)) print("%10d(%2d): %8x %-80s %s" % (icount, newicount, address, symbol, dat))
if bcount%1000000 == 0: if PROFILE:
for k,v in sorted(profiler.items(), key=lambda x: -x[1])[:10]: profiler[symbol] += 1
print("%-80s : %.2f%%" % (k, (v/phit)*100.)) phit += 1
if bcount%1000000 == 0:
for k,v in sorted(profiler.items(), key=lambda x: -x[1])[:10]:
print("%-80s : %.2f%%" % (k, (v/phit)*100.))
icount += newicount icount += newicount
bcount += 1 bcount += 1
return True return True
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment