Generate SIMD code during build
This commit is contained in:
parent
86a55e2c0a
commit
4e6138d785
2 changed files with 15 additions and 0 deletions
|
|
@ -855,7 +855,12 @@ def normalize(t: tarfile.TarInfo) -> tarfile.TarInfo:
|
|||
write_compressed_data(buf.getvalue(), d)
|
||||
|
||||
|
||||
def start_simdgen() -> 'subprocess.Popen[bytes]':
|
||||
return subprocess.Popen(['go', 'run', 'generate.go'], cwd='tools/simdstring', stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
|
||||
|
||||
def main(args: List[str]=sys.argv) -> None:
|
||||
simdgen_process = start_simdgen()
|
||||
with replace_if_needed('constants_generated.go') as f:
|
||||
f.write(generate_constants())
|
||||
with replace_if_needed('tools/utils/style/color-names_generated.go') as f:
|
||||
|
|
@ -878,6 +883,12 @@ def main(args: List[str]=sys.argv) -> None:
|
|||
kitten_clis()
|
||||
stringify()
|
||||
print(json.dumps(changed, indent=2))
|
||||
stdout, stderr = simdgen_process.communicate()
|
||||
if simdgen_process.wait() != 0:
|
||||
print('Failed to generate SIMD ASM', file=sys.stderr)
|
||||
sys.stdout.buffer.write(stdout)
|
||||
sys.stderr.buffer.write(stderr)
|
||||
raise SystemExit(simdgen_process.returncode)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"go/types"
|
||||
"io"
|
||||
|
|
@ -1184,6 +1185,9 @@ func exit(msg any) {
|
|||
|
||||
func write_file(name, text string) {
|
||||
b := unsafe.Slice(unsafe.StringData(text), len(text))
|
||||
if existing, err := os.ReadFile(name); err == nil && bytes.Equal(existing, b) {
|
||||
return
|
||||
}
|
||||
if err := os.WriteFile(name, b, 0660); err != nil {
|
||||
exit(err)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue