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)
TEXT ·Cpuid(SB), 7, $0
XORQ CX, CX
MOVL op+0(FP), AX
CPUID
MOVL AX, eax+8(FP)
MOVL BX, ebx+12(FP)
MOVL CX, ecx+16(FP)
MOVL DX, edx+20(FP)
RET
XORQ CX, CX
MOVL op+0(FP), AX
CPUID
MOVL AX, eax+8(FP)
MOVL BX, ebx+12(FP)
MOVL CX, ecx+16(FP)
MOVL DX, edx+20(FP)
RET

View file

@ -2,19 +2,5 @@
package asm
// stmxcsr reads the MXCSR control and status register.
//
//go:noescape
func stmxcsr(addr *uint32)
// 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)
}
func setRoundingMode(mode uint8)

View file

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

View file

@ -2,19 +2,5 @@
package asm
// stmxcsr reads the MXCSR control and status register.
//
//go:noescape
func stmxcsr(addr *uint32)
// 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)
}
func setRoundingMode(mode uint8)

View file

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