Skip to content

Commit

Permalink
feat(vm/compiler): export su_power function in case user needs it
Browse files Browse the repository at this point in the history
  • Loading branch information
vsariola committed Apr 5, 2024
1 parent beb84d7 commit 6d45299
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions vm/compiler/templates/amd64-386/patch.asm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 11 additions & 7 deletions vm/compiler/x86_macros.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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) {
Expand Down

0 comments on commit 6d45299

Please sign in to comment.