mirror of
https://github.com/codex-storage/constantine.git
synced 2025-01-12 03:54:14 +00:00
#255: revive AT&T syntax, unfortunately cannot be combined with LTO for Clang
This commit is contained in:
parent
3ed57d3690
commit
121334be79
@ -7,6 +7,7 @@
|
|||||||
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
||||||
|
|
||||||
import ./ct_types
|
import ./ct_types
|
||||||
|
import ../isa/macro_assembler_x86
|
||||||
|
|
||||||
# ############################################################
|
# ############################################################
|
||||||
#
|
#
|
||||||
@ -45,20 +46,47 @@ func ccopy_fallback[T](ctl: CTBool[T], x: var T, y: T) {.inline.}=
|
|||||||
# x86 and x86-64
|
# x86 and x86-64
|
||||||
# ------------------------------------------------------------
|
# ------------------------------------------------------------
|
||||||
|
|
||||||
template mux_x86_impl() {.dirty.} =
|
when UseAsmSyntaxIntel:
|
||||||
static: doAssert(X86)
|
template mux_x86_impl() {.dirty.} =
|
||||||
static: doAssert(GCC_Compatible)
|
static: doAssert(X86)
|
||||||
|
static: doAssert(GCC_Compatible)
|
||||||
|
|
||||||
var muxed = x
|
var muxed = x
|
||||||
asm """
|
asm """
|
||||||
test %[ctl], %[ctl]
|
test %[ctl], %[ctl]
|
||||||
cmovz %[muxed], %[y]
|
cmovz %[muxed], %[y]
|
||||||
: [muxed] "+r" (`muxed`)
|
: [muxed] "+r" (`muxed`)
|
||||||
: [ctl] "r" (`ctl`), [y] "r" (`y`)
|
: [ctl] "r" (`ctl`), [y] "r" (`y`)
|
||||||
: "cc"
|
: "cc"
|
||||||
"""
|
"""
|
||||||
muxed
|
muxed
|
||||||
|
else:
|
||||||
|
template mux_x86_impl() {.dirty.} =
|
||||||
|
static: doAssert(X86)
|
||||||
|
static: doAssert(GCC_Compatible)
|
||||||
|
|
||||||
|
when sizeof(T) == 8:
|
||||||
|
var muxed = x
|
||||||
|
asm """
|
||||||
|
testq %[ctl], %[ctl]
|
||||||
|
cmovzq %[y], %[muxed]
|
||||||
|
: [muxed] "+r" (`muxed`)
|
||||||
|
: [ctl] "r" (`ctl`), [y] "r" (`y`)
|
||||||
|
: "cc"
|
||||||
|
"""
|
||||||
|
muxed
|
||||||
|
elif sizeof(T) == 4:
|
||||||
|
var muxed = x
|
||||||
|
asm """
|
||||||
|
testl %[ctl], %[ctl]
|
||||||
|
cmovzl %[y], %[muxed]
|
||||||
|
: [muxed] "+r" (`muxed`)
|
||||||
|
: [ctl] "r" (`ctl`), [y] "r" (`y`)
|
||||||
|
: "cc"
|
||||||
|
"""
|
||||||
|
muxed
|
||||||
|
else:
|
||||||
|
{.error: "Unsupported word size".}
|
||||||
|
|
||||||
func mux_x86[T](ctl: CTBool[T], x, y: T): T {.inline.}=
|
func mux_x86[T](ctl: CTBool[T], x, y: T): T {.inline.}=
|
||||||
## Multiplexer / selector
|
## Multiplexer / selector
|
||||||
@ -74,29 +102,73 @@ func mux_x86[T: CTBool](ctl: CTBool, x, y: T): T {.inline.}=
|
|||||||
## So equivalent to ctl? x: y
|
## So equivalent to ctl? x: y
|
||||||
mux_x86_impl()
|
mux_x86_impl()
|
||||||
|
|
||||||
func ccopy_x86[T](ctl: CTBool[T], x: var T, y: T) {.inline.}=
|
when UseAsmSyntaxIntel:
|
||||||
## Conditional copy
|
func ccopy_x86[T](ctl: CTBool[T], x: var T, y: T) {.inline.}=
|
||||||
## Copy ``y`` into ``x`` if ``ctl`` is true
|
## Conditional copy
|
||||||
static: doAssert(X86)
|
## Copy ``y`` into ``x`` if ``ctl`` is true
|
||||||
static: doAssert(GCC_Compatible)
|
static: doAssert(X86)
|
||||||
|
static: doAssert(GCC_Compatible)
|
||||||
|
|
||||||
when defined(cpp):
|
when defined(cpp):
|
||||||
asm """
|
asm """
|
||||||
test %[ctl], %[ctl]
|
test %[ctl], %[ctl]
|
||||||
cmovnz %[x], %[y]
|
cmovnz %[x], %[y]
|
||||||
: [x] "+r" (`x`)
|
: [x] "+r" (`x`)
|
||||||
: [ctl] "r" (`ctl`), [y] "r" (`y`)
|
: [ctl] "r" (`ctl`), [y] "r" (`y`)
|
||||||
: "cc"
|
: "cc"
|
||||||
"""
|
"""
|
||||||
|
|
||||||
else:
|
else:
|
||||||
asm """
|
asm """
|
||||||
test %[ctl], %[ctl]
|
test %[ctl], %[ctl]
|
||||||
cmovnz %[x], %[y]
|
cmovnz %[x], %[y]
|
||||||
: [x] "+r" (`*x`)
|
: [x] "+r" (`*x`)
|
||||||
: [ctl] "r" (`ctl`), [y] "r" (`y`)
|
: [ctl] "r" (`ctl`), [y] "r" (`y`)
|
||||||
: "cc"
|
: "cc"
|
||||||
"""
|
"""
|
||||||
|
else:
|
||||||
|
func ccopy_x86[T](ctl: CTBool[T], x: var T, y: T) {.inline.}=
|
||||||
|
## Conditional copy
|
||||||
|
## Copy ``y`` into ``x`` if ``ctl`` is true
|
||||||
|
static: doAssert(X86)
|
||||||
|
static: doAssert(GCC_Compatible)
|
||||||
|
|
||||||
|
when sizeof(T) == 8:
|
||||||
|
when defined(cpp):
|
||||||
|
asm """
|
||||||
|
testq %[ctl], %[ctl]
|
||||||
|
cmovnzq %[y], %[x]
|
||||||
|
: [x] "+r" (`x`)
|
||||||
|
: [ctl] "r" (`ctl`), [y] "r" (`y`)
|
||||||
|
: "cc"
|
||||||
|
"""
|
||||||
|
else:
|
||||||
|
asm """
|
||||||
|
testq %[ctl], %[ctl]
|
||||||
|
cmovnzq %[y], %[x]
|
||||||
|
: [x] "+r" (`*x`)
|
||||||
|
: [ctl] "r" (`ctl`), [y] "r" (`y`)
|
||||||
|
: "cc"
|
||||||
|
"""
|
||||||
|
elif sizeof(T) == 4:
|
||||||
|
when defined(cpp):
|
||||||
|
asm """
|
||||||
|
testl %[ctl], %[ctl]
|
||||||
|
cmovnzl %[y], %[x]
|
||||||
|
: [x] "+r" (`x`)
|
||||||
|
: [ctl] "r" (`ctl`), [y] "r" (`y`)
|
||||||
|
: "cc"
|
||||||
|
"""
|
||||||
|
else:
|
||||||
|
asm """
|
||||||
|
testl %[ctl], %[ctl]
|
||||||
|
cmovnzl %[y], %[x]
|
||||||
|
: [x] "+r" (`*x`)
|
||||||
|
: [ctl] "r" (`ctl`), [y] "r" (`y`)
|
||||||
|
: "cc"
|
||||||
|
"""
|
||||||
|
else:
|
||||||
|
{.error: "Unsupported word size".}
|
||||||
|
|
||||||
# Public functions
|
# Public functions
|
||||||
# ------------------------------------------------------------
|
# ------------------------------------------------------------
|
||||||
|
File diff suppressed because it is too large
Load Diff
1136
constantine/platforms/isa/macro_assembler_x86_att.nim
Normal file
1136
constantine/platforms/isa/macro_assembler_x86_att.nim
Normal file
File diff suppressed because it is too large
Load Diff
1092
constantine/platforms/isa/macro_assembler_x86_intel.nim
Normal file
1092
constantine/platforms/isa/macro_assembler_x86_intel.nim
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user