Simplify amd64 / 386 rounding mode set

This commit is contained in:
DataHoarder 2024-05-02 03:00:26 +02:00
parent 8b063bde61
commit cceea5b0ba
Signed by: DataHoarder
SSH key fingerprint: SHA256:OLTRf6Fl87G52SiR7sWLGNzlJt4WOX+tfI2yxo0z7xk
5 changed files with 40 additions and 56 deletions

View file

@ -4,12 +4,12 @@
// func Cpuid(op uint32) (eax, ebx, ecx, edx uint32) // func Cpuid(op uint32) (eax, ebx, ecx, edx uint32)
TEXT ·Cpuid(SB), 7, $0 TEXT ·Cpuid(SB), 7, $0
XORQ CX, CX XORQ CX, CX
MOVL op+0(FP), AX MOVL op+0(FP), AX
CPUID CPUID
MOVL AX, eax+8(FP) MOVL AX, eax+8(FP)
MOVL BX, ebx+12(FP) MOVL BX, ebx+12(FP)
MOVL CX, ecx+16(FP) MOVL CX, ecx+16(FP)
MOVL DX, edx+20(FP) MOVL DX, edx+20(FP)
RET RET

View file

@ -2,19 +2,5 @@
package asm package asm
// stmxcsr reads the MXCSR control and status register.
//
//go:noescape //go:noescape
func stmxcsr(addr *uint32) func setRoundingMode(mode uint8)
// ldmxcsr writes to the MXCSR control and status register.
//
//go:noescape
func ldmxcsr(addr *uint32)
func setRoundingMode(mode uint8) {
var csr uint32
stmxcsr(&csr)
csr = (csr & (^uint32(0x6000))) | ((uint32(mode) & 3) << 13)
ldmxcsr(&csr)
}

View file

@ -2,14 +2,20 @@
#include "textflag.h" #include "textflag.h"
// stmxcsr reads the MXCSR control and status register. TEXT ·setRoundingMode(SB),NOSPLIT|NOFRAME,$4-1
TEXT ·stmxcsr(SB),NOSPLIT|NOFRAME,$0-4 MOVB addr+0(FP), AX
MOVL addr+0(FP), SI ANDL $3, AX
STMXCSR (SI) ROLL $13, AX
RET
// ldmxcsr writes to the MXCSR control and status register. // get current MXCSR register
TEXT ·ldmxcsr(SB),NOSPLIT|NOFRAME,$0-4 PUSHL AX
MOVL addr+0(FP), SI STMXCSR 0(SP)
LDMXCSR (SI)
// put new rounding mode
ANDL $~0x6000, 0(SP)
ORL AX, 0(SP)
// store new MXCSR register
LDMXCSR 0(SP)
POPL AX
RET RET

View file

@ -2,19 +2,5 @@
package asm package asm
// stmxcsr reads the MXCSR control and status register.
//
//go:noescape //go:noescape
func stmxcsr(addr *uint32) func setRoundingMode(mode uint8)
// ldmxcsr writes to the MXCSR control and status register.
//
//go:noescape
func ldmxcsr(addr *uint32)
func setRoundingMode(mode uint8) {
var csr uint32
stmxcsr(&csr)
csr = (csr & (^uint32(0x6000))) | ((uint32(mode) & 3) << 13)
ldmxcsr(&csr)
}

View file

@ -2,14 +2,20 @@
#include "textflag.h" #include "textflag.h"
// stmxcsr reads the MXCSR control and status register. TEXT ·setRoundingMode(SB),NOSPLIT|NOFRAME,$8-1
TEXT ·stmxcsr(SB),NOSPLIT|NOFRAME,$0-8 MOVB addr+0(FP), AX
MOVQ addr+0(FP), SI ANDQ $3, AX
STMXCSR (SI) ROLQ $13, AX
RET
// ldmxcsr writes to the MXCSR control and status register. // get current MXCSR register
TEXT ·ldmxcsr(SB),NOSPLIT|NOFRAME,$0-8 PUSHQ AX
MOVQ addr+0(FP), SI STMXCSR 0(SP)
LDMXCSR (SI)
// put new rounding mode
ANDL $~0x6000, 0(SP)
ORL AX, 0(SP)
// store new MXCSR register
LDMXCSR 0(SP)
POPQ AX
RET RET