diff --git a/CHANGELOG.md b/CHANGELOG.md index 01c9555..cf1608c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Dbgain unit, which allows defining the gain in decibels (-40 dB to +40dB) - `+` and `-` keys add/subtract values in order editor and pattern editor ([#65][i65]) +- The function `su_power` is exported so people can reuse it in the main code; + however, as it assumes the parameter passed in st0 on the x87 stack and + similarly returns it value in st0 on the x87 stack, to my knowledge there is + no calling convention that would correspond this behaviour, so you need to + define a header for it yourself and take care of putting the float value on + x87 stack. ### Fixed - When recording notes from VSTI, no track was created for instruments that had diff --git a/vm/compiler/templates/amd64-386/patch.asm b/vm/compiler/templates/amd64-386/patch.asm index 24f652d..1ec81dd 100644 --- a/vm/compiler/templates/amd64-386/patch.asm +++ b/vm/compiler/templates/amd64-386/patch.asm @@ -114,6 +114,7 @@ su_op_advance_finish: ; Output: st0 : 2^x ;------------------------------------------------------------------------------- {{- if not (.HasCall "su_nonlinear_map")}}{{.SectText "su_power"}}{{end}} +{{.Export "su_power" 0}} su_power: fld1 ; 1 x fld st1 ; x 1 x diff --git a/vm/compiler/x86_macros.go b/vm/compiler/x86_macros.go index 4175710..bc19952 100644 --- a/vm/compiler/x86_macros.go +++ b/vm/compiler/x86_macros.go @@ -353,6 +353,16 @@ func (p *X86Macros) FmtStack() string { return b.String() } +func (p *X86Macros) Export(name string, numParams int) string { + if !p.Amd64 && p.OS == "windows" { + return fmt.Sprintf("global _%[1]v@%[2]v\n_%[1]v@%[2]v:", name, numParams*4) + } + if p.OS == "darwin" { + return fmt.Sprintf("global _%[1]v\n_%[1]v:", name) + } + return fmt.Sprintf("global %[1]v\n%[1]v:", name) +} + func (p *X86Macros) ExportFunc(name string, params ...string) string { numRegisters := 0 // in 32-bit systems, we use stdcall: everything in stack switch { @@ -371,13 +381,7 @@ func (p *X86Macros) ExportFunc(name string, params ...string) string { reverseParams[len(params)-1-i] = param } p.Stacklocs = append(reverseParams, "retaddr_"+name) // in 32-bit, we use stdcall and parameters are in the stack - if !p.Amd64 && p.OS == "windows" { - return fmt.Sprintf("%[1]v\nglobal _%[2]v@%[3]v\n_%[2]v@%[3]v:", p.SectText(name), name, len(params)*4) - } - if p.OS == "darwin" { - return fmt.Sprintf("%[1]v\nglobal _%[2]v\n_%[2]v:", p.SectText(name), name) - } - return fmt.Sprintf("%[1]v\nglobal %[2]v\n%[2]v:", p.SectText(name), name) + return fmt.Sprintf("%[1]v\n%[2]v", p.SectText(name), p.Export(name, len(params))) } func (p *X86Macros) Input(unit string, port string) (string, error) {