Skip to content

Commit

Permalink
Merge branch 'master' into stable
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmos72 committed Oct 28, 2020
2 parents 0116063 + df4b7ff commit 6250a60
Show file tree
Hide file tree
Showing 579 changed files with 75,939 additions and 93,069 deletions.
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/gomacro
/gomacro.test
a.out
*~
*.o
Expand All @@ -9,7 +8,6 @@ a.out
_gen_*.s
/example/example
/jit/**/test
/jit/amd64/_template/_template
/jit/arm64/_template/_template
/jit/**/_template/_template
/jit/arm64/_template/_bitwise_immediate/_bitwise_immediate
/jit/arm64/_template/_go/_go
264 changes: 177 additions & 87 deletions README.md

Large diffs are not rendered by default.

Empty file modified _example/arith.gomacro
100755 → 100644
Empty file.
Empty file modified _example/channel.gomacro
100755 → 100644
Empty file.
Empty file modified _example/collatz.gomacro
100755 → 100644
Empty file.
Empty file modified _example/embedded_field.gomacro
100755 → 100644
Empty file.
Empty file modified _example/fibonacci.gomacro
100755 → 100644
Empty file.
Empty file modified _example/for_range.gomacro
100755 → 100644
Empty file.
12 changes: 6 additions & 6 deletions _example/make_fibonacci.gomacro
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ package main
return ret
}

makefib; int
makefib; int32
makefib; int64
makefib; fibonacci_int; int
makefib; fibonacci_int32; int32
makefib; fibonacci_int64; int64

makefib; uint
makefib; uint32
makefib; uint64
makefib; fibonacci_uint; uint
makefib; fibonacci_uint32; uint32
makefib; fibonacci_uint64; uint64
42 changes: 30 additions & 12 deletions _example/make_fibonacci.gomacro_output
Original file line number Diff line number Diff line change
Expand Up @@ -9,39 +9,57 @@

package main

func fibonacci_int(n int) int {
func fibonacci_int(n int,

) int {
if n <= 2 {
return 1
}
return fibonacci_int(n-1) + fibonacci_int(n-2)
return fibonacci_int(n-1) +
fibonacci_int(n-2)
}
func fibonacci_int32(n int32) int32 {
func fibonacci_int32(n int32,

) int32 {
if n <= 2 {
return 1
}
return fibonacci_int32(n-1) + fibonacci_int32(n-2)
return fibonacci_int32(n-1) +
fibonacci_int32(n-2)
}
func fibonacci_int64(n int64) int64 {
func fibonacci_int64(n int64,

) int64 {
if n <= 2 {
return 1
}
return fibonacci_int64(n-1) + fibonacci_int64(n-2)
return fibonacci_int64(n-1) +
fibonacci_int64(n-2)
}
func fibonacci_uint(n uint) uint {
func fibonacci_uint(n uint,

) uint {
if n <= 2 {
return 1
}
return fibonacci_uint(n-1) + fibonacci_uint(n-2)
return fibonacci_uint(n-1) +
fibonacci_uint(n-2)
}
func fibonacci_uint32(n uint32) uint32 {
func fibonacci_uint32(n uint32,

) uint32 {
if n <= 2 {
return 1
}
return fibonacci_uint32(n-1) + fibonacci_uint32(n-2)
return fibonacci_uint32(n-1) +
fibonacci_uint32(n-2)
}
func fibonacci_uint64(n uint64) uint64 {
func fibonacci_uint64(n uint64,

) uint64 {
if n <= 2 {
return 1
}
return fibonacci_uint64(n-1) + fibonacci_uint64(n-2)
return fibonacci_uint64(n-1) +
fibonacci_uint64(n-2)
}
278 changes: 278 additions & 0 deletions _experiments/bench_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,278 @@
// +build gomacro_jit

/*
* gomacro - A Go interpreter with Lisp-like macros
*
* Copyright (C) 2018-2019 Massimiliano Ghilardi
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
*
* bench_test.go
*
* Created on: Jun 06 2018
* Author: Massimiliano Ghilardi
*/
package experiments

import (
"testing"
"unsafe"

"github.com/cosmos72/gomacro/_experiments/bytecode_interfaces"
"github.com/cosmos72/gomacro/_experiments/bytecode_values"
"github.com/cosmos72/gomacro/_experiments/closure_interfaces"
"github.com/cosmos72/gomacro/_experiments/closure_ints"
"github.com/cosmos72/gomacro/_experiments/closure_maps"
"github.com/cosmos72/gomacro/_experiments/closure_values"
"github.com/cosmos72/gomacro/_experiments/jit"
)

func arithJitEmulate(uenv *uint64) {
env := (*[3]int64)(unsafe.Pointer(uenv))
a := env[0]
a *= 2
a += 3
a |= 4
a &^= 5
a ^= 6
b := env[0]
b &= 2
b |= 1
a /= b
env[1] = a
}

func BenchmarkArithJitEmul(b *testing.B) {
benchArithJit(b, arithJitEmulate)
}

func BenchmarkArithJit(b *testing.B) {
if !jit.SUPPORTED {
b.SkipNow()
return
}
benchArithJit(b, jit.DeclArith(5))
}

func benchArithJit(b *testing.B, f func(*uint64)) {
total := 0
var env [5]uint64
b.ResetTimer()
for i := 0; i < b.N; i++ {
env[0] = uint64(b.N)
f(&env[0])
total += int(env[1])
}
if verbose {
println(total)
}
}

// --------------------------------------------------------------

func BenchmarkSumJit(b *testing.B) {
if !jit.SUPPORTED {
b.SkipNow()
return
}
sum := jit.DeclSum()
b.ResetTimer()
var total int
for i := 0; i < b.N; i++ {
total += sum(sum_arg)
}
}

func TestFibonacciClosureInts(t *testing.T) {
env := closure_ints.NewEnv(nil)
f := closure_ints.DeclFibonacci(env)

expected := fibonacci(fib_arg)
actual := f(fib_arg)
if actual != expected {
t.Errorf("expecting %v, found %v\n", expected, actual)
}
}

func BenchmarkFibonacciClosureInts(b *testing.B) {
env := closure_ints.NewEnv(nil)
fib := closure_ints.DeclFibonacci(env)

b.ResetTimer()
var total int
for i := 0; i < b.N; i++ {
total += fib(fib_arg)
}
}

func BenchmarkFibonacciClosureValues(b *testing.B) {
env := closure_values.NewEnv(nil)
fib := closure_values.DeclFibonacci(env, 0)
n := r.ValueOf(fib_arg)

b.ResetTimer()
var total int
for i := 0; i < b.N; i++ {
total += fib(n)
}
}

func BenchmarkFibonacciClosureInterfaces(b *testing.B) {
env := closure_interfaces.NewEnv(nil)
fib := closure_interfaces.DeclFibonacci(env, 0)
var n interface{} = fib_arg

b.ResetTimer()
var total int
for i := 0; i < b.N; i++ {
total += fib(n)
}
}

func BenchmarkFibonacciClosureMaps(b *testing.B) {
env := closure_maps.NewEnv(nil)
fib := closure_maps.DeclFibonacci(env, "fib")
n := r.ValueOf(fib_arg)

b.ResetTimer()
var total int
for i := 0; i < b.N; i++ {
total += fib(n)
}
}

func TestFibonacciClosureInts(t *testing.T) {
env := closure_ints.NewEnv(nil)
f := closure_ints.DeclFibonacci(env)

expected := fibonacci(fib_arg)
actual := f(fib_arg)
if actual != expected {
t.Errorf("expecting %v, found %v\n", expected, actual)
}
}

func BenchmarkFibonacciClosureInts(b *testing.B) {
env := closure_ints.NewEnv(nil)
fib := closure_ints.DeclFibonacci(env)

b.ResetTimer()
var total int
for i := 0; i < b.N; i++ {
total += fib(fib_arg)
}
}

func BenchmarkFibonacciClosureValues(b *testing.B) {
env := closure_values.NewEnv(nil)
fib := closure_values.DeclFibonacci(env, 0)
n := r.ValueOf(fib_arg)

b.ResetTimer()
var total int
for i := 0; i < b.N; i++ {
total += fib(n)
}
}

func BenchmarkFibonacciClosureInterfaces(b *testing.B) {
env := closure_interfaces.NewEnv(nil)
fib := closure_interfaces.DeclFibonacci(env, 0)
var n interface{} = fib_arg

b.ResetTimer()
var total int
for i := 0; i < b.N; i++ {
total += fib(n)
}
}

func BenchmarkFibonacciClosureMaps(b *testing.B) {
env := closure_maps.NewEnv(nil)
fib := closure_maps.DeclFibonacci(env, "fib")
n := r.ValueOf(fib_arg)

b.ResetTimer()
var total int
for i := 0; i < b.N; i++ {
total += fib(n)
}
}
func BenchmarkSumBytecodeValues(b *testing.B) {
sum := bytecode_values.BytecodeSum(sum_arg)
b.ResetTimer()
var total int
for i := 0; i < b.N; i++ {
total += int(sum.Exec(0)[0].Int())
}
}

func BenchmarkSumBytecodeInterfaces(b *testing.B) {
p := bytecode_interfaces.BytecodeSum(sum_arg)
b.ResetTimer()
var total int
for i := 0; i < b.N; i++ {
total += p.Exec(0)[0].(int)
}
}

func off_TestSumClosureInts(t *testing.T) {
env := closure_ints.NewEnv(nil)
f := closure_ints.DeclSum(env)

expected := sum(sum_arg)
actual := f(sum_arg)
if actual != expected {
t.Errorf("expecting %v, found %v\n", expected, actual)
}
}

func BenchmarkSumClosureInts(b *testing.B) {
env := closure_ints.NewEnv(nil)
sum := closure_ints.DeclSum(env)

b.ResetTimer()
var total int
for i := 0; i < b.N; i++ {
total += sum(sum_arg)
}
}

func BenchmarkSumClosureValues(b *testing.B) {
env := closure_values.NewEnv(nil)
sum := closure_values.DeclSum(env, 0)
n := r.ValueOf(sum_arg)

b.ResetTimer()
var total int
for i := 0; i < b.N; i++ {
total += sum(n)
}
}

func BenchmarkSumClosureInterfaces(b *testing.B) {
env := closure_interfaces.NewEnv(nil)
sum := closure_interfaces.DeclSum(env, 0)
var n interface{} = sum_arg

b.ResetTimer()
var total int
for i := 0; i < b.N; i++ {
total += sum(n)
}
}

func BenchmarkSumClosureMaps(b *testing.B) {
env := closure_maps.NewEnv(nil)
sum := closure_maps.DeclSum(env, "sum")
n := r.ValueOf(sum_arg)

b.ResetTimer()
var total int
for i := 0; i < b.N; i++ {
total += sum(n)
}
}

0 comments on commit 6250a60

Please sign in to comment.