add

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 19, 2021 License: BSD-3-Clause Imports: 0 Imported by: 0

README

add

Add two numbers with avo.

The code generator is as follows:

// +build ignore

package main

import . "github.com/mmcloughlin/avo/build"

func main() {
	TEXT("Add", NOSPLIT, "func(x, y uint64) uint64")
	Doc("Add adds x and y.")
	x := Load(Param("x"), GP64())
	y := Load(Param("y"), GP64())
	ADDQ(x, y)
	Store(y, ReturnIndex(0))
	RET()
	Generate()
}

We use a go:generate line to produce the assembly and Go stub files together.

//go:generate go run asm.go -out add.s -stubs stub.go

This produces add.s as follows:

// Code generated by command: go run asm.go -out add.s -stubs stub.go. DO NOT EDIT.

#include "textflag.h"

// func Add(x uint64, y uint64) uint64
TEXT ·Add(SB), NOSPLIT, $0-24
	MOVQ x+0(FP), AX
	MOVQ y+8(FP), CX
	ADDQ AX, CX
	MOVQ CX, ret+16(FP)
	RET

Documentation

Overview

Package add demonstrates an Add function in avo.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Add

func Add(x uint64, y uint64) uint64

Add adds x and y.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL