aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js/bindings/ZigGeneratedCode.cpp
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-08-15 01:48:31 -0700
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-08-17 07:36:35 -0700
commit6a65631cbdcae75bfa1e64323a6ad613a922cd1a (patch)
treed6a8c56e9455eafbcb944fd29b5ba066ab31bca0 /src/bun.js/bindings/ZigGeneratedCode.cpp
parent382be2cb46eac458e7f619ee1ee05c9efadcce51 (diff)
downloadbun-6a65631cbdcae75bfa1e64323a6ad613a922cd1a.tar.gz
bun-6a65631cbdcae75bfa1e64323a6ad613a922cd1a.tar.zst
bun-6a65631cbdcae75bfa1e64323a6ad613a922cd1a.zip
[bun:ffi] Improve `ptr()` performance and implement code generation for DOMJIT
Diffstat (limited to 'src/bun.js/bindings/ZigGeneratedCode.cpp')
-rw-r--r--src/bun.js/bindings/ZigGeneratedCode.cpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/bun.js/bindings/ZigGeneratedCode.cpp b/src/bun.js/bindings/ZigGeneratedCode.cpp
new file mode 100644
index 000000000..e5e377d82
--- /dev/null
+++ b/src/bun.js/bindings/ZigGeneratedCode.cpp
@@ -0,0 +1,60 @@
+#include "root.h"
+
+#include <JavaScriptCore/DOMJITAbstractHeap.h>
+#include "DOMJITIDLConvert.h"
+#include "DOMJITIDLType.h"
+#include "DOMJITIDLTypeFilter.h"
+#include "DOMJITHelpers.h"
+#include <JavaScriptCore/DFGAbstractHeap.h>
+
+#include "JSDOMConvertBufferSource.h"
+
+using namespace JSC;
+using namespace WebCore;
+
+/* -- BEGIN DOMCall DEFINITIONS -- */
+
+extern "C" JSC_DECLARE_HOST_FUNCTION(FFI__ptr__slowpathWrapper);
+extern "C" JSC_DECLARE_JIT_OPERATION_WITHOUT_WTF_INTERNAL(FFI__ptr__fastpathWrapper, EncodedJSValue, (JSC::JSGlobalObject * lexicalGlobalObject, void* thisValue, JSC::JSUint8Array*));
+
+JSC_DEFINE_JIT_OPERATION(FFI__ptr__fastpathWrapper, EncodedJSValue, (JSC::JSGlobalObject * lexicalGlobalObject, void* thisValue, JSC::JSUint8Array* arg1))
+{
+ VM& vm = JSC::getVM(lexicalGlobalObject);
+ IGNORE_WARNINGS_BEGIN("frame-address")
+ CallFrame* callFrame = DECLARE_CALL_FRAME(vm);
+ IGNORE_WARNINGS_END
+ JSC::JITOperationPrologueCallFrameTracer tracer(vm, callFrame);
+ return FFI__ptr__fastpath(lexicalGlobalObject, thisValue, arg1);
+}
+JSC_DEFINE_HOST_FUNCTION(FFI__ptr__slowpathWrapper, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* frame))
+{
+ return FFI__ptr__slowpath(globalObject, JSValue::encode(frame->thisValue()), reinterpret_cast<JSC::EncodedJSValue*>(frame->addressOfArgumentsStart()), frame->argumentCount());
+}
+
+constexpr JSC::DFG::AbstractHeapKind encodeIntoRead[4] = { JSC::DFG::Absolute, JSC::DFG::MiscFields, JSC::DFG::TypedArrayProperties };
+constexpr JSC::DFG::AbstractHeapKind encodeIntoWrite[4] = { JSC::DFG::Absolute, JSC::DFG::TypedArrayProperties };
+
+extern "C" void FFI__ptr__put(JSC::JSGlobalObject* globalObject, JSC::EncodedJSValue value)
+{
+ JSC::JSObject* thisObject = JSC::jsCast<JSC::JSObject*>(JSC::JSValue::decode(value));
+ static const JSC::DOMJIT::Signature DOMJIT_ptr_signature(
+ FFI__ptr__fastpathWrapper,
+ thisObject->classInfo(),
+ JSC::DOMJIT::Effect::forReadWriteKinds(encodeIntoRead, encodeIntoWrite),
+ JSC::SpecNonIntAsDouble,
+ JSC::SpecUint8Array);
+ JSFunction* function = JSFunction::create(
+ globalObject->vm(),
+ globalObject,
+ 1,
+ String("ptr"_s),
+ FFI__ptr__slowpathWrapper, ImplementationVisibility::Public, NoIntrinsic, FFI__ptr__slowpathWrapper,
+ &DOMJIT_ptr_signature);
+ thisObject->putDirect(
+ globalObject->vm(),
+ Identifier::fromString(globalObject->vm(), "ptr"_s),
+ function,
+ JSC::PropertyAttribute::Function | JSC::PropertyAttribute::DOMJITFunction | 0);
+}
+
+/* -- END DOMCall DEFINITIONS-- */